PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/units/classes/tools/diff.php

http://github.com/mageekguy/atoum
PHP | 148 lines | 134 code | 14 blank | 0 comment | 0 complexity | b037c6cd799915fc323aba9924050dd8 MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\tools;
  3. use
  4. atoum,
  5. atoum\tools
  6. ;
  7. require_once __DIR__ . '/../../runner.php';
  8. class diff extends atoum
  9. {
  10. public function test__construct()
  11. {
  12. $this
  13. ->if($this->newTestedInstance)
  14. ->then
  15. ->variable($this->testedInstance->getExpected())->isNull()
  16. ->variable($this->testedInstance->getActual())->isNull()
  17. ->object($this->testedInstance->getDecorator())->isEqualTo(new tools\diff\decorator())
  18. ->if($this->newTestedInstance($reference = uniqid()))
  19. ->then
  20. ->string($this->testedInstance->getExpected())->isEqualTo($reference)
  21. ->variable($this->testedInstance->getActual())->isNull()
  22. ->object($this->testedInstance->getDecorator())->isEqualTo(new tools\diff\decorator())
  23. ->if($this->newTestedInstance('', $data = uniqid()))
  24. ->then
  25. ->string($this->testedInstance->getExpected())->isEmpty()
  26. ->string($this->testedInstance->getActual())->isEqualTo($data)
  27. ->object($this->testedInstance->getDecorator())->isEqualTo(new tools\diff\decorator())
  28. ->if($this->newTestedInstance($reference = uniqid(), $data = uniqid()))
  29. ->then
  30. ->string($this->testedInstance->getExpected())->isEqualTo($reference)
  31. ->string($this->testedInstance->getActual())->isEqualTo($data)
  32. ->object($this->testedInstance->getDecorator())->isEqualTo(new tools\diff\decorator())
  33. ;
  34. }
  35. public function test__toString()
  36. {
  37. $this
  38. ->given(
  39. $this->newTestedInstance,
  40. $this->testedInstance->setDecorator($decorator = new \mock\atoum\tools\diff\decorator())
  41. )
  42. ->if($this->calling($decorator)->decorate = uniqid())
  43. ->then
  44. ->castToString($this->testedInstance)->isEqualTo($decorator->decorate($this->testedInstance))
  45. ;
  46. }
  47. public function test__invoke()
  48. {
  49. $this
  50. ->if($diff = $this->newTestedInstance)
  51. ->then
  52. ->castToString($diff())->isEmpty()
  53. ->object($diff())
  54. ->isIdenticalTo($diff)
  55. ->toString
  56. ->isEmpty()
  57. ->object($diff($expected = uniqid()))
  58. ->isIdenticalTo($diff)
  59. ->toString
  60. ->isNotEmpty()
  61. ->object($diff($expected = uniqid(), $actual = uniqid()))
  62. ->isIdenticalTo($diff)
  63. ->toString
  64. ->isNotEmpty()
  65. ;
  66. }
  67. public function testSetDecorator()
  68. {
  69. $this
  70. ->if($this->newTestedInstance)
  71. ->then
  72. ->object($this->testedInstance->setDecorator($decorator = new tools\diff\decorator()))->isTestedInstance
  73. ->object($this->testedInstance->getDecorator())->isIdenticalTo($decorator)
  74. ->object($this->testedInstance->setDecorator())->isTestedInstance
  75. ->object($this->testedInstance->getDecorator())
  76. ->isNotIdenticalTo($decorator)
  77. ->isEqualTo(new tools\diff\decorator())
  78. ;
  79. }
  80. public function testSetExpected()
  81. {
  82. $this
  83. ->if($this->newTestedInstance)
  84. ->then
  85. ->object($this->testedInstance->setExpected($reference = uniqid()))->isIdenticalTo($this->testedInstance)
  86. ->string($this->testedInstance->getExpected())->isEqualTo($reference)
  87. ;
  88. }
  89. public function testSetActual()
  90. {
  91. $this
  92. ->if($this->newTestedInstance)
  93. ->then
  94. ->object($this->testedInstance->setActual($data = uniqid()))->isIdenticalTo($this->testedInstance)
  95. ->string($this->testedInstance->getActual())->isEqualTo($data)
  96. ;
  97. }
  98. public function testMake()
  99. {
  100. $this
  101. ->if($this->newTestedInstance)
  102. ->then
  103. ->array($this->testedInstance->make())->isEqualTo(array(''))
  104. ->array($this->testedInstance->setActual($data = rand(0, 9))->make())->isEqualTo(array(
  105. array(
  106. '-' => array(''),
  107. '+' => array($data)
  108. )
  109. )
  110. )
  111. ->array($this->testedInstance->setActual($data = uniqid())->make())->isEqualTo(array(
  112. array(
  113. '-' => array(''),
  114. '+' => array($data)
  115. )
  116. )
  117. )
  118. ->array($this->testedInstance->setExpected($data)->make())->isEqualTo(array(
  119. $data
  120. )
  121. )
  122. ->array($this->testedInstance->setExpected('')->setActual(($firstLine = uniqid()). PHP_EOL . ($secondLine = uniqid()))->make())->isEqualTo(array(
  123. array(
  124. '-' => array(''),
  125. '+' => array(
  126. $firstLine,
  127. $secondLine
  128. )
  129. )
  130. )
  131. )
  132. ;
  133. }
  134. }