ConfigTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. class ConfigTest extends PHPUnit_Framework_TestCase {
  3. public static function setUpBeforeClass()
  4. {
  5. IoC::container()->singletons = array();
  6. }
  7. public function tearDown()
  8. {
  9. IoC::container()->singletons = array();
  10. }
  11. /**
  12. * @dataProvider getGetMocker
  13. */
  14. public function testHasMethodReturnsTrueWhenItemExists($mock, $mocker)
  15. {
  16. $mocker->will($this->returnValue('value'));
  17. $this->assertTrue($mock->has('something'));
  18. }
  19. /**
  20. * @dataProvider getGetMocker
  21. */
  22. public function testHasMethodReturnsFalseWhenItemDoesntExist($mock, $mocker)
  23. {
  24. $mocker->will($this->returnValue(null));
  25. $this->assertFalse($mock->has('something'));
  26. }
  27. public function getGetMocker()
  28. {
  29. $mock = $this->getMock('Laravel\\Config', array('get'), array(null));
  30. return array(array($mock, $mock->expects($this->any())->method('get')));
  31. }
  32. public function testConfigClassCanRetrieveItems()
  33. {
  34. $config = IoC::container()->resolve('laravel.config');
  35. $this->assertTrue(is_array($config->get('application')));
  36. $this->assertEquals($config->get('application.url'), 'http://localhost');
  37. }
  38. public function testGetMethodReturnsDefaultWhenItemDoesntExist()
  39. {
  40. $config = IoC::container()->resolve('laravel.config');
  41. $this->assertNull($config->get('config.item'));
  42. $this->assertEquals($config->get('config.item', 'test'), 'test');
  43. $this->assertEquals($config->get('config.item', function() {return 'test';}), 'test');
  44. }
  45. public function testConfigClassCanSetItems()
  46. {
  47. $config = IoC::container()->resolve('laravel.config');
  48. $config->set('application.names.test', 'test');
  49. $config->set('application.url', 'test');
  50. $config->set('session', array());
  51. $config->set('test', array());
  52. $this->assertEquals($config->get('application.names.test'), 'test');
  53. $this->assertEquals($config->get('application.url'), 'test');
  54. $this->assertEquals($config->get('session'), array());
  55. $this->assertEquals($config->get('test'), array());
  56. }
  57. }