ConfigurationTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Alchemy\Tests\BinaryDriver;
  3. use Alchemy\BinaryDriver\Configuration;
  4. class ConfigurationTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testArrayAccessImplementation()
  7. {
  8. $configuration = new Configuration(array('key' => 'value'));
  9. $this->assertTrue(isset($configuration['key']));
  10. $this->assertEquals('value', $configuration['key']);
  11. $this->assertFalse(isset($configuration['key2']));
  12. unset($configuration['key']);
  13. $this->assertFalse(isset($configuration['key']));
  14. $configuration['key2'] = 'value2';
  15. $this->assertTrue(isset($configuration['key2']));
  16. $this->assertEquals('value2', $configuration['key2']);
  17. }
  18. public function testGetOnNonExistentKeyShouldReturnDefaultValue()
  19. {
  20. $conf = new Configuration();
  21. $this->assertEquals('booba', $conf->get('hooba', 'booba'));
  22. $this->assertEquals(null, $conf->get('hooba'));
  23. }
  24. public function testSetHasGetRemove()
  25. {
  26. $configuration = new Configuration(array('key' => 'value'));
  27. $this->assertTrue($configuration->has('key'));
  28. $this->assertEquals('value', $configuration->get('key'));
  29. $this->assertFalse($configuration->has('key2'));
  30. $configuration->remove('key');
  31. $this->assertFalse($configuration->has('key'));
  32. $configuration->set('key2', 'value2');
  33. $this->assertTrue($configuration->has('key2'));
  34. $this->assertEquals('value2', $configuration->get('key2'));
  35. }
  36. public function testIterator()
  37. {
  38. $data = array(
  39. 'key1' => 'value1',
  40. 'key2' => 'value2',
  41. 'key3' => 'value3',
  42. );
  43. $captured = array();
  44. $conf = new Configuration($data);
  45. foreach ($conf as $key => $value) {
  46. $captured[$key] = $value;
  47. }
  48. $this->assertEquals($data, $captured);
  49. }
  50. public function testAll()
  51. {
  52. $data = array(
  53. 'key1' => 'value1',
  54. 'key2' => 'value2',
  55. 'key3' => 'value3',
  56. );
  57. $conf = new Configuration($data);
  58. $this->assertEquals($data, $conf->all());
  59. }
  60. }