PageRenderTime 63ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

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