diff --git a/src/WritersInstance.php b/src/WritersInstance.php index 846d516..36d1c09 100644 --- a/src/WritersInstance.php +++ b/src/WritersInstance.php @@ -18,23 +18,18 @@ final class WritersInstance { - private static ?WritersInterface $instance; + private static WritersInterface $instance; public function __construct(WritersInterface $writers) { self::$instance = $writers; } - public function __destruct() - { - self::$instance = null; - } - public static function get(): WritersInterface { if (! isset(self::$instance)) { throw new LogicException( - 'No writers instance present' + sprintf('No `%s` instance present', WritersInterface::class) ); } diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 0d52d19..fd0a699 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -22,12 +22,18 @@ final class FunctionsTest extends TestCase { + public function testWritersNoInstance(): void + { + $this->expectException(LogicException::class); + writers(); + } + public function testWritersInstance(): void { $writers = new Writers(); $instance = new WritersInstance($writers); + $this->assertSame($writers, writers()); $this->assertSame($instance->get(), writers()); - unset($instance); } public function testStreamFor(): void diff --git a/tests/WritersInstanceTest.php b/tests/WritersInstanceTest.php index 7e02d61..074c665 100644 --- a/tests/WritersInstanceTest.php +++ b/tests/WritersInstanceTest.php @@ -15,22 +15,14 @@ use Chevere\Writer\Writers; use Chevere\Writer\WritersInstance; -use LogicException; use PHPUnit\Framework\TestCase; final class WritersInstanceTest extends TestCase { - public function testNoConstruct(): void - { - $this->expectException(LogicException::class); - WritersInstance::get(); - } - public function testConstruct(): void { $writers = new Writers(); $instance = new WritersInstance($writers); $this->assertSame($writers, $instance::get()); - unset($instance); } }