generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ergebnis/feature/duration-comparator
Enhancement: Implement DurationComparator
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector\Comparator; | ||
|
||
use PHPUnit\Event; | ||
|
||
final class DurationComparator | ||
{ | ||
public function compare(Event\Telemetry\Duration $one, Event\Telemetry\Duration $two): int | ||
{ | ||
if ($one->isLessThan($two)) { | ||
return -1; | ||
} | ||
|
||
if ($one->isGreaterThan($two)) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/phpunit-slow-test-detector | ||
*/ | ||
|
||
namespace Ergebnis\PHPUnit\SlowTestDetector\Test\Unit\Comparator; | ||
|
||
use Ergebnis\PHPUnit\SlowTestDetector\Comparator\DurationComparator; | ||
use Ergebnis\Test\Util; | ||
use PHPUnit\Event; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Comparator\DurationComparator | ||
*/ | ||
final class DurationComparatorTest extends Framework\TestCase | ||
{ | ||
use Util\Helper; | ||
|
||
public function testReturnsMinusOneWhenOneIsLessThanTwo(): void | ||
{ | ||
$one = Event\Telemetry\Duration::fromSeconds(5); | ||
$two = Event\Telemetry\Duration::fromSeconds(6); | ||
|
||
$comparator = new DurationComparator(); | ||
|
||
self::assertSame(-1, $comparator->compare($one, $two)); | ||
} | ||
|
||
public function testReturnsZeroWhenOneEqualsTwo(): void | ||
{ | ||
$one = Event\Telemetry\Duration::fromSeconds(5); | ||
$two = Event\Telemetry\Duration::fromSeconds(5); | ||
|
||
$comparator = new DurationComparator(); | ||
|
||
self::assertSame(0, $comparator->compare($one, $two)); | ||
} | ||
|
||
public function testReturnsPlusOneWhenOneIsGreaterThanTwo(): void | ||
{ | ||
$one = Event\Telemetry\Duration::fromSeconds(5); | ||
$two = Event\Telemetry\Duration::fromSeconds(4); | ||
|
||
$comparator = new DurationComparator(); | ||
|
||
self::assertSame(1, $comparator->compare($one, $two)); | ||
} | ||
} |