PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/asserter/generator.php

http://github.com/mageekguy/atoum
PHP | 155 lines | 131 code | 24 blank | 0 comment | 0 complexity | 0e864bef83a279496f4e94c41fd415d8 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\asserter;
  3. use
  4. mageekguy\atoum,
  5. mageekguy\atoum\asserter,
  6. mageekguy\atoum\test\assertion
  7. ;
  8. require_once __DIR__ . '/../../runner.php';
  9. class generator extends atoum\test
  10. {
  11. public function test__construct()
  12. {
  13. $this
  14. ->given($this->newTestedInstance)
  15. ->then
  16. ->object($this->testedInstance->getLocale())->isEqualTo(new atoum\locale())
  17. ->object($this->testedInstance->getResolver())->isEqualTo(new asserter\resolver())
  18. ->given($this->newTestedInstance($locale = new atoum\locale(), $resolver = new asserter\resolver(), $aliaser = new assertion\aliaser()))
  19. ->then
  20. ->object($this->testedInstance->getLocale())->isIdenticalTo($locale)
  21. ->object($this->testedInstance->getResolver())->isIdenticalTo($resolver)
  22. ;
  23. }
  24. public function test__get()
  25. {
  26. $this
  27. ->given($this->newTestedInstance)
  28. ->then
  29. ->exception(function($test) use (& $asserter) { $test->testedInstance->{$asserter = uniqid()}; })
  30. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  31. ->hasMessage('Asserter \'' . $asserter . '\' does not exist')
  32. ->object($this->testedInstance->variable)->isInstanceOf('mageekguy\atoum\asserters\variable')
  33. ;
  34. }
  35. public function test__call()
  36. {
  37. $this
  38. ->given($this->newTestedInstance)
  39. ->then
  40. ->exception(function($test) use (& $asserter) { $test->testedInstance->{$asserter = uniqid()}(); })
  41. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  42. ->hasMessage('Asserter \'' . $asserter . '\' does not exist')
  43. ->object($asserter = $this->testedInstance->variable($variable = uniqid()))->isInstanceOf('mageekguy\atoum\asserters\variable')
  44. ->string($asserter->getValue())->isEqualTo($variable)
  45. ;
  46. }
  47. public function testSetBaseClass()
  48. {
  49. $this
  50. ->given($this->newTestedInstance)
  51. ->if($this->testedInstance->setResolver($resolver = new \mock\atoum\asserter\resolver()))
  52. ->then
  53. ->object($this->testedInstance->setBaseClass($baseClass = uniqid()))->isTestedInstance
  54. ->mock($resolver)->call('setBaseClass')->withArguments($baseClass)->once
  55. ;
  56. }
  57. public function testGetBaseClass()
  58. {
  59. $this
  60. ->given($this->newTestedInstance)
  61. ->if(
  62. $this->testedInstance->setResolver($resolver = new \mock\atoum\asserter\resolver()),
  63. $this->calling($resolver)->getBaseClass = $baseClass = uniqid()
  64. )
  65. ->then
  66. ->string($this->testedInstance->getBaseClass())->isEqualTo($baseClass)
  67. ;
  68. }
  69. public function testAddNamespace()
  70. {
  71. $this
  72. ->given($this->newTestedInstance)
  73. ->if($this->testedInstance->setResolver($resolver = new \mock\atoum\asserter\resolver()))
  74. ->then
  75. ->object($this->testedInstance->addNamespace($namespace = uniqid()))->isTestedInstance
  76. ->mock($resolver)->call('addNamespace')->withArguments($namespace)->once
  77. ;
  78. }
  79. public function testGetNamespaces()
  80. {
  81. $this
  82. ->given($this->newTestedInstance)
  83. ->if(
  84. $this->testedInstance->setResolver($resolver = new \mock\atoum\asserter\resolver()),
  85. $this->calling($resolver)->getNamespaces = $namespaces = range(1, 5)
  86. )
  87. ->then
  88. ->array($this->testedInstance->getNamespaces())->isEqualTo($namespaces)
  89. ;
  90. }
  91. public function testSetLocale()
  92. {
  93. $this
  94. ->given($this->newTestedInstance)
  95. ->then
  96. ->object($this->testedInstance->setLocale($locale = new atoum\locale()))->isTestedInstance
  97. ->object($this->testedInstance->getLocale())->isIdenticalTo($locale)
  98. ->object($this->testedInstance->setLocale())->isTestedInstance
  99. ->object($this->testedInstance->getLocale())
  100. ->isNotIdenticalTo($locale)
  101. ->isEqualTo(new atoum\locale())
  102. ;
  103. }
  104. public function testSetResolver()
  105. {
  106. $this
  107. ->given($this->newTestedInstance)
  108. ->then
  109. ->object($this->testedInstance->setResolver($resolver = new asserter\resolver()))->isTestedInstance
  110. ->object($this->testedInstance->getResolver())->isIdenticalTo($resolver)
  111. ->object($this->testedInstance->setResolver())->isTestedInstance
  112. ->object($this->testedInstance->getResolver())
  113. ->isEqualTo(new asserter\resolver())
  114. ->isNotIdenticalTo($resolver)
  115. ;
  116. }
  117. public function testGetAsserterClass()
  118. {
  119. $this
  120. ->given($this->newTestedInstance->setResolver($resolver = new \mock\atoum\asserter\resolver()))
  121. ->if($this->calling($resolver)->resolve = null)
  122. ->then
  123. ->variable($this->testedInstance->getAsserterClass($asserter = uniqid()))->isNull()
  124. ->mock($resolver)->call('resolve')->withArguments($asserter)->once
  125. ->if($this->calling($resolver)->resolve = $class = uniqid())
  126. ->then
  127. ->string($this->testedInstance->getAsserterClass($asserter = uniqid()))->isEqualTo($class)
  128. ->mock($resolver)->call('resolve')->withArguments($asserter)->once
  129. ;
  130. }
  131. }