-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CodeCoverage::validate(TargetCollection)
- Loading branch information
1 parent
873416b
commit 02adea8
Showing
6 changed files
with
199 additions
and
0 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
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,46 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of phpunit/php-code-coverage. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace SebastianBergmann\CodeCoverage\Test\Target; | ||
|
||
/** | ||
* @immutable | ||
* | ||
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage | ||
*/ | ||
final readonly class ValidationFailure extends ValidationResult | ||
{ | ||
/** | ||
* @var non-empty-string | ||
*/ | ||
private string $message; | ||
|
||
/** | ||
* @param non-empty-string $message | ||
* | ||
* @noinspection PhpMissingParentConstructorInspection | ||
*/ | ||
protected function __construct(string $message) | ||
{ | ||
$this->message = $message; | ||
} | ||
|
||
public function isFailure(): true | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @return non-empty-string | ||
*/ | ||
public function message(): string | ||
{ | ||
return $this->message; | ||
} | ||
} |
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); | ||
/* | ||
* This file is part of phpunit/php-code-coverage. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace SebastianBergmann\CodeCoverage\Test\Target; | ||
|
||
/** | ||
* @immutable | ||
* | ||
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage | ||
*/ | ||
abstract readonly class ValidationResult | ||
{ | ||
public static function success(): ValidationSuccess | ||
{ | ||
return new ValidationSuccess; | ||
} | ||
|
||
/** | ||
* @param non-empty-string $message | ||
*/ | ||
public static function failure(string $message): ValidationFailure | ||
{ | ||
return new ValidationFailure($message); | ||
} | ||
|
||
protected function __construct() | ||
{ | ||
} | ||
|
||
/** | ||
* @phpstan-assert-if-true ValidationSuccess $this | ||
*/ | ||
public function isSuccess(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* @phpstan-assert-if-true ValidationFailure $this | ||
*/ | ||
public function isFailure(): bool | ||
{ | ||
return false; | ||
} | ||
} |
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,23 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of phpunit/php-code-coverage. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace SebastianBergmann\CodeCoverage\Test\Target; | ||
|
||
/** | ||
* @immutable | ||
* | ||
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage | ||
*/ | ||
final readonly class ValidationSuccess extends ValidationResult | ||
{ | ||
public function isSuccess(): true | ||
{ | ||
return true; | ||
} | ||
} |
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,36 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of phpunit/php-code-coverage. | ||
* | ||
* (c) Sebastian Bergmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace SebastianBergmann\CodeCoverage\Test\Target; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\Attributes\Small; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[CoversClass(ValidationResult::class)] | ||
#[CoversClass(ValidationSuccess::class)] | ||
#[CoversClass(ValidationFailure::class)] | ||
#[Small] | ||
final class ValidationResultTest extends TestCase | ||
{ | ||
public function testCanBeSuccess(): void | ||
{ | ||
$this->assertTrue(ValidationResult::success()->isSuccess()); | ||
$this->assertFalse(ValidationResult::success()->isFailure()); | ||
} | ||
|
||
public function testCanBeFailure(): void | ||
{ | ||
$message = 'message'; | ||
|
||
$this->assertTrue(ValidationResult::failure($message)->isFailure()); | ||
$this->assertFalse(ValidationResult::failure($message)->isSuccess()); | ||
$this->assertSame($message, ValidationResult::failure($message)->message()); | ||
} | ||
} |