Test Failed
Push — main ( 4e5202...c3e146 )
by Dylan
02:21
created

ObjectFactoryTest::testFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 20
rs 9.9332
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Lifeboat\Tests\Factory;
4
5
use Lifeboat\Client;
6
use Lifeboat\Exceptions\InvalidArgumentException;
7
use Lifeboat\Factory\ClassMap;
8
use Lifeboat\Factory\ObjectFactory;
9
use Lifeboat\Factory\ServiceFactory;
10
use Lifeboat\Models\LifeboatModel;
11
use Lifeboat\Models\Order;
12
use PHPUnit\Framework\TestCase;
13
14
class ObjectFactoryTest extends TestCase {
15
16
    /**
17
     * @test
18
     * @covers \Lifeboat\Factory\ObjectFactory::create
19
     * @covers \Lifeboat\Factory\ObjectFactory::make
20
     * @covers \Lifeboat\Models\LifeboatModel::__construct
21
     */
22
    public function testFactory()
23
    {
24
        $mock       = new Client('mock', 'mock');
25
        $mock_data  = ['ID' => 0];
26
27
        foreach (ClassMap::MODELS as $name => $class) {
28
            $this->assertInstanceOf($class, ObjectFactory::create($mock, $name, $mock_data));
29
            $this->assertInstanceOf($class, ObjectFactory::create($mock, strtoupper($name), $mock_data));
30
        }
31
32
        // Test the make function
33
        $this->assertInstanceOf(Order::class, ObjectFactory::make($mock, ['model' => 'order']));
34
35
        // Default if model is invalid
36
        $this->assertInstanceOf(LifeboatModel::class, ObjectFactory::create($mock, 'does_not_exist', $mock_data));
37
        $this->assertInstanceOf(LifeboatModel::class, ObjectFactory::make($mock, ['model' => 'does_not_exist']));
38
39
        // Expect error
40
        $this->expectException(InvalidArgumentException::class);
41
        ObjectFactory::create($mock, 'does_not_exist');
42
    }
43
}
44