Passed
Branch main (d4eae3)
by Chema
03:50
created

php$0   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 4
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
c 1
b 0
f 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Unit\Framework\Factory;
6
7
use Gacela\Framework\AbstractFactory;
8
use GacelaTest\Fixtures\CustomClass;
9
use GacelaTest\Fixtures\CustomInterface;
10
use PHPUnit\Framework\TestCase;
11
12
final class FactorySingletonTest extends TestCase
13
{
14
    public function test_singleton_returns_same_instance(): void
15
    {
16
        $factory = new class() extends AbstractFactory {
17
            public function createObject(): CustomInterface
18
            {
19
                return $this->singleton(CustomInterface::class, static fn (): CustomClass => new CustomClass());
20
            }
21
        };
22
        $a = $factory->createObject();
23
        $b = $factory->createObject();
24
25
        self::assertSame($a, $b);
26
    }
27
28
    public function test_without_singleton_returns_new_instance(): void
29
    {
30
        $factory = new class() extends AbstractFactory {
31
            public function createObject(): CustomInterface
32
            {
33
                return new CustomClass();
34
            }
35
        };
36
37
        $a = $factory->createObject();
38
        $b = $factory->createObject();
39
40
        self::assertNotSame($a, $b);
41
    }
42
}
43