Completed
Push — master ( 0e62b9...f2b79c )
by Korotkov
03:40 queued 02:16
created

FactoryMethodTest::getFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Creational\FactoryMethod\Tests;
11
12
use Creational\FactoryMethod\FirstProduct;
13
use Creational\FactoryMethod\SecondProduct;
14
use Creational\FactoryMethod\FactoryMethod;
15
use Creational\FactoryMethod\ProductInterface;
16
use Creational\FactoryMethod\FactoryMethodInterface;
17
use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
18
19
/**
20
 * Class FactoryMethodTest
21
 */
22
class FactoryMethodTest extends PHPUnit_Framework_TestCase
23
{
24
    /**
25
     * @var FactoryMethodInterface
26
     */
27
    private $factory;
28
29
    protected function setUp(): void
30
    {
31
        $this->factory = new FactoryMethod();
32
    }
33
34
    public function testProducts()
35
    {
36
        $this->assertEquals($this->getFactory()->create(FirstProduct::class)->getClassName(), FirstProduct::class);
37
        $this->assertEquals($this->getFactory()->create(SecondProduct::class)->getClassName(), SecondProduct::class);
38
    }
39
40
    public function testFactoryMethod()
41
    {
42
        $this->assertInstanceOf(FactoryMethodInterface::class, $this->getFactory());
43
        $this->assertInstanceOf(ProductInterface::class, $this->getFactory()->create(FirstProduct::class));
44
        $this->assertInstanceOf(ProductInterface::class, $this->getFactory()->create(SecondProduct::class));
45
    }
46
47
    /**
48
     * @return FactoryMethod
49
     */
50
    public function getFactory(): FactoryMethodInterface
51
    {
52
        return $this->factory;
53
    }
54
}
55