PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/units/classes/asserters/adapter/call/adapter.php

http://github.com/mageekguy/atoum
PHP | 101 lines | 93 code | 8 blank | 0 comment | 0 complexity | 69075bf1f5615da561412d18737b973a MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\asserters\adapter\call;
  3. require_once __DIR__ . '/../../../../runner.php';
  4. use
  5. mageekguy\atoum,
  6. mageekguy\atoum\test,
  7. mageekguy\atoum\asserter,
  8. mageekguy\atoum\asserters,
  9. mageekguy\atoum\asserters\adapter\call
  10. ;
  11. class adapter extends atoum\test
  12. {
  13. public function test__construct()
  14. {
  15. $this
  16. ->if($call = new call\adapter($adapterAsserter = new asserters\adapter(new asserter\generator()), $adapter = new test\adapter(), $functionName = uniqid()))
  17. ->then
  18. ->object($call->getMockAsserter())->isIdenticalTo($adapterAsserter)
  19. ->object($call->getAdapter())->isIdenticalTo($adapter)
  20. ->string($call->getFunctionName())->isEqualTo($functionName)
  21. ->variable($call->getArguments())->isNull()
  22. ->if($call = new call\adapter($adapterAsserter = new asserters\adapter(new asserter\generator()), $adapter = new test\adapter, $functionName = rand(1, PHP_INT_MAX)))
  23. ->then
  24. ->object($call->getMockAsserter())->isIdenticalTo($adapterAsserter)
  25. ->object($call->getAdapter())->isIdenticalTo($adapter)
  26. ->string($call->getFunctionName())->isEqualTo((string) $functionName)
  27. ->variable($call->getArguments())->isNull()
  28. ;
  29. }
  30. public function test__call()
  31. {
  32. $this
  33. ->if($call = new call\adapter($adapterAsserter = new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator()), new test\adapter(), uniqid()))
  34. ->and($adapterAsserter->getMockController()->call = $adapterAsserter)
  35. ->then
  36. ->object($call->call($arg = uniqid()))->isIdenticalTo($adapterAsserter)
  37. ->mock($adapterAsserter)
  38. ->call('call')->withArguments($arg)->once()
  39. ->if($unknownFunction = uniqid())
  40. ->then
  41. ->exception(function() use ($call, $unknownFunction) { $call->{$unknownFunction}(); })
  42. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  43. ->hasMessage('Method ' . get_class($adapterAsserter) . '::' . $unknownFunction . '() does not exist')
  44. ;
  45. }
  46. public function testWithArguments()
  47. {
  48. $this
  49. ->if($call = new call\adapter(new asserters\adapter(new asserter\generator()), new test\adapter(), uniqid()))
  50. ->then
  51. ->object($call->withArguments($arg = uniqid()))->isIdenticalTo($call)
  52. ->array($call->getArguments())->isEqualTo(array($arg))
  53. ->object($call->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($call)
  54. ->array($call->getArguments())->isEqualTo(array($arg1, $arg2))
  55. ;
  56. }
  57. public function testGetFirstCall()
  58. {
  59. $this
  60. ->if($call = new call\adapter( new asserters\adapter(new asserter\generator()), $adapter = new test\adapter(), 'md5'))
  61. ->then
  62. ->variable($call->getFirstCall())->isNull()
  63. ->if($otherAdapter = new test\adapter())
  64. ->and($otherAdapter->md5(uniqid()))
  65. ->then
  66. ->variable($call->getFirstCall())->isNull()
  67. ->if($adapter->md5(uniqid()))
  68. ->then
  69. ->integer($call->getFirstCall())->isEqualTo(2)
  70. ->if($adapter->md5(uniqid()))
  71. ->then
  72. ->integer($call->getFirstCall())->isEqualTo(2)
  73. ;
  74. }
  75. public function testGetLastCall()
  76. {
  77. $this
  78. ->if($call = new call\adapter(new asserters\adapter(new asserter\generator()), $adapter = new test\adapter(), 'md5'))
  79. ->then
  80. ->variable($call->getLastCall())->isNull()
  81. ->if($otherAdapter = new test\adapter())
  82. ->and($otherAdapter->md5(uniqid()))
  83. ->then
  84. ->variable($call->getLastCall())->isNull()
  85. ->if($adapter->md5(uniqid()))
  86. ->then
  87. ->integer($call->getLastCall())->isEqualTo(2)
  88. ->if($adapter->md5(uniqid()))
  89. ->then
  90. ->integer($call->getLastCall())->isEqualTo(3)
  91. ;
  92. }
  93. }