Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Yandex/Allure/Adapter/Annotation/AllureId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Yandex\Allure\Adapter\Annotation;

use Doctrine\Common\Annotations\Annotation\Required;

/**
* @Annotation
* @Target({"METHOD"})
* @package Yandex\Allure\Adapter\Annotation
*/
class AllureId
{
/**
* @var string
* @Required
*/
public $value;
}
11 changes: 9 additions & 2 deletions src/Yandex/Allure/Adapter/Annotation/AnnotationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Yandex\Allure\Adapter\Annotation;

use Doctrine\Common\Annotations\Annotation;
use Yandex\Allure\Adapter\Event\TestCaseStartedEvent;
use Yandex\Allure\Adapter\Event\TestSuiteStartedEvent;
use Yandex\Allure\Adapter\Model;
Expand Down Expand Up @@ -40,7 +39,9 @@ public function __construct(array $annotations)
private function processAnnotations(array $annotations)
{
foreach ($annotations as $annotation) {
if ($annotation instanceof Title) {
if ($annotation instanceof AllureId) {
$this->labels[] = Model\Label::id($annotation->value);
} elseif ($annotation instanceof Title) {
$this->title = $annotation->value;
} elseif ($annotation instanceof Description) {
$this->description = new Model\Description(
Expand Down Expand Up @@ -83,6 +84,12 @@ private function processAnnotations(array $annotations)
$parameter->kind
);
}
} elseif ($annotation instanceof Label) {
$this->labels[] = Model\Label::label($annotation->name, $annotation->value);
} elseif ($annotation instanceof Labels) {
foreach ($annotation -> labels as $label) {
$this->labels[] = Model\Label::label($label->name, $label->value);
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/Yandex/Allure/Adapter/Annotation/Label.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Yandex\Allure\Adapter\Annotation;

use Doctrine\Common\Annotations\Annotation\Required;
use Yandex\Allure\Adapter\Model\ParameterKind;

/**
* @Annotation
* @Target({"METHOD", "ANNOTATION"})
* @package Yandex\Allure\Adapter\Annotation
*/
class Label
{
/**
* @var string
* @Required
*/
public $name;

/**
* @var string
* @Required
*/
public $value;

}
17 changes: 17 additions & 0 deletions src/Yandex/Allure/Adapter/Annotation/Labels.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Yandex\Allure\Adapter\Annotation;

/**
* @Annotation
* @Target({"METHOD"})
* @package Yandex\Allure\Adapter\Annotation
*/
class Labels
{
/**
* @var array<Yandex\Allure\Adapter\Annotation\Label>
* @Required
*/
public $labels;
}
18 changes: 18 additions & 0 deletions src/Yandex/Allure/Adapter/Model/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public function getValue()
return $this->value;
}

/**
* @param $id
* @return Label
*/
public static function id($id)
{
return new Label(LabelType::ID, $id);
}
/**
* @param $featureName
* @return Label
Expand Down Expand Up @@ -104,4 +112,14 @@ public static function testId($testCaseId)
return new Label(LabelType::TEST_ID, $testCaseId);
}

/**
* @param $name
* @param $value
*
* @return Label
*/
public static function label($name, $value)
{
return new Label($name, $value);
}
}
1 change: 1 addition & 0 deletions src/Yandex/Allure/Adapter/Model/LabelType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class LabelType
{
const ID = 'AS_ID';
const FEATURE = 'feature';
const STORY = 'story';
const SEVERITY = 'severity';
Expand Down
19 changes: 18 additions & 1 deletion test/Yandex/Allure/Adapter/Annotation/AnnotationManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ public function testUpdateTestCaseStartedEvent()
$this->assertEquals('test-case-title', $event->getTitle());
$this->assertEquals('test-case-description', $event->getDescription()->getValue());
$this->assertEquals(DescriptionType::HTML, $event->getDescription()->getType());
$this->assertEquals(7, sizeof($event->getLabels()));
$this->assertEquals(10, sizeof($event->getLabels()));

//Check id presence
$ids = $this->getLabelsByType($event->getLabels(), LabelType::ID);
$this->assertEquals(1, sizeof($ids));
$id = array_pop($ids);
$this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $id);
$this->assertSame("123", $id->getValue());

//Check feature presence
$features = $this->getLabelsByType($event->getLabels(), LabelType::FEATURE);
Expand Down Expand Up @@ -101,6 +108,16 @@ public function testUpdateTestCaseStartedEvent()
$index++;
}

//Check custom labels presence
$customs = $this->getLabelsByType($event->getLabels(), "custom-name");
$this->assertEquals(2, sizeof($customs));
$index = 1;
foreach ($customs as $custom) {
$this->assertInstanceOf('Yandex\Allure\Adapter\Model\Label', $custom);
$this->assertEquals("custom-value-$index", $custom->getValue());
$index++;
}

//Check severity presence
$severities = $this->getLabelsByType($event->getLabels(), LabelType::SEVERITY);
$this->assertEquals(1, sizeof($severities));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Yandex\Allure\Adapter\Annotation\Fixtures;

use Yandex\Allure\Adapter\Annotation\AllureId;
use Yandex\Allure\Adapter\Annotation\Issues;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Annotation\Description;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Severity;
use Yandex\Allure\Adapter\Annotation\Label;
use Yandex\Allure\Adapter\Annotation\Labels;
use Yandex\Allure\Adapter\Annotation\Parameter;
use Yandex\Allure\Adapter\Model\DescriptionType;
use Yandex\Allure\Adapter\Model\SeverityLevel;
Expand All @@ -23,12 +26,17 @@
class ExampleTestSuite
{
/**
* @AllureId("123")
* @Title("test-case-title")
* @Description(value="test-case-description", type=DescriptionType::HTML)
* @Features({"test-case-feature1", "test-case-feature2"})
* @Stories({"test-case-story1", "test-case-story2"})
* @Severity(SeverityLevel::BLOCKER)
* @Parameter(name = "test-case-param-name", value = "test-case-param-value", kind = ParameterKind::ARGUMENT)
* @Labels({
* @Label(name = "custom-name", value = "custom-value-1"),
* @Label(name = "custom-name", value = "custom-value-2")
* })
* @Issues({"test-case-issue1", "test-case-issue2"})
*/
public function exampleTestCase()
Expand Down