1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lifeboat\Tests\Factory; |
4
|
|
|
|
5
|
|
|
use Lifeboat\Exceptions\InvalidArgumentException; |
6
|
|
|
use Lifeboat\Factory\ClassMap; |
7
|
|
|
use Lifeboat\Factory\ObjectFactory; |
8
|
|
|
use Lifeboat\Models\LifeboatModel; |
9
|
|
|
use Lifeboat\Models\Order; |
10
|
|
|
use Lifeboat\Tests\TestCase; |
11
|
|
|
|
12
|
|
|
class ObjectFactoryTest extends TestCase { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @test |
16
|
|
|
* @covers \Lifeboat\Factory\ObjectFactory::create |
17
|
|
|
* @covers \Lifeboat\Factory\ObjectFactory::make |
18
|
|
|
* @covers \Lifeboat\Models\LifeboatModel::__construct |
19
|
|
|
*/ |
20
|
|
|
public function testFactory() |
21
|
|
|
{ |
22
|
|
|
$mock_data = ['ID' => 0]; |
23
|
|
|
|
24
|
|
|
foreach (ClassMap::MODELS as $name => $class) { |
25
|
|
|
$this->assertInstanceOf($class, ObjectFactory::create($this->getMockClient(), $name, $mock_data)); |
26
|
|
|
$this->assertInstanceOf($class, ObjectFactory::create($this->getMockClient(), strtoupper($name), $mock_data)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// Test the make function |
30
|
|
|
$this->assertInstanceOf(Order::class, ObjectFactory::make($this->getMockClient(), ['model' => 'order'])); |
31
|
|
|
|
32
|
|
|
// Default if model is invalid |
33
|
|
|
$this->assertInstanceOf(LifeboatModel::class, ObjectFactory::create($this->getMockClient(), 'does_not_exist', $mock_data)); |
34
|
|
|
$this->assertInstanceOf(LifeboatModel::class, ObjectFactory::make($this->getMockClient(), ['model' => 'does_not_exist'])); |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
try { |
38
|
|
|
ObjectFactory::create($this->getMockClient(), 'does_not_exist'); |
39
|
|
|
$this->fail('ObjectFactory::create should have thrown error for a model class that does not exist'); |
40
|
|
|
} catch (InvalidArgumentException $e) { |
41
|
|
|
// Error should be thrown |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|