Skip to content

Commit

Permalink
fix persistency
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jun 5, 2024
1 parent 3c4420a commit 1a5801a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
9 changes: 2 additions & 7 deletions src/WritersInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}

Expand Down
8 changes: 7 additions & 1 deletion tests/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions tests/WritersInstanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 1a5801a

Please sign in to comment.