added unit tests.
This commit is contained in:
parent
cb8e8194ce
commit
018d25c895
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
class BenchmarkTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testStartMethodCreatesMark()
|
||||
{
|
||||
Benchmark::start('test');
|
||||
|
||||
$this->assertTrue(is_float(Benchmark::check('test')));
|
||||
$this->assertGreaterThan(0.0, Benchmark::check('test'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
class ConfigTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
IoC::container()->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());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue