PageRenderTime 74ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/units/jubianchi/PhpSwitch/Config/Configuration.php

https://github.com/horechek/phpswitch
PHP | 130 lines | 119 code | 11 blank | 0 comment | 0 complexity | 2ca328be6d160d82cebb691e97b954dc MD5 | raw file
  1. <?php
  2. namespace tests\units\jubianchi\PhpSwitch\Config;
  3. use mageekguy\atoum;
  4. use jubianchi\PhpSwitch\Config\Configuration as TestedClass;
  5. require_once __DIR__ . '/../../../../bootstrap.php';
  6. class Configuration extends atoum\test
  7. {
  8. public function testClass()
  9. {
  10. $this
  11. ->testedClass
  12. ->isSubclassOf('\\IteratorAggregate')
  13. ;
  14. }
  15. public function testGet()
  16. {
  17. $this
  18. ->if($object = new TestedClass())
  19. ->and($offset = uniqid())
  20. ->then
  21. ->exception(function() use($object, $offset) {
  22. $object->get($offset);
  23. })
  24. ->isInstanceOf('\\InvalidArgumentException')
  25. ->hasMessage(sprintf('Offset %s does not exist', $offset))
  26. ->if($value = uniqid())
  27. ->and($object->set($offset, $value))
  28. ->then
  29. ->variable($object->get($offset))->isIdenticalTo($value)
  30. ;
  31. }
  32. public function testSet()
  33. {
  34. $this
  35. ->if($object = new TestedClass())
  36. ->and($offset = uniqid())
  37. ->and($value = uniqid())
  38. ->then
  39. ->object($object->set($offset, $value))->isIdenticalTo($object)
  40. ->variable($object->get($offset))->isIdenticalTo($value)
  41. ;
  42. }
  43. public function testSetValues()
  44. {
  45. $this
  46. ->if($object = new TestedClass())
  47. ->and($values = array(uniqid() => uniqid()))
  48. ->then
  49. ->object($object->setValues($values))->isIdenticalTo($object)
  50. ->array($object->getValues())->isIdenticalTo($values)
  51. ;
  52. }
  53. public function testGetValues()
  54. {
  55. $this
  56. ->if($object = new TestedClass())
  57. ->then
  58. ->array($object->getValues())->isEmpty()
  59. ->if($values = array(uniqid() => uniqid()))
  60. ->and($object->setValues($values))
  61. ->then
  62. ->array($object->getValues())->isIdenticalTo($values)
  63. ;
  64. }
  65. public function testGetIterator()
  66. {
  67. $this
  68. ->if($object = new TestedClass())
  69. ->then
  70. ->object($object->getIterator())->isInstanceOf('\\RecursiveArrayIterator')
  71. ->array((array) $object->getIterator())->isEmpty()
  72. ->if($values = array(uniqid() => uniqid()))
  73. ->and($object->setValues($values))
  74. ->then
  75. ->array((array) $object->getIterator())->isEqualTo($values)
  76. ;
  77. }
  78. public function testDump()
  79. {
  80. $this
  81. ->if($object = new TestedClass())
  82. ->then
  83. ->exception(function() use($object) {
  84. $object->dump();
  85. })
  86. ->isInstanceOf('\\RuntimeException')
  87. ->hasMessage('No dumper available')
  88. ->mockGenerator->shuntParentClassCalls()
  89. ->if($dumper = new \mock\jubianchi\PhpSwitch\Config\Dumper(uniqid()))
  90. ->and($object->setDumper($dumper))
  91. ->then
  92. ->object($object->dump())->isIdenticalTo($object)
  93. ->mock($dumper)
  94. ->call('dump')->withArguments('.phpswitch.yml', $object)->once()
  95. ;
  96. }
  97. public function testSetDumper()
  98. {
  99. $this
  100. ->if($object = new TestedClass())
  101. ->and($dumper = new \mock\jubianchi\PhpSwitch\Config\Dumper(uniqid()))
  102. ->then
  103. ->object($object->setDumper($dumper))->isIdenticalTo($object)
  104. ->object($object->getDumper())->isIdenticalTo($dumper)
  105. ;
  106. }
  107. public function testGetDumper()
  108. {
  109. $this
  110. ->if($object = new TestedClass())
  111. ->then
  112. ->variable($object->getDumper())->isNull()
  113. ->if($dumper = new \mock\jubianchi\PhpSwitch\Config\Dumper(uniqid()))
  114. ->and($object->setDumper($dumper))
  115. ->then
  116. ->object($object->getDumper())->isIdenticalTo($dumper)
  117. ;
  118. }
  119. }