Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cmatosbc committed Dec 18, 2024
1 parent 9bc5f22 commit 2108b0d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand All @@ -73,4 +73,3 @@ jobs:
label: coverage
message: ${{ env.coverage }}%
color: ${{ env.coverage >= 80 && 'success' || env.coverage >= 60 && 'yellow' || 'critical' }}

18 changes: 18 additions & 0 deletions tests/MultitonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/SingletonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2108b0d

Please sign in to comment.