Skip to content

Commit

Permalink
print list of active extensions
Browse files Browse the repository at this point in the history
this closes #47
  • Loading branch information
konecnyjakub committed Dec 27, 2024
1 parent 296b7d9 commit 2fe1279
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ Version 8.0.0-dev
- dropped support for Composer 2.0 and 2.1
- BC break: removed support for old way of providing 1 parameter to a test method via data provided
- BC break: removed support for using conditions with attribute Skip
- added event ExtensionsLoaded
- BC break: added methods getName amd onExtensionsLoaded to interface ITesterExtension
- InfoExtension (when added to automated tests runner) prints active extensions

Version 7.3.1
- allowed installation konecnyjakub/event-dispatcher 2
Expand Down
4 changes: 4 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
A new version of My Tester is out. It is only for Composer 2.2 or later. It removes previously deprecated stuff.

Interface ITesterExtension was changed - it has new method getName and supports new event ExtensionsLoaded.

Automated tests runner can now print list of active extensions along My Tester and PHP version (all of that is handled by InfoExtension).

For complete list of changes since previous version, see CHANGELOG.md.
9 changes: 9 additions & 0 deletions src/CodeCoverage/CodeCoverageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public function __construct(private Collector $collector)
{
}

public function onExtensionsLoaded(Events\ExtensionsLoaded $event): void
{
}

/**
* @throws CodeCoverageException
*/
Expand Down Expand Up @@ -62,4 +66,9 @@ public function onTestCaseStarted(Events\TestCaseStarted $event): void
public function onTestCaseFinished(Events\TestCaseFinished $event): void
{
}

public function getName(): string
{
return "code coverage";
}
}
9 changes: 9 additions & 0 deletions src/ErrorsFilesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public function __construct(private TestsFolderProvider $folderProvider)
{
}

public function onExtensionsLoaded(Events\ExtensionsLoaded $event): void
{
}

public function onTestsStarted(Events\TestsStarted $event): void
{
$files = Finder::findFiles("*.errors")->in($this->folderProvider->folder);
Expand Down Expand Up @@ -46,4 +50,9 @@ public function onTestCaseFinished(Events\TestCaseFinished $event): void
}
}
}

public function getName(): string
{
return "error files";
}
}
16 changes: 16 additions & 0 deletions src/Events/ExtensionsLoaded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);

namespace MyTester\Events;

use MyTester\ITesterExtension;

final readonly class ExtensionsLoaded
{
/**
* @param ITesterExtension[] $extensions
*/
public function __construct(public array $extensions = [])
{
}
}
10 changes: 10 additions & 0 deletions src/ExtensionsEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public function __construct(private array $extensions = [])
public static function getSubscribedEvents(): iterable
{
return [
Events\ExtensionsLoaded::class => [
["onExtensionsLoaded", ],
],
Events\TestsStarted::class => [
["onTestsStarted", ],
],
Expand All @@ -38,6 +41,13 @@ public static function getSubscribedEvents(): iterable
];
}

public function onExtensionsLoaded(Events\ExtensionsLoaded $event): void
{
foreach ($this->extensions as $extension) {
$extension->onExtensionsLoaded($event);
}
}

public function onTestsStarted(Events\TestsStarted $event): void
{
foreach ($this->extensions as $extension) {
Expand Down
4 changes: 4 additions & 0 deletions src/ITesterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
*/
interface ITesterExtension
{
public function onExtensionsLoaded(Events\ExtensionsLoaded $event): void;

public function onTestsStarted(Events\TestsStarted $event): void;

public function onTestsFinished(Events\TestsFinished $event): void;

public function onTestCaseStarted(Events\TestCaseStarted $event): void;

public function onTestCaseFinished(Events\TestCaseFinished $event): void;

public function getName(): string;
}
16 changes: 16 additions & 0 deletions src/InfoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ final class InfoExtension implements ITesterExtension
{
private const string PACKAGE_NAME = "konecnyjakub/mytester";

/** @var string[] */
private array $extensionNames = [];

public function __construct(private readonly ConsoleColors $console)
{
}

public function onExtensionsLoaded(Events\ExtensionsLoaded $event): void
{
$this->extensionNames = array_map(function (ITesterExtension $extension) {
return $extension->getName();
}, $event->extensions);
}

public function onTestsStarted(Events\TestsStarted $event): void
{
echo $this->console->color(self::getTesterVersion() . "\n", "silver");
echo $this->console->color("Loaded extensions: " . implode(", ", $this->extensionNames) . "\n", "silver");
echo "\n";
echo $this->console->color(self::getPhpVersion() . "\n", "silver");
echo "\n";
Expand All @@ -33,6 +44,11 @@ public function onTestCaseFinished(Events\TestCaseFinished $event): void
{
}

public function getName(): string
{
return "info";
}

public static function getTesterVersion(): string
{
$version = InstalledVersions::getPrettyVersion(self::PACKAGE_NAME);
Expand Down
1 change: 1 addition & 0 deletions src/Tester.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(
$this->resultsFormatter->setConsole($this->console);
}
$this->eventDispatcher = $this->createEventDispatcher();
$this->eventDispatcher->dispatch(new Events\ExtensionsLoaded($this->extensions));
}

private function createEventDispatcher(): EventDispatcherInterface
Expand Down

0 comments on commit 2fe1279

Please sign in to comment.