diff --git a/src/Exception/InvalidTestDescription.php b/src/Exception/InvalidTestDescription.php new file mode 100644 index 00000000..0e3fca8b --- /dev/null +++ b/src/Exception/InvalidTestDescription.php @@ -0,0 +1,25 @@ +getName() )); + $testDescription = TestDescription::fromString(\sprintf( + '%s::%s', + \get_class($test), + $test->getName() + )); + $slowTest = SlowTest::create( $testIdentifier, + $testDescription, $duration, $maximumDuration ); @@ -314,9 +321,11 @@ public function executeAfterTest( } $testIdentifier = TestIdentifier::fromString($test); + $testDescription = TestDescription::fromString($test); $slowTest = SlowTest::create( $testIdentifier, + $testDescription, $duration, $maximumDuration ); diff --git a/src/Reporter/DefaultReporter.php b/src/Reporter/DefaultReporter.php index 342bad27..180e01f1 100644 --- a/src/Reporter/DefaultReporter.php +++ b/src/Reporter/DefaultReporter.php @@ -159,10 +159,10 @@ static function (Duration $maximumDuration, SlowTest $slowTest): Duration { ) ); - $testName = $slowTest->testIdentifier()->toString(); + $testDescription = $slowTest->testDescription()->toString(); return <<testIdentifier = $testIdentifier; + $this->testDescription = $testDescription; $this->duration = $duration; $this->maximumDuration = $maximumDuration; } public static function create( TestIdentifier $testIdentifier, + TestDescription $testDescription, Duration $duration, Duration $maximumDuration ): self { return new self( $testIdentifier, + $testDescription, $duration, $maximumDuration ); @@ -60,6 +69,11 @@ public function testIdentifier(): TestIdentifier return $this->testIdentifier; } + public function testDescription(): TestDescription + { + return $this->testDescription; + } + public function duration(): Duration { return $this->duration; diff --git a/src/Subscriber/Test/FinishedSubscriber.php b/src/Subscriber/Test/FinishedSubscriber.php index c53a3afc..8e93c223 100644 --- a/src/Subscriber/Test/FinishedSubscriber.php +++ b/src/Subscriber/Test/FinishedSubscriber.php @@ -18,6 +18,7 @@ use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\PhaseIdentifier; use Ergebnis\PHPUnit\SlowTestDetector\SlowTest; +use Ergebnis\PHPUnit\SlowTestDetector\TestDescription; use Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier; use Ergebnis\PHPUnit\SlowTestDetector\Time; use Ergebnis\PHPUnit\SlowTestDetector\TimeKeeper; @@ -82,6 +83,7 @@ public function notify(Event\Test\Finished $event): void $slowTest = SlowTest::create( TestIdentifier::fromString($event->test()->id()), + TestDescription::fromString($event->test()->id()), $duration, $maximumDuration ); diff --git a/src/TestDescription.php b/src/TestDescription.php new file mode 100644 index 00000000..098acc39 --- /dev/null +++ b/src/TestDescription.php @@ -0,0 +1,47 @@ +value = $value; + } + + /** + * @throws Exception\InvalidTestIdentifier + */ + public static function fromString(string $value): self + { + if ('' === \trim($value)) { + throw Exception\InvalidTestIdentifier::blankOrEmpty(); + } + + return new self($value); + } + + public function toString(): string + { + return $this->value; + } +} diff --git a/test/Unit/Collector/DefaultCollectorTest.php b/test/Unit/Collector/DefaultCollectorTest.php index a086b662..2fa11a01 100644 --- a/test/Unit/Collector/DefaultCollectorTest.php +++ b/test/Unit/Collector/DefaultCollectorTest.php @@ -17,6 +17,7 @@ use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\SlowTest; use Ergebnis\PHPUnit\SlowTestDetector\Test; +use Ergebnis\PHPUnit\SlowTestDetector\TestDescription; use Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier; use PHPUnit\Framework; @@ -25,6 +26,7 @@ * * @uses \Ergebnis\PHPUnit\SlowTestDetector\Duration * @uses \Ergebnis\PHPUnit\SlowTestDetector\SlowTest + * @uses \Ergebnis\PHPUnit\SlowTestDetector\TestDescription * @uses \Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier */ final class DefaultCollectorTest extends Framework\TestCase @@ -37,12 +39,14 @@ public function testCollectCollectsSlowTests() $one = SlowTest::create( TestIdentifier::fromString($faker->word()), + TestDescription::fromString($faker->word()), Duration::fromMilliseconds($faker->numberBetween(0)), Duration::fromMilliseconds($faker->numberBetween(0)) ); $two = SlowTest::create( TestIdentifier::fromString($faker->word()), + TestDescription::fromString($faker->word()), Duration::fromMilliseconds($faker->numberBetween(0)), Duration::fromMilliseconds($faker->numberBetween(0)) ); @@ -66,12 +70,14 @@ public function testCollectCollectsSlowerTestWithSameTestIdentifier() $one = SlowTest::create( TestIdentifier::fromString($faker->word()), + TestDescription::fromString($faker->word()), Duration::fromMilliseconds($faker->numberBetween(0)), Duration::fromMilliseconds($faker->numberBetween(0, 999999999 - 1)) ); $two = SlowTest::create( $one->testIdentifier(), + TestDescription::fromString($faker->word()), Duration::fromSecondsAndNanoseconds( $one->duration()->seconds(), $one->duration()->nanoseconds() + 1 @@ -97,12 +103,14 @@ public function testCollectDoesNotCollectFasterTestWithSameTestIdentifier() $one = SlowTest::create( TestIdentifier::fromString($faker->word()), + TestDescription::fromString($faker->word()), Duration::fromMilliseconds($faker->numberBetween(0)), Duration::fromMilliseconds($faker->numberBetween(1, 999999999)) ); $two = SlowTest::create( $one->testIdentifier(), + TestDescription::fromString($faker->word()), Duration::fromSecondsAndNanoseconds( $one->duration()->seconds(), $one->duration()->nanoseconds() - 1 diff --git a/test/Unit/Exception/InvalidTestDescriptionTest.php b/test/Unit/Exception/InvalidTestDescriptionTest.php new file mode 100644 index 00000000..fd7336b9 --- /dev/null +++ b/test/Unit/Exception/InvalidTestDescriptionTest.php @@ -0,0 +1,30 @@ +getMessage()); + } +} diff --git a/test/Unit/Reporter/DefaultReporterTest.php b/test/Unit/Reporter/DefaultReporterTest.php index 93556144..83805a56 100644 --- a/test/Unit/Reporter/DefaultReporterTest.php +++ b/test/Unit/Reporter/DefaultReporterTest.php @@ -19,6 +19,7 @@ use Ergebnis\PHPUnit\SlowTestDetector\Reporter; use Ergebnis\PHPUnit\SlowTestDetector\SlowTest; use Ergebnis\PHPUnit\SlowTestDetector\Test; +use Ergebnis\PHPUnit\SlowTestDetector\TestDescription; use Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier; use PHPUnit\Framework; @@ -30,6 +31,7 @@ * @uses \Ergebnis\PHPUnit\SlowTestDetector\Duration * @uses \Ergebnis\PHPUnit\SlowTestDetector\Formatter\DefaultDurationFormatter * @uses \Ergebnis\PHPUnit\SlowTestDetector\SlowTest + * @uses \Ergebnis\PHPUnit\SlowTestDetector\TestDescription * @uses \Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier */ final class DefaultReporterTest extends Framework\TestCase @@ -91,6 +93,7 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe [ SlowTest::create( TestIdentifier::fromString('FooTest::test'), + TestDescription::fromString('FooTest::test'), Duration::fromMilliseconds(300), Duration::fromMilliseconds(100) ), @@ -109,11 +112,13 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe [ SlowTest::create( TestIdentifier::fromString('FooTest::test'), + TestDescription::fromString('FooTest::test'), Duration::fromMilliseconds(300), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('BarTest::test'), + TestDescription::fromString('BarTest::test'), Duration::fromMilliseconds(275), Duration::fromMilliseconds(100) ), @@ -133,16 +138,19 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe [ SlowTest::create( TestIdentifier::fromString('FooTest::test'), + TestDescription::fromString('FooTest::test'), Duration::fromMilliseconds(300), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('BarTest::test'), + TestDescription::fromString('BarTest::test'), Duration::fromMilliseconds(275), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('BazTest::test'), + TestDescription::fromString('BazTest::test'), Duration::fromMilliseconds(250), Duration::fromMilliseconds(100) ), @@ -162,16 +170,19 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe [ SlowTest::create( TestIdentifier::fromString('BazTest::test'), + TestDescription::fromString('BazTest::test'), Duration::fromMilliseconds(250), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('BarTest::test'), + TestDescription::fromString('BarTest::test'), Duration::fromMilliseconds(275), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('FooTest::test'), + TestDescription::fromString('FooTest::test'), Duration::fromMilliseconds(300), Duration::fromMilliseconds(100) ), @@ -198,51 +209,61 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe [ SlowTest::create( TestIdentifier::fromString('FooTest::test'), + TestDescription::fromString('FooTest::test'), Duration::fromMilliseconds(1250000), Duration::fromMilliseconds(1000000) ), SlowTest::create( TestIdentifier::fromString('BarTest::test'), + TestDescription::fromString('BarTest::test'), Duration::fromMilliseconds(575000), Duration::fromMilliseconds(500000) ), SlowTest::create( TestIdentifier::fromString('BazTest::test'), + TestDescription::fromString('BazTest::test'), Duration::fromMilliseconds(250), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('QuxTest::test'), + TestDescription::fromString('QuxTest::test'), Duration::fromMilliseconds(200), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('QuuxTest::test'), + TestDescription::fromString('QuuxTest::test'), Duration::fromMilliseconds(160), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('CorgeTest::test'), + TestDescription::fromString('CorgeTest::test'), Duration::fromMilliseconds(150), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('GraultTest::test'), + TestDescription::fromString('GraultTest::test'), Duration::fromMilliseconds(140), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('GarplyTest::test'), + TestDescription::fromString('GarplyTest::test'), Duration::fromMilliseconds(130), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('WaldoTest::test'), + TestDescription::fromString('WaldoTest::test'), Duration::fromMilliseconds(120), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('FredTest::test'), + TestDescription::fromString('FredTest::test'), Duration::fromMilliseconds(110), Duration::fromMilliseconds(100) ), @@ -262,11 +283,13 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe [ SlowTest::create( TestIdentifier::fromString('FooTest::test'), + TestDescription::fromString('FooTest::test'), Duration::fromMilliseconds(300), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('BarTest::test'), + TestDescription::fromString('BarTest::test'), Duration::fromMilliseconds(275), Duration::fromMilliseconds(100) ), @@ -286,16 +309,19 @@ public static function provideExpectedReportMaximumDurationMaximumCountAndSlowTe [ SlowTest::create( TestIdentifier::fromString('FooTest::test'), + TestDescription::fromString('FooTest::test'), Duration::fromMilliseconds(300), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('BarTest::test'), + TestDescription::fromString('BarTest::test'), Duration::fromMilliseconds(275), Duration::fromMilliseconds(100) ), SlowTest::create( TestIdentifier::fromString('BazTest::test'), + TestDescription::fromString('BazTest::test'), Duration::fromMilliseconds(250), Duration::fromMilliseconds(100) ), diff --git a/test/Unit/SlowTestTest.php b/test/Unit/SlowTestTest.php index e0c83782..999d5dad 100644 --- a/test/Unit/SlowTestTest.php +++ b/test/Unit/SlowTestTest.php @@ -16,6 +16,7 @@ use Ergebnis\PHPUnit\SlowTestDetector\Duration; use Ergebnis\PHPUnit\SlowTestDetector\SlowTest; use Ergebnis\PHPUnit\SlowTestDetector\Test; +use Ergebnis\PHPUnit\SlowTestDetector\TestDescription; use Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier; use PHPUnit\Framework; @@ -23,6 +24,7 @@ * @covers \Ergebnis\PHPUnit\SlowTestDetector\SlowTest * * @uses \Ergebnis\PHPUnit\SlowTestDetector\Duration + * @uses \Ergebnis\PHPUnit\SlowTestDetector\TestDescription * @uses \Ergebnis\PHPUnit\SlowTestDetector\TestIdentifier */ final class SlowTestTest extends Framework\TestCase @@ -34,16 +36,19 @@ public function testCreateReturnsSlowTest() $faker = self::faker(); $testIdentifier = TestIdentifier::fromString($faker->word()); + $testDescription = TestDescription::fromString($faker->word()); $duration = Duration::fromMilliseconds($faker->numberBetween(0)); $maximumDuration = Duration::fromMilliseconds($faker->numberBetween(0)); $slowTest = SlowTest::create( $testIdentifier, + $testDescription, $duration, $maximumDuration ); self::assertSame($testIdentifier, $slowTest->testIdentifier()); + self::assertSame($testDescription, $slowTest->testDescription()); self::assertSame($duration, $slowTest->duration()); self::assertSame($maximumDuration, $slowTest->maximumDuration()); } diff --git a/test/Unit/TestDescriptionTest.php b/test/Unit/TestDescriptionTest.php new file mode 100644 index 00000000..2f5c8eba --- /dev/null +++ b/test/Unit/TestDescriptionTest.php @@ -0,0 +1,48 @@ +expectException(Exception\InvalidTestDescription::class); + + TestDescription::fromString($value); + } + + public function testFromStringReturnsTestDescription() + { + $value = self::faker()->word(); + + $testDescription = TestDescription::fromString($value); + + self::assertSame($value, $testDescription->toString()); + } +}