From ec01f219e893c53e47bf485367aef408df9c4e0e Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 31 Oct 2024 07:14:39 +0100 Subject: [PATCH] Add tests --- tests/tests/TestSizeTest.php | 81 ++++++++++++++++++++++++++++++++++ tests/tests/TestStatusTest.php | 56 +++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 tests/tests/TestSizeTest.php create mode 100644 tests/tests/TestStatusTest.php diff --git a/tests/tests/TestSizeTest.php b/tests/tests/TestSizeTest.php new file mode 100644 index 000000000..acfc75d0b --- /dev/null +++ b/tests/tests/TestSizeTest.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\CodeCoverage\Test\TestSize; + +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\TestCase; + +#[CoversClass(TestSize::class)] +#[CoversClass(Unknown::class)] +#[CoversClass(Known::class)] +#[CoversClass(Small::class)] +#[CoversClass(Medium::class)] +#[CoversClass(Large::class)] +#[\PHPUnit\Framework\Attributes\Small] +final class TestSizeTest extends TestCase +{ + public function testCanBeUnknown(): void + { + $size = TestSize::unknown(); + + $this->assertTrue($size->isUnknown()); + $this->assertFalse($size->isKnown()); + $this->assertFalse($size->isSmall()); + $this->assertFalse($size->isMedium()); + $this->assertFalse($size->isLarge()); + $this->assertSame('unknown', $size->asString()); + } + + public function testCanBeSmall(): void + { + $size = TestSize::small(); + + $this->assertFalse($size->isUnknown()); + $this->assertTrue($size->isKnown()); + $this->assertTrue($size->isSmall()); + $this->assertFalse($size->isMedium()); + $this->assertFalse($size->isLarge()); + $this->assertSame('small', $size->asString()); + } + + public function testCanBeMedium(): void + { + $size = TestSize::medium(); + + $this->assertFalse($size->isUnknown()); + $this->assertTrue($size->isKnown()); + $this->assertFalse($size->isSmall()); + $this->assertTrue($size->isMedium()); + $this->assertFalse($size->isLarge()); + $this->assertSame('medium', $size->asString()); + } + + public function testCanBeLarge(): void + { + $size = TestSize::large(); + + $this->assertFalse($size->isUnknown()); + $this->assertTrue($size->isKnown()); + $this->assertFalse($size->isSmall()); + $this->assertFalse($size->isMedium()); + $this->assertTrue($size->isLarge()); + $this->assertSame('large', $size->asString()); + } + + public function testCanBeCompared(): void + { + $this->assertFalse(TestSize::small()->isGreaterThan(TestSize::small())); + $this->assertFalse(TestSize::medium()->isGreaterThan(TestSize::large())); + $this->assertTrue(TestSize::medium()->isGreaterThan(TestSize::small())); + $this->assertFalse(TestSize::large()->isGreaterThan(TestSize::large())); + $this->assertTrue(TestSize::large()->isGreaterThan(TestSize::small())); + $this->assertTrue(TestSize::large()->isGreaterThan(TestSize::medium())); + } +} diff --git a/tests/tests/TestStatusTest.php b/tests/tests/TestStatusTest.php new file mode 100644 index 000000000..607ce9141 --- /dev/null +++ b/tests/tests/TestStatusTest.php @@ -0,0 +1,56 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\CodeCoverage\Test\TestStatus; + +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Small; +use PHPUnit\Framework\TestCase; + +#[CoversClass(TestStatus::class)] +#[CoversClass(Known::class)] +#[CoversClass(Unknown::class)] +#[CoversClass(Success::class)] +#[CoversClass(Failure::class)] +#[Small] +final class TestStatusTest extends TestCase +{ + public function testCanBeUnknown(): void + { + $status = TestStatus::unknown(); + + $this->assertTrue($status->isUnknown()); + $this->assertFalse($status->isKnown()); + $this->assertFalse($status->isSuccess()); + $this->assertFalse($status->isFailure()); + $this->assertSame('unknown', $status->asString()); + } + + public function testCanBeSuccess(): void + { + $status = TestStatus::success(); + + $this->assertFalse($status->isUnknown()); + $this->assertTrue($status->isKnown()); + $this->assertTrue($status->isSuccess()); + $this->assertFalse($status->isFailure()); + $this->assertSame('success', $status->asString()); + } + + public function testCanBeFailure(): void + { + $status = TestStatus::failure(); + + $this->assertFalse($status->isUnknown()); + $this->assertTrue($status->isKnown()); + $this->assertFalse($status->isSuccess()); + $this->assertTrue($status->isFailure()); + $this->assertSame('failure', $status->asString()); + } +}