Commit 018d25c8 authored by Taylor Otwell's avatar Taylor Otwell

added unit tests.

parent cb8e8194
......@@ -7,7 +7,7 @@ class Benchmark {
*
* @var array
*/
public static $marks = array();
protected static $marks = array();
/**
* Start a benchmark.
......@@ -32,10 +32,10 @@ class Benchmark {
{
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 @@ class Config {
* @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 @@ class ArrTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(Arr::get($array, 'names.uncle'), $array['names']['uncle']);
}
/**
* @dataProvider getArray
*/
......@@ -21,6 +23,7 @@ class ArrTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(Arr::get($array, 'names.aunt', function() {return 'Tammy';}), 'Tammy');
}
/**
* @dataProvider getArray
*/
......@@ -36,6 +39,7 @@ class ArrTest extends PHPUnit_Framework_TestCase {
}
public function getArray()
{
return array(array(
......
<?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'));
}
}
\ No newline at end of file
<?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());
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment