PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/jubianchi/PhpSwitch/Console/Application.php

https://github.com/horechek/phpswitch
PHP | 147 lines | 135 code | 12 blank | 0 comment | 0 complexity | 6d1172e7f897d0456b4d8a5f59a82891 MD5 | raw file
  1. <?php
  2. namespace tests\units\jubianchi\PhpSwitch\Console;
  3. use mageekguy\atoum;
  4. use jubianchi\PhpSwitch\Console\Application as TestedClass;
  5. require_once __DIR__ . '/../../../../bootstrap.php';
  6. class Application extends atoum\test
  7. {
  8. public function testClass()
  9. {
  10. $this
  11. ->testedClass
  12. ->isSubclassOf('\\Symfony\\Component\\Console\\Application')
  13. ;
  14. }
  15. public function test__construct()
  16. {
  17. $this
  18. ->if($object = new TestedClass())
  19. ->then
  20. ->string($object->getName())->isEqualTo('phpswitch')
  21. ->string($object->getVersion())->isEqualTo('0.1')
  22. ;
  23. }
  24. public function testSetConfiguration()
  25. {
  26. $this
  27. ->if($object = new TestedClass())
  28. ->and($config = new \mock\jubianchi\PhpSwitch\Config\Configuration())
  29. ->then
  30. ->object($object->setConfiguration($config))->isIdenticalTo($object)
  31. ->object($object->getConfiguration())->isIdenticalTo($config)
  32. ;
  33. }
  34. public function testGetDownloader()
  35. {
  36. $this
  37. ->if($object = new TestedClass())
  38. ->and($container = new \mock\Pimple())
  39. ->and($container->getMockController()->offsetGet = $downloader = new \mock\jubianchi\PhpSwitch\PHP\Downloader(uniqid()))
  40. ->and($object->setContainer($container))
  41. ->then
  42. ->object($object->getDownloader())->isIdenticalTo($downloader)
  43. ->mock($container)
  44. ->call('offsetGet')->withArguments('app.php.downloader')->once()
  45. ;
  46. }
  47. public function testGetExtracter()
  48. {
  49. $this
  50. ->if($object = new TestedClass())
  51. ->and($container = new \mock\Pimple())
  52. ->and($container->getMockController()->offsetGet = $extracter = new \mock\jubianchi\PhpSwitch\PHP\Extracter(uniqid()))
  53. ->and($object->setContainer($container))
  54. ->then
  55. ->object($object->getExtracter())->isIdenticalTo($extracter)
  56. ->mock($container)
  57. ->call('offsetGet')->withArguments('app.php.extracter')->once()
  58. ;
  59. }
  60. public function testGetBuilder()
  61. {
  62. $this
  63. ->if($object = new TestedClass())
  64. ->and($container = new \mock\Pimple())
  65. ->and($container->getMockController()->offsetGet = $builder = new \mock\jubianchi\PhpSwitch\PHP\Builder(uniqid()))
  66. ->and($object->setContainer($container))
  67. ->then
  68. ->object($object->getBuilder())->isIdenticalTo($builder)
  69. ->mock($container)
  70. ->call('offsetGet')->withArguments('app.php.builder')->once()
  71. ;
  72. }
  73. public function testGetOptionFinder()
  74. {
  75. $this
  76. ->if($object = new TestedClass())
  77. ->and($container = new \mock\Pimple())
  78. ->mockGenerator->shuntParentClassCalls()
  79. ->and($container->getMockController()->offsetGet = $builder = new \mock\jubianchi\PhpSwitch\PHP\Option\Finder(uniqid(), uniqid()))
  80. ->and($object->setContainer($container))
  81. ->then
  82. ->object($object->getOptionFinder())->isIdenticalTo($builder)
  83. ->mock($container)
  84. ->call('offsetGet')->withArguments('app.php.option.finder')->once()
  85. ;
  86. }
  87. public function testGetContainer()
  88. {
  89. $this
  90. ->if($object = new TestedClass())
  91. ->then
  92. ->variable($object->getContainer())->isNull()
  93. ->if($container = new \mock\Pimple())
  94. ->and($object->setContainer($container))
  95. ->then
  96. ->object($object->getContainer())->isIdenticalTo($container)
  97. ;
  98. }
  99. public function testSetContainer()
  100. {
  101. $this
  102. ->if($object = new TestedClass())
  103. ->and($container = new \mock\Pimple())
  104. ->then
  105. ->object($object->setContainer($container))->isIdenticalTo($object)
  106. ->object($object->getContainer())->isIdenticalTo($container)
  107. ;
  108. }
  109. public function testGetService()
  110. {
  111. $this
  112. ->if($object = new TestedClass())
  113. ->then
  114. ->exception(function() use($object) {
  115. $object->getService(uniqid());
  116. })
  117. ->isInstanceOf('\\RuntimeException')
  118. ->hasMessage('No service container defined')
  119. ->if($container = new \mock\Pimple())
  120. ->and($object->setContainer($container))
  121. ->and($service = uniqid())
  122. ->then
  123. ->exception(function() use($object, $service) {
  124. $object->getService($service);
  125. })
  126. ->isInstanceOf('\\InvalidArgumentException')
  127. ->hasMessage(sprintf('Identifier "%s" is not defined.', $service))
  128. ->mock($container)
  129. ->call('offsetGet')->withArguments($service)->once()
  130. ->if($container[$service] = $value = uniqid())
  131. ->then
  132. ->string($object->getService($service))->isEqualTo($value)
  133. ;
  134. }
  135. }