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

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

http://github.com/mageekguy/atoum
PHP | 92 lines | 84 code | 8 blank | 0 comment | 0 complexity | 0ad0dbd885277f701a7d26d1deaa0077 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\asserter,
  7. mageekguy\atoum\asserters,
  8. mageekguy\atoum\asserters\adapter\call
  9. ;
  10. class mock extends atoum\test
  11. {
  12. public function test__construct()
  13. {
  14. $this
  15. ->if($call = new call\mock($adapterAsserter = new asserters\adapter(new asserter\generator()), $mockAggregator = new \mock\dummy(), $methodName = uniqid()))
  16. ->then
  17. ->object($call->getAdapterAsserter())->isIdenticalTo($adapterAsserter)
  18. ->object($call->getMockAggregator())->isIdenticalTo($mockAggregator)
  19. ->string($call->getMethodName())->isEqualTo($methodName)
  20. ->variable($call->getArguments())->isNull()
  21. ->if($call = new call\mock($adapterAsserter = new asserters\adapter(new asserter\generator()), $mockAggregator = new \mock\dummy, $methodName = rand(1, PHP_INT_MAX)))
  22. ->then
  23. ->object($call->getAdapterAsserter())->isIdenticalTo($adapterAsserter)
  24. ->object($call->getMockAggregator())->isIdenticalTo($mockAggregator)
  25. ->string($call->getMethodName())->isEqualTo((string) $methodName)
  26. ->variable($call->getArguments())->isNull()
  27. ;
  28. }
  29. public function test__call()
  30. {
  31. $this
  32. ->if($call = new call\mock($adapterAsserter = new \mock\mageekguy\atoum\asserters\adapter(new asserter\generator()), new \mock\dummy(), uniqid()))
  33. ->and($adapterAsserter->getMockController()->call = $adapterAsserter)
  34. ->then
  35. ->object($call->call($arg = uniqid()))->isIdenticalTo($adapterAsserter)
  36. ->mock($adapterAsserter)
  37. ->call('call')->withArguments($arg)->once()
  38. ->if($unknownMethod = uniqid())
  39. ->then
  40. ->exception(function() use ($call, $unknownMethod) { $call->{$unknownMethod}(); })
  41. ->isInstanceOf('mageekguy\atoum\exceptions\logic\invalidArgument')
  42. ->hasMessage('Method ' . get_class($adapterAsserter) . '::' . $unknownMethod . '() does not exist')
  43. ;
  44. }
  45. public function testWithArguments()
  46. {
  47. $this
  48. ->if($call = new call\mock(new asserters\adapter(new asserter\generator()), new \mock\dummy(), uniqid()))
  49. ->then
  50. ->object($call->withArguments($arg = uniqid()))->isIdenticalTo($call)
  51. ->array($call->getArguments())->isEqualTo(array($arg))
  52. ->object($call->withArguments($arg1 = uniqid(), $arg2 = uniqid()))->isIdenticalTo($call)
  53. ->array($call->getArguments())->isEqualTo(array($arg1, $arg2))
  54. ;
  55. }
  56. public function testGetFirstCall()
  57. {
  58. $this
  59. ->if($call = new call\mock(new asserters\adapter(new asserter\generator()), $mock = new \mock\dummy(), 'foo'))
  60. ->then
  61. ->variable($call->getFirstCall())->isNull()
  62. ->when(function() { $otherMock = new \mock\dummy(); $otherMock->foo(); })
  63. ->variable($call->getFirstCall())->isNull()
  64. ->when(function() use ($mock) { $mock->foo(); })
  65. ->integer($call->getFirstCall())->isEqualTo(2)
  66. ->when(function() use ($mock) { $mock->foo(); })
  67. ->integer($call->getFirstCall())->isEqualTo(2)
  68. ;
  69. }
  70. public function testGetLastCall()
  71. {
  72. $this
  73. ->if($call = new call\mock(new asserters\adapter(new asserter\generator()), $mock = new \mock\dummy(), 'foo'))
  74. ->then
  75. ->variable($call->getLastCall())->isNull()
  76. ->when(function() { $otherMock = new \mock\dummy(); $otherMock->foo(); })
  77. ->variable($call->getLastCall())->isNull()
  78. ->when(function() use ($mock) { $mock->foo(); })
  79. ->integer($call->getLastCall())->isEqualTo(2)
  80. ->when(function() use ($mock) { $mock->foo(); })
  81. ->integer($call->getLastCall())->isEqualTo(3)
  82. ;
  83. }
  84. }