From 2108b0dec6443b3846965d5b29f091296e0a6cba Mon Sep 17 00:00:00 2001 From: Carlos MAtos Date: Wed, 18 Dec 2024 11:30:26 +0000 Subject: [PATCH] Coverage --- .github/workflows/coverage.yml | 3 +-- tests/MultitonTest.php | 18 ++++++++++++++++++ tests/SingletonTest.php | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index f7e6f41..53de49b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -51,7 +51,7 @@ jobs: 'coverage.json': { content: JSON.stringify({ schemaVersion: 1, - label: 'coverage', + label: 'Code Coverage', message: process.env.coverage + '%', color: process.env.coverage >= 80 ? 'success' : process.env.coverage >= 60 ? 'yellow' : 'critical' }) @@ -73,4 +73,3 @@ jobs: label: coverage message: ${{ env.coverage }}% color: ${{ env.coverage >= 80 && 'success' || env.coverage >= 60 && 'yellow' || 'critical' }} - \ No newline at end of file diff --git a/tests/MultitonTest.php b/tests/MultitonTest.php index c82a604..6f977ac 100644 --- a/tests/MultitonTest.php +++ b/tests/MultitonTest.php @@ -43,6 +43,24 @@ public function testHasInstance(): void // Check for a non-existent instance $this->assertFalse(TestMultiton::hasInstance('second')); } + + public function testCloneThrowsException() + { + $this->expectException(\Error::class); + $this->expectExceptionMessage('Call to private Tests\Traits\TestMultiton::__clone() from scope Tests\Traits\MultitonTest'); + + $instance = TestMultiton::getInstance('test'); + clone $instance; + } + + public function testSerializationThrowsException() + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Multiton instances cannot be serialized'); + + $instance = TestMultiton::getInstance('test'); + serialize($instance); + } } class TestMultiton diff --git a/tests/SingletonTest.php b/tests/SingletonTest.php index ab577fa..55200e1 100644 --- a/tests/SingletonTest.php +++ b/tests/SingletonTest.php @@ -22,6 +22,24 @@ public function testInstanceAccessibility() $this->assertEquals('test value', $instance->someProperty); } + + public function testCloneThrowsException() + { + $this->expectException(\Error::class); + $this->expectExceptionMessage('Call to private Tests\Traits\TestSingleton::__clone() from scope Tests\Traits\SingletonTest'); + + $instance = TestSingleton::getInstance(); + clone $instance; + } + + public function testSerializationThrowsException() + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Singleton instance cannot be serialized'); + + $instance = TestSingleton::getInstance(); + serialize($instance); + } } class TestSingleton