Skip to content

Commit

Permalink
prepare for release (via #69)
Browse files Browse the repository at this point in the history
  • Loading branch information
remorhaz authored Dec 29, 2021
1 parent 31995bd commit 3884842
Show file tree
Hide file tree
Showing 34 changed files with 28 additions and 126 deletions.
59 changes: 21 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,53 +49,36 @@ Then add Allure test listener in **phpunit.xml** file:
<extension class="Qameta\Allure\PHPUnit\AllureExtension">
<!-- Optional arguments block; omit it if you want to use default values -->
<arguments>
<!-- JSON files output directory (default is build/allure-results; you may pass null to use default value) -->
<string>build/allure-results</string>
<!-- Configurator object class (default is Qameta\Allure\PHPUnit\Setup\DefaultConfigurator; you pass null to use default value) -->
<string>Qameta\Allure\PHPUnit\Setup\DefaultConfigurator</string>
<!-- Other arguments (if any) are passed to configurator's constructor -->
<!-- Path to config file (default is config/allure.config.php) -->
<string>config/allure.config.php</string>
</arguments>
</extension>
</extensions>
```
After running PHPUnit tests a new folder will be created (**build/allure-results** in the example above). This folder will contain generated JSON files. See [framework help](https://docs.qameta.io/allure/#_reporting) for details about how to generate report from JSON files. By default generated report will only show a limited set of information but you can use cool Allure features by adding a minimum of test code changes. Read next section for details.

You can also use setup hook to tune or extend Allure lifecycle:
```xml
<extensions>
<extension class="Qameta\Allure\PHPUnit\AllureExtension">
<!-- Optional arguments block; omit it if you want to use default values -->
<arguments>
<!-- JSON files output directory (default is build/allure-results; you may pass null to use default value) -->
<null/>
<!-- Configurator object class (default is Qameta\Allure\PHPUnit\Setup\DefaultConfigurator; you pass null to use default value) -->
<null/>
<!-- For default configurator, just pass name of invokable class in this argument -->
<string>My\Namespace\OnSetupHook</string>
</arguments>
</extension>
</extensions>
```

And the hook class could look like this:

Config is common PHP file that should return an array:
```php
<?php

namespace My\Namespace;

use Qameta\Allure\Allure;

class OnSetupHook
{
public function __invoke(): void
{
Allure::getLifecycleConfigurator()->addHooks(new MyHook())
}
}
return [
// Path to output directory (default is build/allure-results)
'outputDirectory' => 'build/allure-results',
'linkTemplates' => [
// Class or object must implement \Qameta\Allure\Setup\LinkTemplateInterface
'tms' => \My\LinkTemplate::class,
],
'setupHook' => function (): void {
// Some actions performed before starting the lifecycle
},
// Class or object must implement \Qameta\Allure\PHPUnit\Setup\ThreadDetectorInterface
'threadDetector' => \My\ThreadDetector::class,
'lifecycleHooks' => [
// Class or object must implement one of \Qameta\Allure\Hook\LifecycleHookInterface descendants.
\My\LifecycleHook::class,
],
];
```

In the above example we add some custom hook `MyHook` to Allure lifecycle.
After running PHPUnit tests a new folder will be created (**build/allure-results** in the example above). This folder will contain generated JSON files. See [framework help](https://docs.qameta.io/allure/#_reporting) for details about how to generate report from JSON files. By default generated report will only show a limited set of information but you can use cool Allure features by adding a minimum of test code changes. Read next section for details.

## Main features
This adapter comes with a set of PHP annotations and traits allowing to use main Allure features.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
},
"require": {
"php": "^8",
"allure-framework/allure-php-commons": "2.0.0-rc4",
"allure-framework/allure-php-commons": "^2",
"phpunit/phpunit": "^9"
},
"require-dev": {
"brianium/paratest": "^6.3.3",
"brianium/paratest": "^6.4.1",
"psalm/plugin-phpunit": "^0.16.1",
"squizlabs/php_codesniffer": "^3.6.1",
"vimeo/psalm": "^4.13.1"
"squizlabs/php_codesniffer": "^3.6.2",
"vimeo/psalm": "^4.16.1"
},
"conflict": {
"amphp/byte-stream": "<1.5.1"
Expand Down
1 change: 0 additions & 1 deletion src/AllureAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

final class AllureAdapter implements AllureAdapterInterface
{

private static ?AllureAdapterInterface $instance = null;

/**
Expand Down
1 change: 0 additions & 1 deletion src/AllureAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

interface AllureAdapterInterface
{

public function registerStart(ContainerResult $containerResult, TestResult $testResult, TestInfo $info): string;

public function registerRun(TestResult $testResult, TestInfo $info): TestRunInfo;
Expand Down
4 changes: 3 additions & 1 deletion src/AllureExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ private function createTestLifecycle(string|array|ConfigInterface|null $configSo

private function setupAllure(ConfigInterface $config): void
{
Allure::setOutputDirectory($config->getOutputDirectory() ?? self::DEFAULT_OUTPUT_DIRECTORY);
Allure::getLifecycleConfigurator()->setOutputDirectory(
$config->getOutputDirectory() ?? self::DEFAULT_OUTPUT_DIRECTORY,
);

foreach ($config->getLinkTemplates() as $linkType => $linkTemplate) {
Allure::getLifecycleConfigurator()->addLinkTemplate(
Expand Down
1 change: 0 additions & 1 deletion src/ExceptionDetailsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

trait ExceptionDetailsTrait
{

protected function onNotSuccessfulTest(Throwable $t): void
{
AllureAdapter::getInstance()->setLastException($t);
Expand Down
1 change: 0 additions & 1 deletion src/Internal/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

interface ConfigInterface
{

public function getOutputDirectory(): ?string;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Internal/DefaultThreadDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
final class DefaultThreadDetector implements ThreadDetectorInterface
{

private string|false|null $hostName = null;

public function getThread(): ?string
Expand Down
1 change: 0 additions & 1 deletion src/Internal/TestInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
final class TestInfo
{

/**
* @param string $test
* @param class-string|null $class
Expand Down
1 change: 0 additions & 1 deletion src/Internal/TestLifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
final class TestLifecycle implements TestLifecycleInterface
{

private ?TestInfo $currentTest = null;

public function __construct(
Expand Down
1 change: 0 additions & 1 deletion src/Internal/TestLifecycleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

interface TestLifecycleInterface
{

public function create(): TestLifecycleInterface;

public function updateInfo(): TestLifecycleInterface;
Expand Down
1 change: 0 additions & 1 deletion src/Internal/TestRunInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
final class TestRunInfo
{

public function __construct(
private TestInfo $testInfo,
private string $uuid,
Expand Down
1 change: 0 additions & 1 deletion src/Internal/TestStartInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

final class TestStartInfo
{

public function __construct(
private string $containerId,
private string $testId,
Expand Down
1 change: 0 additions & 1 deletion src/Internal/TestUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
*/
class TestUpdater implements TestUpdaterInterface
{

public function __construct(
private LinkTemplateCollectionInterface $linkTemplates,
) {
Expand Down
1 change: 0 additions & 1 deletion src/Internal/TestUpdaterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
interface TestUpdaterInterface
{

public function setInfo(TestResult $testResult, TestInfo $info): void;

public function setRunInfo(TestResult $testResult, TestRunInfo $runInfo): void;
Expand Down
1 change: 0 additions & 1 deletion src/Setup/ThreadDetectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

interface ThreadDetectorInterface
{

public function getThread(): ?string;

public function getHost(): ?string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
]
class TitleClassLevelLegacyTest extends TestCase
{

public function testWithoutTitleAnnotation(): void
{
$this->expectNotToPerformAssertions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
]
class TitleClassLevelMixedTest extends TestCase
{

public function testWithoutTitleAnnotation(): void
{
$this->expectNotToPerformAssertions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
]
class TitleClassLevelNativeTest extends TestCase
{

public function testWithoutTitleAnnotation(): void
{
$this->expectNotToPerformAssertions();
Expand Down
2 changes: 0 additions & 2 deletions test/report/Generate/AnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

class AnnotationTest extends TestCase
{


/**
* @Description ("Legacy description with `markdown`", type = DescriptionType::MARKDOWN)
*/
Expand Down
1 change: 0 additions & 1 deletion test/report/Hook/OnLifecycleErrorHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

final class OnLifecycleErrorHook implements OnLifecycleErrorHookInterface
{

/**
* @throws Throwable
*/
Expand Down
1 change: 0 additions & 1 deletion test/report/Hook/OnSetupHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

final class OnSetupHook
{

public function __invoke()
{
Allure::getLifecycleConfigurator()
Expand Down
1 change: 0 additions & 1 deletion test/unit/AllureAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
class AllureAdapterTest extends TestCase
{

public function setUp(): void
{
AllureAdapter::reset();
Expand Down
52 changes: 0 additions & 52 deletions test/unit/AllureExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,70 +8,18 @@
use Qameta\Allure\Allure;
use Qameta\Allure\Model\Status;
use Qameta\Allure\PHPUnit\AllureExtension;
use Qameta\Allure\PHPUnit\Internal\ConfigInterface;
use Qameta\Allure\PHPUnit\Internal\TestLifecycleInterface;
use Qameta\Allure\Setup\LifecycleBuilderInterface;

use const DIRECTORY_SEPARATOR;

/**
* @covers \Qameta\Allure\PHPUnit\AllureExtension
*/
class AllureExtensionTest extends TestCase
{

public function setUp(): void
{
Allure::reset();
}

/**
* @dataProvider providerOutputDirectory
*/
public function testConstruct_ConfigProvidesOutputDirectory_ConstructsResultsWriterWithWithMatchingDirectory(
?string $outputDirectory,
string $expectedValue,
): void {
$builder = $this->createMock(LifecycleBuilderInterface::class);
Allure::setLifecycleBuilder($builder);
$config = $this->createStub(ConfigInterface::class);
$config
->method('getOutputDirectory')
->willReturn($outputDirectory);
$builder
->expects(self::once())
->method('createResultsWriter')
->with(self::identicalTo($expectedValue));
new AllureExtension($config);
}

/**
* @return iterable<string, array{string|null, string}>
*/
public function providerOutputDirectory(): iterable
{
return [
'Null' => [null, 'build' . DIRECTORY_SEPARATOR . 'allure-results'],
'Non-null' => ['a', 'a'],
];
}

/**
* @dataProvider providerOutputDirectory
*/
public function testConstruct_ConfigDataProvidesOutputDirectory_ConstructsResultsWriterWithWithMatchingDirectory(
?string $outputDirectory,
string $expectedValue,
): void {
$builder = $this->createMock(LifecycleBuilderInterface::class);
Allure::setLifecycleBuilder($builder);
$builder
->expects(self::once())
->method('createResultsWriter')
->with(self::identicalTo($expectedValue));
new AllureExtension(['outputDirectory' => $outputDirectory]);
}

public function testExecuteBeforeTest_Constructed_CreatesTestAfterResettingSwitchedContext(): void
{
$testLifecycle = $this->createMock(TestLifecycleInterface::class);
Expand Down
1 change: 0 additions & 1 deletion test/unit/ExceptionDetailsTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
class ExceptionDetailsTraitTest extends TestCase
{

public function testOnNotSuccessfulTest_GivenException_ThrowsSameException(): void
{
$sharedState = $this->createStub(AllureAdapterInterface::class);
Expand Down
1 change: 0 additions & 1 deletion test/unit/Internal/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
class ConfigTest extends TestCase
{

/**
* @dataProvider providerNoOutputDirectory
*/
Expand Down
1 change: 0 additions & 1 deletion test/unit/Internal/DefaultThreadDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class DefaultThreadDetectorTest extends TestCase
{

public function testGetThread_WithoutParatestToken_ReturnsNull(): void
{
unset($_ENV['TEST_TOKEN']);
Expand Down
1 change: 0 additions & 1 deletion test/unit/Internal/TestInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class TestInfoTest extends TestCase
{

public function testGetTest_ConstructedWithTest_ReturnsSameValue(): void
{
$info = new TestInfo(
Expand Down
1 change: 0 additions & 1 deletion test/unit/Internal/TestLinkTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

final class TestLinkTemplate implements LinkTemplateInterface
{

public function buildUrl(?string $name): ?string
{
return null;
Expand Down
1 change: 0 additions & 1 deletion test/unit/Internal/TestRunInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class TestRunInfoTest extends TestCase
{

public function testGetTestInfo_ConstructedWithTestInfo_ReturnsSameInstance(): void
{
$testInfo = new TestInfo(
Expand Down
1 change: 0 additions & 1 deletion test/unit/Internal/TestStartInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class TestStartInfoTest extends TestCase
{

public function testGetContainerId_ConstructedWithContainerId_ReturnsSameId(): void
{
$info = new TestStartInfo('a', 'b');
Expand Down
Loading

0 comments on commit 3884842

Please sign in to comment.