Skip to content

Commit c996bca

Browse files
committed
respositorie was defined
1 parent 4a03bd8 commit c996bca

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Repositories/Catalog/Products/ProductRepository.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
final class ProductRepository
66
{
7-
private static ProductRepositoryInterface $repository;
7+
private static ?ProductRepositoryInterface $repository = null;
88

99
public function __construct()
1010
{
@@ -15,6 +15,16 @@ public static function config(ProductRepositoryInterface $repository): void
1515
static::$repository = $repository;
1616
}
1717

18+
public static function configDefined(): bool
19+
{
20+
return isset(static::$repository);
21+
}
22+
23+
public static function clearConfig(): void
24+
{
25+
static::$repository = null;
26+
}
27+
1828
public static function get(int $productId): ?array
1929
{
2030
if (! isset(static::$repository)) {

tests/Feature/ProductRepositoryTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99
class ProductRepositoryTest extends TestCase
1010
{
11+
public function setUp(): void
12+
{
13+
parent::setUp();
14+
15+
ProductRepository::clearConfig();
16+
}
17+
18+
public function testDefinedRepository()
19+
{
20+
$this->assertFalse(ProductRepository::configDefined());
21+
ProductRepository::config(new ProductRepositoryDriver());
22+
$this->assertTrue(ProductRepository::configDefined());
23+
}
24+
1125
public function testGetRepositoryUni()
1226
{
1327
$product = ProductRepository::get(1);

0 commit comments

Comments
 (0)