File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
src/Repositories/Catalog/Products Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 4
4
5
5
final class ProductRepository
6
6
{
7
- private static ProductRepositoryInterface $ repository ;
7
+ private static ? ProductRepositoryInterface $ repository = null ;
8
8
9
9
public function __construct ()
10
10
{
@@ -15,6 +15,16 @@ public static function config(ProductRepositoryInterface $repository): void
15
15
static ::$ repository = $ repository ;
16
16
}
17
17
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
+
18
28
public static function get (int $ productId ): ?array
19
29
{
20
30
if (! isset (static ::$ repository )) {
Original file line number Diff line number Diff line change 8
8
9
9
class ProductRepositoryTest extends TestCase
10
10
{
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
+
11
25
public function testGetRepositoryUni ()
12
26
{
13
27
$ product = ProductRepository::get (1 );
You can’t perform that action at this time.
0 commit comments