Skip to content

Commit b1f2bf0

Browse files
authored
use commons 2.0.0 (via #87)
1 parent 79a583a commit b1f2bf0

32 files changed

+139
-126
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,42 @@ extensions:
3131
enabled:
3232
- Qameta\Allure\Codeception\AllureCodeception
3333
config:
34-
Qameta\Allure\Codeception\AllureCodeception:
34+
Qameta\Allure\Codeception\AllureCodeception:
3535
outputDirectory: allure-results
36+
linkTemplates:
37+
issue: https://example.org/issues/%s
38+
setipHook: My\SetupHook
3639
```
3740
3841
`outputDirectory` is used to store Allure results and will be calculated
3942
relatively to Codeception output directory (also known as `paths: log` in
4043
codeception.yml) unless you specify an absolute path. You can traverse up using
4144
`..` as usual. `outputDirectory` defaults to `allure-results`.
4245

46+
`linkTemplates` is used to process links and generate URLs for them. You can put
47+
here an `sprintf()`-like template or a name of class to be constructed; such class
48+
must implement `Qameta\Allure\Setup\LinkTemplateInterface`.
49+
50+
`setupHook` allows to execute some bootstrapping code during initialization. You can
51+
put here a name of the class that implements magic `__invoke()` method - and that method
52+
will be called. For example, it can be used to ignore unnecessary docblock annotations:
53+
54+
```php
55+
<?php
56+
57+
namespace My;
58+
59+
use Doctrine\Common\Annotations\AnnotationReader;
60+
61+
class SetupHook
62+
{
63+
public function __invoke(): void
64+
{
65+
AnnotationReader::addGlobalIgnoredName('annotationToIgnore');
66+
}
67+
}
68+
```
69+
4370
To generate report from your favourite terminal,
4471
[install](https://github.com/allure-framework/allure-cli#installation)
4572
allure-cli and run following command (assuming you're in project root and using

codeception.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ extensions:
1313
config:
1414
Qameta\Allure\Codeception\AllureCodeception:
1515
outputDirectory: allure-results
16-
17-
16+
linkTemplates:
17+
issue: https://example.org/issues/%s

composer.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@
2424
"php": "^8",
2525
"ext-json": "*",
2626
"codeception/codeception": "^4.1",
27-
"allure-framework/allure-php-commons": "2.0.0-rc3"
27+
"allure-framework/allure-php-commons": "^2"
2828
},
2929
"require-dev": {
30-
"ext-dom": "*",
3130
"phpunit/phpunit": "^9",
3231
"psalm/plugin-phpunit": "^0.16.1",
3332
"remorhaz/php-json-data": "^0.5.3",
3433
"remorhaz/php-json-path": "^0.7.7",
35-
"squizlabs/php_codesniffer": "^3.6.1",
36-
"vimeo/psalm": "^4.10"
34+
"squizlabs/php_codesniffer": "^3.6.2",
35+
"vimeo/psalm": "^4.20"
3736
},
3837
"conflict": {
3938
"codeception/phpunit-wrapper": "<9.0.1"

src/AllureCodeception.php

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
use Codeception\Step;
1616
use Qameta\Allure\Allure;
1717
use Qameta\Allure\Allure as QametaAllure;
18-
use Qameta\Allure\Attribute\LinkTemplateInterface;
1918
use Qameta\Allure\Codeception\Internal\DefaultThreadDetector;
2019
use Qameta\Allure\Codeception\Internal\SuiteInfo;
2120
use Qameta\Allure\Codeception\Internal\TestLifecycle;
2221
use Qameta\Allure\Codeception\Internal\TestLifecycleInterface;
2322
use Qameta\Allure\Codeception\Setup\ThreadDetectorInterface;
23+
use Qameta\Allure\Model\LinkType;
2424
use Qameta\Allure\Model\Status;
2525
use Qameta\Allure\Model\StatusDetails;
2626
use Qameta\Allure\Setup\DefaultStatusDetector;
27+
use Qameta\Allure\Setup\LinkTemplate;
28+
use Qameta\Allure\Setup\LinkTemplateInterface;
2729
use Throwable;
2830

2931
use function class_exists;
32+
use function is_a;
33+
use function is_array;
3034
use function is_callable;
3135
use function is_string;
3236
use function trim;
@@ -35,9 +39,9 @@
3539

3640
final class AllureCodeception extends Extension
3741
{
38-
3942
private const SETUP_HOOK_PARAMETER = 'setupHook';
4043
private const OUTPUT_DIRECTORY_PARAMETER = 'outputDirectory';
44+
private const LINK_TEMPLATES_PARAMETER = 'linkTemplates';
4145

4246
private const DEFAULT_RESULTS_DIRECTORY = 'allure-results';
4347

@@ -55,11 +59,6 @@ final class AllureCodeception extends Extension
5559
Events::STEP_AFTER => 'stepAfter'
5660
];
5761

58-
/**
59-
* @var array<string, LinkTemplateInterface>
60-
*/
61-
private array $linkTemplates = [];
62-
6362
private ?ThreadDetectorInterface $threadDetector = null;
6463

6564
private ?TestLifecycleInterface $testLifecycle = null;
@@ -76,9 +75,12 @@ public function _initialize(): void
7675
parent::_initialize();
7776
QametaAllure::reset();
7877
QametaAllure::getLifecycleConfigurator()
79-
->setStatusDetector(new StatusDetector(new DefaultStatusDetector()));
78+
->setStatusDetector(new StatusDetector(new DefaultStatusDetector()))
79+
->setOutputDirectory($this->getOutputDirectory());
80+
foreach ($this->getLinkTemplates() as $linkType => $linkTemplate) {
81+
QametaAllure::getLifecycleConfigurator()->addLinkTemplate($linkType, $linkTemplate);
82+
}
8083
$this->callSetupHook();
81-
QametaAllure::setOutputDirectory($this->getOutputDirectory());
8284
}
8385

8486
private function callSetupHook(): void
@@ -115,6 +117,31 @@ private function getOutputDirectory(): string
115117
return Configuration::outputDir() . ($outputLocal ?? self::DEFAULT_RESULTS_DIRECTORY) . DIRECTORY_SEPARATOR;
116118
}
117119

120+
/**
121+
* @psalm-suppress MoreSpecificReturnType
122+
* @return iterable<LinkType, LinkTemplate>
123+
*/
124+
private function getLinkTemplates(): iterable
125+
{
126+
/**
127+
* @var mixed $templatesConfig
128+
* @psalm-var array $this->config
129+
*/
130+
$templatesConfig = $this->config[self::LINK_TEMPLATES_PARAMETER] ?? [];
131+
if (!is_array($templatesConfig)) {
132+
$templatesConfig = [];
133+
}
134+
foreach ($templatesConfig as $linkTypeName => $linkConfig) {
135+
if (!is_string($linkConfig) || !is_string($linkTypeName)) {
136+
continue;
137+
}
138+
yield LinkType::fromOptionalString($linkTypeName) =>
139+
class_exists($linkConfig) && is_a($linkConfig, LinkTemplateInterface::class, true)
140+
? new $linkConfig()
141+
: new LinkTemplate($linkConfig);
142+
}
143+
}
144+
118145
/**
119146
* @psalm-suppress MissingDependency
120147
*/
@@ -270,10 +297,10 @@ private function getTestLifecycle(): TestLifecycleInterface
270297
{
271298
return $this->testLifecycle ??= new TestLifecycle(
272299
Allure::getLifecycle(),
273-
Allure::getResultFactory(),
274-
Allure::getStatusDetector(),
300+
Allure::getConfig()->getResultFactory(),
301+
Allure::getConfig()->getStatusDetector(),
275302
$this->getThreadDetector(),
276-
$this->linkTemplates,
303+
Allure::getConfig()->getLinkTemplates(),
277304
);
278305
}
279306
}

src/Internal/ArgumentAsString.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Stringable;
99

1010
use function array_map;
11+
use function class_exists;
1112
use function is_a;
1213
use function is_array;
1314
use function is_object;
@@ -22,7 +23,6 @@
2223
*/
2324
final class ArgumentAsString implements Stringable
2425
{
25-
2626
public function __construct(
2727
private mixed $argument,
2828
) {
@@ -75,7 +75,8 @@ private function prepareObject(object $argument): string
7575
return (string) $argument;
7676
}
7777

78-
if (is_a($argument, 'Facebook\WebDriver\WebDriverBy')) {
78+
$webdriverByClass = '\Facebook\WebDriver\WebDriverBy';
79+
if (class_exists($webdriverByClass) && is_a($argument, $webdriverByClass)) {
7980
return Locator::humanReadableString($argument);
8081
}
8182

src/Internal/CeptInfoBuilder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
final class CeptInfoBuilder implements TestInfoBuilderInterface
1010
{
11-
1211
public function __construct(
1312
private Cept $test,
1413
) {

src/Internal/CeptProvider.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Qameta\Allure\Codeception\Internal;
66

77
use Codeception\Test\Cept;
8-
use Qameta\Allure\Attribute\LinkTemplateInterface;
8+
use Qameta\Allure\Setup\LinkTemplateCollectionInterface;
99
use Qameta\Allure\Model\Label;
1010
use Qameta\Allure\Model\Link;
1111
use Qameta\Allure\Model\LinkType;
@@ -27,7 +27,6 @@
2727
*/
2828
final class CeptProvider implements ModelProviderInterface
2929
{
30-
3130
private bool $isLoaded = false;
3231

3332
/**
@@ -45,21 +44,21 @@ final class CeptProvider implements ModelProviderInterface
4544
private ?string $legacyDescription = null;
4645

4746
/**
48-
* @param Cept $test
49-
* @param array<string, LinkTemplateInterface> $linkTemplates
47+
* @param Cept $test
48+
* @param LinkTemplateCollectionInterface $linkTemplates
5049
*/
5150
public function __construct(
5251
private Cept $test,
53-
private array $linkTemplates = [],
52+
private LinkTemplateCollectionInterface $linkTemplates,
5453
) {
5554
}
5655

5756
/**
58-
* @param Cept $test
59-
* @param array<string, LinkTemplateInterface> $linkTemplates
57+
* @param Cept $test
58+
* @param LinkTemplateCollectionInterface $linkTemplates
6059
* @return list<ModelProviderInterface>
6160
*/
62-
public static function createForChain(Cept $test, array $linkTemplates): array
61+
public static function createForChain(Cept $test, LinkTemplateCollectionInterface $linkTemplates): array
6362
{
6463
return [new self($test, $linkTemplates)];
6564
}
@@ -83,14 +82,6 @@ public function getParameters(): array
8382
return [];
8483
}
8584

86-
/**
87-
* @deprecated Please use {@see getDisplayName()} method
88-
*/
89-
public function getTitle(): ?string
90-
{
91-
return $this->getDisplayName();
92-
}
93-
9485
public function getDisplayName(): ?string
9586
{
9687
$this->loadLegacyModels();
@@ -107,6 +98,11 @@ public function getDisplayName(): ?string
10798
: null;
10899
}
109100

101+
public function getFullName(): ?string
102+
{
103+
return (string) $this->test->getSignature();
104+
}
105+
110106
public function getDescription(): ?string
111107
{
112108
$this->loadLegacyModels();
@@ -179,7 +175,7 @@ private function loadLegacyModels(): void
179175
$this->getLegacyAnnotations('Stories'),
180176
),
181177
];
182-
$linkTemplate = $this->linkTemplates[(string) LinkType::issue()] ?? null;
178+
$linkTemplate = $this->linkTemplates->get(LinkType::issue()) ?? null;
183179
$this->legacyLinks = array_map(
184180
fn (string $value): Link => Link::issue($value, $linkTemplate?->buildUrl($value)),
185181
$this->getLegacyAnnotations('Issues'),

src/Internal/CestInfoBuilder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
final class CestInfoBuilder implements TestInfoBuilderInterface
1414
{
15-
1615
public function __construct(
1716
private Cest $test,
1817
) {

src/Internal/CestProvider.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Codeception\Test\Cest;
88
use Qameta\Allure\Attribute\AttributeParser;
9-
use Qameta\Allure\Attribute\LinkTemplateInterface;
9+
use Qameta\Allure\Setup\LinkTemplateCollectionInterface;
1010
use Qameta\Allure\Model\ModelProviderInterface;
1111
use Qameta\Allure\Model\Parameter;
1212
use ReflectionException;
@@ -24,19 +24,18 @@
2424
*/
2525
final class CestProvider implements ModelProviderInterface
2626
{
27-
2827
public function __construct(
2928
private Cest $test,
3029
) {
3130
}
3231

3332
/**
34-
* @param Cest $test
35-
* @param array<string, LinkTemplateInterface> $linkTemplates
33+
* @param Cest $test
34+
* @param LinkTemplateCollectionInterface $linkTemplates
3635
* @return list<ModelProviderInterface>
3736
* @throws ReflectionException
3837
*/
39-
public static function createForChain(Cest $test, array $linkTemplates = []): array
38+
public static function createForChain(Cest $test, LinkTemplateCollectionInterface $linkTemplates): array
4039
{
4140
/** @var mixed $testClass */
4241
$testClass = $test->getTestClass();
@@ -86,14 +85,6 @@ public function getParameters(): array
8685
);
8786
}
8887

89-
/**
90-
* @deprecated Please, use {@see getDisplayName()} method
91-
*/
92-
public function getTitle(): ?string
93-
{
94-
return $this->getDisplayName();
95-
}
96-
9788
public function getDisplayName(): ?string
9889
{
9990
/** @psalm-var mixed $displayName */
@@ -113,4 +104,9 @@ public function getDescriptionHtml(): ?string
113104
{
114105
return null;
115106
}
107+
108+
public function getFullName(): ?string
109+
{
110+
return null;
111+
}
116112
}

src/Internal/DefaultThreadDetector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
final class DefaultThreadDetector implements ThreadDetectorInterface
1212
{
13-
1413
private string|false|null $host = null;
1514

1615
public function getHost(): ?string

0 commit comments

Comments
 (0)