/** * endTest is called after each test and checks if \Mockery::close() has * been called, and will let the test fail if it hasn't. * * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest(\PHPUnit_Framework_Test $test, $time) { if (!$test instanceof \PHPUnit_Framework_TestCase) { // We need the getTestResultObject and getStatus methods which are // not part of the interface. return; } if ($test->getStatus() !== \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) { // If the test didn't pass there is no guarantee that // verifyMockObjects and assertPostConditions have been called. // And even if it did, the point here is to prevent false // negatives, not to make failing tests fail for more reasons. return; } try { // The self() call is used as a sentinel. Anything that throws if // the container is closed already will do. \Mockery::self(); } catch (\LogicException $_) { return; } $e = new \PHPUnit_Framework_ExpectationFailedException(sprintf("Mockery's expectations have not been verified. Make sure that \\Mockery::close() is called at the end of the test. Consider using %s\\MockeryPHPUnitIntegration or extending %s\\MockeryTestCase.", __NAMESPACE__, __NAMESPACE__)); $result = $test->getTestResultObject(); $result->addFailure($test, $e, $time); }
/** * After each test, perform Mockery verification tasks and cleanup the * statically stored Mockery container for the next test. * * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest(\PHPUnit_Framework_Test $test, $time) { try { \Mockery::close(); } catch (\Exception $e) { $result = $test->getTestResultObject(); $result->addError($test, $e, $time); } }
/** * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest(\PHPUnit_Framework_Test $test, $time) { try { if ($test instanceof \PHPUnit_Framework_TestCase) { $test->addToAssertionCount(MatcherAssert::getCount()); } } catch (\Exception $e) { $result = $test->getTestResultObject(); $result->addError($test, $e, $time); } }
/** * After each test, perform ehough_mockery_Mockery verification tasks and cleanup the * statically stored ehough_mockery_Mockery container for the next test. * * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest(PHPUnit_Framework_Test $test, $time) { try { $container = ehough_mockery_Mockery::getContainer(); if ($container != null) { $expectation_count = $container->mockery_getExpectationCount(); $test->addToAssertionCount($expectation_count); } ehough_mockery_Mockery::close(); } catch (Exception $e) { $result = $test->getTestResultObject(); $result->addError($test, $e, $time); } }
/** * A failure occurred. * * @todo Add check that $test is instance of PHPUnit_Framework_TestCase * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $failures = array(); $testResult = $test->getTestResultObject(); /** @var $failure PHPUnit_Framework_TestFailure */ foreach ($testResult->failures() as $failure) { $hash = "{$e->getMessage()} {$e->getTraceAsString()}"; if (isset($failures[$hash])) { continue; } $array = array('type' => self::MESSAGE_COMPARISON_FAILURE, 'name' => $test->getName(), 'message' => $e->getMessage(), 'details' => $e->getTraceAsString()); /** @var $exception PHPUnit_Framework_ExpectationFailedException */ $exception = $failure->thrownException(); $comparisonFailure = $exception->getComparisonFailure(); if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure) { $array += array('expected' => $comparisonFailure->getExpectedAsString(), 'actual' => $comparisonFailure->getActualAsString()); } $message = $this->getServiceMessage(self::MESSAGE_TEST_FAILED, $array); $this->write($message); $failures[$hash] = true; } }
/** * A test ended. * * @param PHPUnit_Framework_Test $test * @param float $time * @return void */ public function endTest(PHPUnit_Framework_Test $test, $time) { $t =& $this->test($test->getName()); if (!$t['status']) { $t['status'] = 'passed'; } $deprecated = $test->getTestResultObject()->deprecatedFeatures(); $t['deprecated'] = array_diff($deprecated, $this->deprecated); $t['assertions'] = $test->getNumAssertions(); $t['output'] = ob_get_contents(); $t['time'] = $time; $this->deprecated = $deprecated; $this->test(null); ob_end_clean(); }