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

/tests/units/classes/test/engines/concurrent.php

http://github.com/mageekguy/atoum
PHP | 124 lines | 115 code | 9 blank | 0 comment | 0 complexity | 36cb6531fda091dda441d2dd2a82a12b MD5 | raw file
  1. <?php
  2. namespace mageekguy\atoum\tests\units\test\engines;
  3. require_once __DIR__ . '/../../../runner.php';
  4. use
  5. mageekguy\atoum,
  6. mageekguy\atoum\test\engines\concurrent as testedClass
  7. ;
  8. class concurrent extends atoum\test
  9. {
  10. public function testClass()
  11. {
  12. $this->testedClass->extends('mageekguy\atoum\test\engine');
  13. }
  14. public function test__construct()
  15. {
  16. $this
  17. ->if($engine = new testedClass())
  18. ->then
  19. ->object($defaultScoreFactory = $engine->getScoreFactory())->isInstanceOf('closure')
  20. ->object($defaultScoreFactory())->isInstanceOf('mageekguy\atoum\score')
  21. ->object($engine->getPhp())->isEqualTo(new atoum\php())
  22. ;
  23. }
  24. public function testSetPhp()
  25. {
  26. $this
  27. ->if($engine = new testedClass())
  28. ->then
  29. ->object($engine->setPhp($php = new atoum\php()))->isIdenticalTo($engine)
  30. ->object($engine->getPhp())->isIdenticalTo($php)
  31. ->object($engine->setPhp())->isIdenticalTo($engine)
  32. ->object($engine->getPhp())
  33. ->isEqualTo(new atoum\php())
  34. ->isNotIdenticalTo($php)
  35. ;
  36. }
  37. public function testIsAsynchronous()
  38. {
  39. $this
  40. ->if($engine = new testedClass())
  41. ->then
  42. ->boolean($engine->isAsynchronous())->isTrue()
  43. ;
  44. }
  45. public function testRun()
  46. {
  47. $this
  48. ->if($engine = new testedClass())
  49. ->and($engine->setPhp($php = new \mock\mageekguy\atoum\php()))
  50. ->then
  51. ->object($engine->run($test = new \mock\mageekguy\atoum\test()))->isIdenticalTo($engine)
  52. ->if($test->getMockController()->getCurrentMethod = $method = uniqid())
  53. ->and($test->getMockController()->getPath = $testPath = uniqid())
  54. ->and($test->getMockController()->getPhpPath = $phpPath = uniqid())
  55. ->and($test->getMockController()->codeCoverageIsEnabled = false)
  56. ->and($test->getMockController()->getBootstrapFile = null)
  57. ->and($test->setXdebugConfig($xdebugConfig = uniqid()))
  58. ->and($this->calling($php)->run->throw = $exception = new atoum\php\exception())
  59. ->and($this->function->getenv = false)
  60. ->and($this->function->ini_get = 0)
  61. ->then
  62. ->exception(function() use ($engine, $test) { $engine->run($test); })
  63. ->isIdenticalTo($exception)
  64. ->if($this->calling($php)->run = $php)
  65. ->then
  66. ->object($engine->run($test))->isIdenticalTo($engine)
  67. ->mock($php)
  68. ->call('run')->withArguments(
  69. '<?php ' .
  70. 'ob_start();' .
  71. 'require \'' . atoum\directory . '/classes/autoloader.php\';' .
  72. 'require \'' . $testPath . '\';' .
  73. '$test = new ' . get_class($test) . '();' .
  74. '$test->setLocale(new ' . get_class($test->getLocale()) . '(' . $test->getLocale()->get() . '));' .
  75. '$test->setPhpPath(\'' . $phpPath . '\');' .
  76. '$test->disableCodeCoverage();' .
  77. 'ob_end_clean();' .
  78. 'mageekguy\atoum\scripts\runner::disableAutorun();' .
  79. 'echo serialize($test->runTestMethod(\'' . $method . '\')->getScore());'
  80. )->twice()
  81. ->call('__set')->withArguments('XDEBUG_CONFIG', $xdebugConfig)->twice()
  82. ;
  83. }
  84. public function testGetScore()
  85. {
  86. $this
  87. ->if($engine = new testedClass())
  88. ->and($engine->setPhp($php = new \mock\mageekguy\atoum\php()))
  89. ->and($this->calling($php)->run = $php)
  90. ->and($this->calling($php)->isRunning = false)
  91. ->then
  92. ->variable($engine->getScore())->isNull()
  93. ->if($engine->run($test = new \mock\mageekguy\atoum\test()))
  94. ->and($this->calling($php)->isRunning = true)
  95. ->then
  96. ->variable($engine->getScore())->isNull()
  97. ->if( $this->calling($test)->getCurrentMethod = $method = uniqid())
  98. ->and($this->calling($test)->getPath = $testPath = uniqid())
  99. ->and($this->calling($test)->getPhpPath = $phpPath = uniqid())
  100. ->and($this->calling($test)->codeCoverageIsEnabled = false)
  101. ->and($this->calling($test)->getBootstrapFile = null)
  102. ->and($this->calling($php)->isRunning = false)
  103. ->and($this->calling($php)->getStdOut = $output = uniqid())
  104. ->and($this->calling($php)->getExitCode = $exitCode = uniqid())
  105. ->and($engine->run($test))
  106. ->then
  107. ->object($score = $engine->getScore())->isInstanceOf('mageekguy\atoum\score')
  108. ->array($score->getUncompletedMethods())->isEqualTo(array(array('file' => $testPath, 'class' => get_class($test), 'method' => $method, 'exitCode' => $exitCode, 'output' => $output)))
  109. ->if($this->calling($php)->getStdOut = serialize($score))
  110. ->and($engine->run($test))
  111. ->then
  112. ->object($score = $engine->getScore())->isEqualTo($score)
  113. ;
  114. }
  115. }