Skip to content

Commit 8311f71

Browse files
committed
Fixed issue with not processed @depend annotation - skipped test ignored (fixes allure-framework#21)
1 parent d3c3a1a commit 8311f71

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/Yandex/Allure/Adapter/AllureAdapter.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AllureAdapter implements PHPUnit_Framework_TestListener
2525
//NOTE: here we implicitly assume that PHPUnit runs in single-threaded mode
2626
private $uuid;
2727
private $suiteName;
28+
private $methodName;
2829

2930
/**
3031
* Annotations that should be ignored by the annotaions parser (especially PHPUnit annotations)
@@ -152,8 +153,21 @@ public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time)
152153
*/
153154
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
154155
{
156+
$shouldCreateStartStopEvents = false;
157+
if ($test instanceof \PHPUnit_Framework_TestCase){
158+
$methodName = $test->getName();
159+
if ($methodName !== $this->methodName){
160+
$shouldCreateStartStopEvents = true;
161+
$this->startTest($test);
162+
}
163+
}
164+
155165
$event = new TestCaseCanceledEvent();
156166
Allure::lifecycle()->fire($event->withException($e)->withMessage($e->getMessage()));
167+
168+
if ($shouldCreateStartStopEvents && $test instanceof \PHPUnit_Framework_TestCase){
169+
$this->endTest($test, 0);
170+
}
157171
}
158172

159173
/**
@@ -200,11 +214,14 @@ public function startTest(PHPUnit_Framework_Test $test)
200214
if ($test instanceof \PHPUnit_Framework_TestCase) {
201215
$suiteName = $this->suiteName;
202216
$methodName = $test->getName();
217+
$this->methodName = $methodName;
203218
$event = new TestCaseStartedEvent($this->uuid, get_class($test) . T_DOUBLE_COLON . $methodName);
204-
$annotationManager = new Annotation\AnnotationManager(
205-
Annotation\AnnotationProvider::getMethodAnnotations($suiteName, $methodName)
206-
);
207-
$annotationManager->updateTestCaseEvent($event);
219+
if (class_exists($suiteName, false) && method_exists($suiteName, $methodName)) {
220+
$annotationManager = new Annotation\AnnotationManager(
221+
Annotation\AnnotationProvider::getMethodAnnotations($suiteName, $methodName)
222+
);
223+
$annotationManager->updateTestCaseEvent($event);
224+
}
208225
Allure::lifecycle()->fire($event);
209226
}
210227
}

test/Yandex/Allure/Adapter/AllureAdapterTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ public function testAddSkippedTest()
107107
$events = $this->getMockedLifecycle()->getEvents();
108108
$event = new TestCaseCanceledEvent();
109109
$event->withException($exception)->withMessage(EXCEPTION_MESSAGE);
110-
$this->assertEquals(1, sizeof($events));
111-
$this->assertInstanceOf('\Yandex\Allure\Adapter\Event\TestCaseCanceledEvent', $events[0]);
112-
$this->assertEquals($event, $events[0]);
110+
$this->assertEquals(3, sizeof($events));
111+
$this->assertInstanceOf('\Yandex\Allure\Adapter\Event\TestCaseStartedEvent', $events[0]);
112+
$this->assertInstanceOf('\Yandex\Allure\Adapter\Event\TestCaseCanceledEvent', $events[1]);
113+
$this->assertInstanceOf('\Yandex\Allure\Adapter\Event\TestCaseFinishedEvent', $events[2]);
114+
$this->assertEquals($event, $events[1]);
113115
}
114116

115117
public function testStartTestSuite()

0 commit comments

Comments
 (0)