|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Tests\Lib\DB\ORM; |
|
6
|
|
|
|
|
7
|
|
|
use Lib\DB\ORM\HydratorDecoratorFactory; |
|
8
|
|
|
use Lib\Routing\RouteDefinition; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class HydratorDecoratorFactoryTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var HydratorDecoratorFactory */ |
|
14
|
|
|
private $factory; |
|
15
|
|
|
|
|
16
|
|
|
public function setUp() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->factory = new HydratorDecoratorFactory(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testCreateHydratorFileCreatesFile() |
|
22
|
|
|
{ |
|
23
|
|
|
$file = __DIR__.'/../../../../../../var/cache/tests/RouteDefinitionHydratorDecorator.php'; |
|
24
|
|
|
$hydratorClass = 'RouteDefinitionHydratorDecorator'; |
|
25
|
|
|
|
|
26
|
|
|
$this->factory->createHydratorFile(RouteDefinition::class, $hydratorClass, $file); |
|
27
|
|
|
include $file; |
|
28
|
|
|
$hydrator = new $hydratorClass('home', '/'); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertTrue(file_exists($file)); |
|
31
|
|
|
$this->assertInstanceOf(RouteDefinition::class, $hydrator); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testCreateHydratorForClassCreatesHydrator() |
|
35
|
|
|
{ |
|
36
|
|
|
$hydratorClass = 'RouteDefinitionHydratorDecorator'; |
|
37
|
|
|
|
|
38
|
|
|
$this->factory->createHydratorForClass(RouteDefinition::class, ['home', '/']); |
|
39
|
|
|
$hydrator = new $hydratorClass('home', '/'); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertInstanceOf(RouteDefinition::class, $hydrator); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testGetHydratorForClassReturnsPreviouslyInstanciatedHydrator() |
|
45
|
|
|
{ |
|
46
|
|
|
$hydrator = $this->factory->getHydratorForClass(RouteDefinition::class, ['home', '/']); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertInstanceOf(RouteDefinition::class, $hydrator); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testGetHydratorForClassWithObjectAsArg() |
|
52
|
|
|
{ |
|
53
|
|
|
$hydrator = $this->factory->getHydratorForClass(new RouteDefinition('home', '/'), ['home', '/']); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertInstanceOf(RouteDefinition::class, $hydrator); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|