/** * @param string $depends * @param array $expected * * @dataProvider dpDepends */ public function testDepends($depends, array $expected) { $method = new \ReflectionMethod($this->meta, 'setDependencies'); $method->setAccessible(true); $method->invoke($this->meta, ['depends' => $depends]); $this->assertEquals($expected, $this->meta->getDependencies()); }
/** * Check specified depends and run test if necessary. * * @param TestMeta $test * * @throws \LogicException If found infinitive depends loop */ public function resolveDependencies(TestMeta $test) { $depends = $test->getDependencies(); if (empty($depends)) { return; } $test->setStatus(TestMeta::TEST_MARKED); foreach ($depends as $depend) { $test = $this->getTestMethod($depend); if ($test->getStatus() === TestMeta::TEST_NEW) { if ($this->testMethod($test)) { /** @var SkipOnce $controller */ $controller = $this->controller->switchTo(ControllerParentInterface::CONTROLLER_SKIP_ONCE); $controller->setDepends(null); } } elseif ($test->getStatus() === TestMeta::TEST_MARKED) { throw new \LogicException(sprintf('Found infinitive loop in depends for test method "%s::%s()"', $this->reflectionClass->getName(), $depend)); } elseif ($test->getStatus() !== TestMeta::TEST_DONE) { /** @var SkipOnce $controller */ $controller = $this->controller->switchTo(ControllerParentInterface::CONTROLLER_SKIP_ONCE); $controller->setDepends(null); } } }
/** * Try to resolve situation with exception. * * @param TestMeta $test * @param MethodEvent $event * @param \Exception $exception * * @return int Status code */ private function exceptionControl(TestMeta $test, MethodEvent $event, \Exception $exception) { if (is_a($exception, $test->getExpectedException())) { $code = $test->getExpectedExceptionCode(); if ($code !== null && $code !== $exception->getCode()) { $error = new TestFailException(sprintf('Failed asserting that expected exception code %d is equal to %d', $code, $exception->getCode()), 0, $exception); $status = $this->context->onFailure($error); $this->finish($test, $event, MethodEvent::METHOD_FAILED, $exception); return $status; } $message = $test->getExpectedExceptionMessage(); if ($message !== null && strpos($exception->getMessage(), $message) === false) { $error = new TestFailException(sprintf('Failed asserting that exception message "%s" contains "%s"', $exception->getMessage(), $message), 0, $exception); $status = $this->context->onFailure($error); $this->finish($test, $event, MethodEvent::METHOD_FAILED, $exception); return $status; } return 0; } else { $this->context->onUnexpectedException($exception); return 1; } }
/** * Run test method. * * @param TestMeta $test Meta information about test method * @param MethodEvent $event Configured method event * @param array $dataSet Arguments for test * * @return int Status code */ public function test(TestMeta $test, MethodEvent $event, array $dataSet) { $test->setStatus(TestMeta::TEST_SKIPPED); $event->setStatus(MethodEvent::METHOD_SKIPPED); if ($this->depends !== null) { $event->addDepend($this->depends); } $this->dispatcher->dispatch(EventStorage::EV_METHOD_SKIPPED, clone $event); return 1; }
/** * @param TestMeta $test */ public function configByTestMeta(TestMeta $test) { $this->class = $test->getClass(); $this->method = $test->getMethod(); $this->depends = $test->getDependencies(); $this->annotations = $test->getAnnotations(); }