diff --git a/laravel/benchmark.php b/laravel/benchmark.php index 078b96be..34168b41 100644 --- a/laravel/benchmark.php +++ b/laravel/benchmark.php @@ -7,7 +7,7 @@ class Benchmark { * * @var array */ - public static $marks = array(); + protected static $marks = array(); /** * Start a benchmark. @@ -32,10 +32,10 @@ public static function check($name) { if (array_key_exists($name, static::$marks)) { - return number_format((microtime(true) - static::$marks[$name]) * 1000, 2); + return (float) number_format((microtime(true) - static::$marks[$name]) * 1000, 2); } - return 0.0; + return (float) 0.0; } /** diff --git a/laravel/config.php b/laravel/config.php index 88101e70..eefedb5d 100644 --- a/laravel/config.php +++ b/laravel/config.php @@ -119,7 +119,7 @@ private function parse($key) * @param string $file * @return bool */ - private function load($file) + protected function load($file) { if (isset($this->items[$file])) return true; diff --git a/laravel/container.php b/laravel/container.php index c79d0237..2a72f9d3 100644 --- a/laravel/container.php +++ b/laravel/container.php @@ -39,14 +39,14 @@ class Container { * * @var array */ - private $singletons = array(); + public $singletons = array(); /** * The registered dependencies. * * @var array */ - private $resolvers = array(); + protected $resolvers = array(); /** * Create a new IoC container instance. diff --git a/tests/ArrTest.php b/tests/ArrTest.php index 7db6b07f..bbc85a92 100644 --- a/tests/ArrTest.php +++ b/tests/ArrTest.php @@ -2,6 +2,7 @@ class ArrTest extends PHPUnit_Framework_TestCase { + /** * @dataProvider getArray */ @@ -11,6 +12,7 @@ public function testGetMethodReturnsItemsFromArray($array) $this->assertEquals(Arr::get($array, 'names.uncle'), $array['names']['uncle']); } + /** * @dataProvider getArray */ @@ -21,6 +23,7 @@ public function testGetMethodReturnsDefaultWhenItemDoesntExist($array) $this->assertEquals(Arr::get($array, 'names.aunt', function() {return 'Tammy';}), 'Tammy'); } + /** * @dataProvider getArray */ @@ -36,6 +39,7 @@ public function testSetMethodSetsItemsInArray($array) } + public function getArray() { return array(array( diff --git a/tests/BenchmarkTest.php b/tests/BenchmarkTest.php new file mode 100644 index 00000000..0b5425f8 --- /dev/null +++ b/tests/BenchmarkTest.php @@ -0,0 +1,13 @@ +assertTrue(is_float(Benchmark::check('test'))); + $this->assertGreaterThan(0.0, Benchmark::check('test')); + } + +} \ No newline at end of file diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php new file mode 100644 index 00000000..60e3fb5b --- /dev/null +++ b/tests/ConfigTest.php @@ -0,0 +1,72 @@ +singletons = array(); + } + + + /** + * @dataProvider getGetMocker + */ + public function testHasMethodReturnsTrueWhenItemExists($mock, $mocker) + { + $mocker->will($this->returnValue('value')); + + $this->assertTrue($mock->has('something')); + } + + + /** + * @dataProvider getGetMocker + */ + public function testHasMethodReturnsFalseWhenItemDoesntExist($mock, $mocker) + { + $mocker->will($this->returnValue(null)); + + $this->assertFalse($mock->has('something')); + } + + + public function getGetMocker() + { + $mock = $this->getMock('Laravel\\Config', array('get'), array(null)); + + return array(array($mock, $mock->expects($this->any())->method('get'))); + } + + + public function testConfigClassCanRetrieveItems() + { + $config = IoC::container()->config; + + $this->assertTrue(is_array($config->get('application'))); + $this->assertEquals($config->get('application.url'), 'http://localhost'); + } + + + public function testGetMethodReturnsDefaultWhenItemDoesntExist() + { + $config = IoC::container()->config; + + $this->assertNull($config->get('config.item')); + $this->assertEquals($config->get('config.item', 'test'), 'test'); + $this->assertEquals($config->get('config.item', function() {return 'test';}), 'test'); + } + + + public function testConfigClassCanSetItems() + { + $config = IoC::container()->config; + + $config->set('application.url', 'test'); + $config->set('session', array()); + + $this->assertEquals($config->get('application.url'), 'test'); + $this->assertEquals($config->get('session'), array()); + } + +} \ No newline at end of file