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
|
|
|
|