added unit tests.

This commit is contained in:
Taylor Otwell
2011-09-04 23:55:28 -05:00
parent cb8e8194ce
commit 018d25c895
6 changed files with 95 additions and 6 deletions

View File

@@ -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(

13
tests/BenchmarkTest.php Normal file
View File

@@ -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'));
}
}

72
tests/ConfigTest.php Normal file
View File

@@ -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());
}
}