Skip to content

Commit

Permalink
Enhancement: Compose data into TestSuite\Started event
Browse files Browse the repository at this point in the history
Fixes #25.

Co-authored-by: Andreas Möller <am@localheinz.com>
Co-authored-by: Arne Blankerts <Arne@Blankerts.de>
  • Loading branch information
localheinz and theseer committed Jan 28, 2021
1 parent 09186dd commit 0c4548a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/Event/DispatchingEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,12 @@ public function testSuiteSorted(int $executionOrder, int $executionOrderDefects,
));
}

public function testSuiteStarted(): void
public function testSuiteStarted(string $name): void
{
$this->dispatcher->dispatch(new TestSuite\Started($this->telemetryInfo()));
$this->dispatcher->dispatch(new TestSuite\Started(
$this->telemetryInfo(),
$name
));
}

private function telemetryInfo(): Telemetry\Info
Expand Down
2 changes: 1 addition & 1 deletion src/Event/Emitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ public function testSuiteRunFinished(): void;

public function testSuiteSorted(int $executionOrder, int $executionOrderDefects, bool $resolveDependencies): void;

public function testSuiteStarted(): void;
public function testSuiteStarted(string $name): void;
}
10 changes: 9 additions & 1 deletion src/Event/TestSuite/Started.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@ final class Started implements Event
{
private Telemetry\Info $telemetryInfo;

public function __construct(Telemetry\Info $telemetryInfo)
private string $name;

public function __construct(Telemetry\Info $telemetryInfo, string $name)
{
$this->telemetryInfo = $telemetryInfo;
$this->name = $name;
}

public function telemetryInfo(): Telemetry\Info
{
return $this->telemetryInfo;
}

public function name(): string
{
return $this->name;
}
}
2 changes: 1 addition & 1 deletion src/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ public function run(TestSuite $suite, array $arguments = [], array $warnings = [
$this->write(PHP_EOL);
}

Event\Registry::emitter()->testSuiteStarted();
Event\Registry::emitter()->testSuiteStarted($suite->getName());

$suite->run($result);

Expand Down
2 changes: 1 addition & 1 deletion tests/_files/NullEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function testSuiteSorted(int $executionOrder, int $executionOrderDefects,
{
}

public function testSuiteStarted(): void
public function testSuiteStarted(string $name): void
{
}
}
11 changes: 9 additions & 2 deletions tests/unit/Event/DispatchingEmitterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,8 @@ public function notify(TestSuite\Sorted $event): void

public function testTestSuiteStartedDispatchesTestSuiteStartedEvent(): void
{
$name = 'foo';

$subscriber = new class extends RecordingSubscriber implements TestSuite\StartedSubscriber {
public function notify(TestSuite\Started $event): void
{
Expand All @@ -1364,10 +1366,15 @@ public function notify(TestSuite\Started $event): void
$telemetrySystem
);

$emitter->testSuiteStarted();
$emitter->testSuiteStarted($name);

$this->assertSame(1, $subscriber->recordedEventCount());
$this->assertInstanceOf(TestSuite\Started::class, $subscriber->lastRecordedEvent());

$event = $subscriber->lastRecordedEvent();

$this->assertInstanceOf(TestSuite\Started::class, $event);

$this->assertSame($name, $event->name());
}

private static function createDispatcherWithRegisteredSubscriber(string $subscriberInterface, string $eventClass, Subscriber $subscriber): Dispatcher
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/Event/TestSuite/StartedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ final class StartedTest extends AbstractEventTestCase
public function testConstructorSetsValues(): void
{
$telemetryInfo = self::createTelemetryInfo();
$name = 'foo';

$event = new Started($telemetryInfo);
$event = new Started(
$telemetryInfo,
$name
);

$this->assertSame($telemetryInfo, $event->telemetryInfo());
$this->assertSame($name, $event->name());
}
}

0 comments on commit 0c4548a

Please sign in to comment.