Skip to content

Commit

Permalink
Merge pull request #44 from ergebnis/fix/constructor
Browse files Browse the repository at this point in the history
Fix: Do not use named constructor
  • Loading branch information
ergebnis-bot authored Jan 26, 2021
2 parents 9d65334 + b272262 commit 7c85a95
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 37 deletions.
5 changes: 4 additions & 1 deletion src/TimeKeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public function stop(Event\Code\Test $test, Event\Telemetry\HRTime $stoppedTime)
$key = self::key($test);

if (!\array_key_exists($key, $this->startedTimes)) {
return Event\Telemetry\Duration::fromSeconds(0);
return Event\Telemetry\Duration::fromSecondsAndNanoseconds(
0,
0
);
}

$startedTime = $this->startedTimes[$key];
Expand Down
33 changes: 27 additions & 6 deletions test/Unit/Comparator/DurationComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ final class DurationComparatorTest extends Framework\TestCase

public function testReturnsMinusOneWhenOneIsLessThanTwo(): void
{
$one = Event\Telemetry\Duration::fromSeconds(5);
$two = Event\Telemetry\Duration::fromSeconds(6);
$one = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
5,
0
);

$two = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
5,
1
);

$comparator = new DurationComparator();

Expand All @@ -39,8 +46,15 @@ public function testReturnsMinusOneWhenOneIsLessThanTwo(): void

public function testReturnsZeroWhenOneEqualsTwo(): void
{
$one = Event\Telemetry\Duration::fromSeconds(5);
$two = Event\Telemetry\Duration::fromSeconds(5);
$one = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
5,
0
);

$two = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
5,
0
);

$comparator = new DurationComparator();

Expand All @@ -49,8 +63,15 @@ public function testReturnsZeroWhenOneEqualsTwo(): void

public function testReturnsPlusOneWhenOneIsGreaterThanTwo(): void
{
$one = Event\Telemetry\Duration::fromSeconds(5);
$two = Event\Telemetry\Duration::fromSeconds(4);
$one = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
5,
1
);

$two = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
5,
0
);

$comparator = new DurationComparator();

Expand Down
10 changes: 8 additions & 2 deletions test/Unit/SlowTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ public function testFromTestDurationAndMaximumDurationReturnsSlowTest(): void
$faker->word
);

$duration = Event\Telemetry\Duration::fromSeconds($faker->numberBetween());
$maximumDuration = Event\Telemetry\Duration::fromSeconds($faker->numberBetween());
$duration = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
);
$maximumDuration = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
);

$slowTest = SlowTest::fromTestDurationAndMaximumDuration(
$test,
Expand Down
54 changes: 36 additions & 18 deletions test/Unit/Subscriber/TestPassedSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public function testNotifyDoesNotCollectSlowTestWhenDurationIsLessThanMaximumDur
{
$faker = self::faker();

$maximumDuration = Event\Telemetry\Duration::fromSeconds($faker->numberBetween(
5,
10
));
$maximumDuration = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(5, 10),
0
);

$preparedTime = Event\Telemetry\HRTime::fromSecondsAndNanoseconds(
$faker->numberBetween(),
Expand Down Expand Up @@ -72,9 +72,15 @@ public function testNotifyDoesNotCollectSlowTestWhenDurationIsLessThanMaximumDur
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween())
),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
),
$passedTest
Expand Down Expand Up @@ -104,10 +110,10 @@ public function testNotifyDoesNotCollectSlowTestWhenDurationIsEqualToMaximumDura
{
$faker = self::faker();

$maximumDuration = Event\Telemetry\Duration::fromSeconds($faker->numberBetween(
5,
10
));
$maximumDuration = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(5, 10),
0
);

$preparedTime = Event\Telemetry\HRTime::fromSecondsAndNanoseconds(
$faker->numberBetween(),
Expand All @@ -134,9 +140,15 @@ public function testNotifyDoesNotCollectSlowTestWhenDurationIsEqualToMaximumDura
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween())
),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
),
$passedTest
Expand Down Expand Up @@ -166,10 +178,10 @@ public function testNotifyCollectsSlowTestWhenDurationIsGreaterThanMaximumDurati
{
$faker = self::faker();

$maximumDuration = Event\Telemetry\Duration::fromSeconds($faker->numberBetween(
5,
10
));
$maximumDuration = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(5, 10),
0
);

$preparedTime = Event\Telemetry\HRTime::fromSecondsAndNanoseconds(
$faker->numberBetween(),
Expand All @@ -196,9 +208,15 @@ public function testNotifyCollectsSlowTestWhenDurationIsGreaterThanMaximumDurati
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween())
),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
),
$passedTest
Expand Down
10 changes: 8 additions & 2 deletions test/Unit/Subscriber/TestPreparedSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ public function testNotifyRecordsTestStartWithTimeKeeper(): void
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween())
),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
),
$preparedTest
Expand Down
30 changes: 24 additions & 6 deletions test/Unit/Subscriber/TestSuiteFinishedSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ public function testNotifyDoesNothingWhenCollectorHasNotCollectedAnything(): voi
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween())
),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
),
$faker->word,
Expand Down Expand Up @@ -142,9 +148,15 @@ public function testNotifyDoesNothingWhenReporterHasNotReportedAnything(): void
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween())
),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
),
$faker->word,
Expand Down Expand Up @@ -244,9 +256,15 @@ public function testNotifyEchosReportWhenReporterHasReportedSomething(): void
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween())
),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
Event\Telemetry\Duration::fromSeconds($faker->numberBetween()),
Event\Telemetry\Duration::fromSecondsAndNanoseconds(
$faker->numberBetween(),
$faker->numberBetween(0, 999_999_999)
),
Event\Telemetry\MemoryUsage::fromBytes($faker->numberBetween()),
),
$faker->word,
Expand Down
14 changes: 12 additions & 2 deletions test/Unit/TimeKeeperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public function testStopReturnsZeroDurationWhenTestHasNotBeenStoppedButNotStarte
$stoppedTime
);

self::assertEquals(Event\Telemetry\Duration::fromSeconds(0), $duration);
$expected = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
0,
0
);

self::assertEquals($expected, $duration);
}

public function testStopReturnsDurationWhenTestHasBeenStartedAndStopped(): void
Expand Down Expand Up @@ -136,7 +141,12 @@ public function testStopReturnsZeroDurationWhenTestHasBeenStartedAndStoppedAndSt
$secondStoppedTime
);

self::assertEquals(Event\Telemetry\Duration::fromSeconds(0), $duration);
$expected = Event\Telemetry\Duration::fromSecondsAndNanoseconds(
0,
0
);

self::assertEquals($expected, $duration);
}

public function testCanStartAndStopMultipleTests(): void
Expand Down

0 comments on commit 7c85a95

Please sign in to comment.