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.
Enhancement: Implement StartedPhase and Phase
- Loading branch information
1 parent
3ddec39
commit 86a915c
Showing
11 changed files
with
439 additions
and
42 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 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\Exception; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class InvalidPhaseIdentifier extends \InvalidArgumentException | ||
{ | ||
public static function blankOrEmpty(): self | ||
{ | ||
return new self('Value can not be blank or empty.'); | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 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; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Phase | ||
{ | ||
private PhaseIdentifier $phaseIdentifier; | ||
private Time $startTime; | ||
private Time $stopTime; | ||
private Duration $duration; | ||
|
||
private function __construct( | ||
PhaseIdentifier $phaseIdentifier, | ||
Time $startTime, | ||
Time $stopTime, | ||
Duration $duration | ||
) { | ||
$this->phaseIdentifier = $phaseIdentifier; | ||
$this->startTime = $startTime; | ||
$this->stopTime = $stopTime; | ||
$this->duration = $duration; | ||
} | ||
|
||
public static function create( | ||
PhaseIdentifier $phaseIdentifier, | ||
Time $startTime, | ||
Time $stopTime | ||
): self { | ||
return new self( | ||
$phaseIdentifier, | ||
$startTime, | ||
$stopTime, | ||
$stopTime->duration($startTime), | ||
); | ||
} | ||
|
||
public function phaseIdentifier(): PhaseIdentifier | ||
{ | ||
return $this->phaseIdentifier; | ||
} | ||
|
||
public function startTime(): Time | ||
{ | ||
return $this->startTime; | ||
} | ||
|
||
public function stopTime(): Time | ||
{ | ||
return $this->stopTime; | ||
} | ||
|
||
public function duration(): Duration | ||
{ | ||
return $this->duration; | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 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; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class PhaseIdentifier | ||
{ | ||
private string $value; | ||
|
||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @throws Exception\InvalidPhaseIdentifier | ||
*/ | ||
public static function fromString(string $value): self | ||
{ | ||
if ('' === \trim($value)) { | ||
throw Exception\InvalidPhaseIdentifier::blankOrEmpty(); | ||
} | ||
|
||
return new self($value); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 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; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class StartedPhase | ||
{ | ||
private PhaseIdentifier $phaseIdentifier; | ||
private Time $startTime; | ||
|
||
private function __construct( | ||
PhaseIdentifier $phaseIdentifier, | ||
Time $startTime | ||
) { | ||
$this->phaseIdentifier = $phaseIdentifier; | ||
$this->startTime = $startTime; | ||
} | ||
|
||
public static function create( | ||
PhaseIdentifier $phaseIdentifier, | ||
Time $startTime | ||
): self { | ||
return new self( | ||
$phaseIdentifier, | ||
$startTime, | ||
); | ||
} | ||
|
||
public function phaseIdentifier(): PhaseIdentifier | ||
{ | ||
return $this->phaseIdentifier; | ||
} | ||
|
||
public function startTime(): Time | ||
{ | ||
return $this->startTime; | ||
} | ||
} |
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
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 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\Exception; | ||
|
||
use Ergebnis\PHPUnit\SlowTestDetector\Exception; | ||
use Ergebnis\PHPUnit\SlowTestDetector\Test; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @covers \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidTestIdentifier | ||
*/ | ||
final class InvalidPhaseIdentifierTest extends Framework\TestCase | ||
{ | ||
use Test\Util\Helper; | ||
|
||
public function testBlankOrEmptyReturnsException(): void | ||
{ | ||
$exception = Exception\InvalidTestIdentifier::blankOrEmpty(); | ||
|
||
self::assertSame('Value can not be blank or empty.', $exception->getMessage()); | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2021-2023 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; | ||
|
||
use Ergebnis\DataProvider; | ||
use Ergebnis\PHPUnit\SlowTestDetector\Exception; | ||
use Ergebnis\PHPUnit\SlowTestDetector\PhaseIdentifier; | ||
use Ergebnis\PHPUnit\SlowTestDetector\Test; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @covers \Ergebnis\PHPUnit\SlowTestDetector\PhaseIdentifier | ||
* | ||
* @uses \Ergebnis\PHPUnit\SlowTestDetector\Exception\InvalidPhaseIdentifier | ||
*/ | ||
final class PhaseIdentifierTest extends Framework\TestCase | ||
{ | ||
use Test\Util\Helper; | ||
|
||
/** | ||
* @dataProvider \Ergebnis\DataProvider\StringProvider::blank | ||
* @dataProvider \Ergebnis\DataProvider\StringProvider::empty | ||
*/ | ||
public function testFromStringRejectsInvalidValue(string $value): void | ||
{ | ||
$this->expectException(Exception\InvalidPhaseIdentifier::class); | ||
|
||
PhaseIdentifier::fromString($value); | ||
} | ||
|
||
public function testFromStringReturnsPhaseIdentifier(): void | ||
{ | ||
$value = self::faker()->word(); | ||
|
||
$testIdentifier = PhaseIdentifier::fromString($value); | ||
|
||
self::assertSame($value, $testIdentifier->tostring()); | ||
} | ||
} |
Oops, something went wrong.