|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GeneratedHydratorTest\Factory; |
|
6
|
|
|
|
|
7
|
|
|
use CodeGenerationUtils\GeneratorStrategy\EvaluatingGeneratorStrategy; |
|
8
|
|
|
use CodeGenerationUtils\Inflector\Util\UniqueIdentifierGenerator; |
|
9
|
|
|
use CodeGenerationUtils\ReflectionBuilder\ClassBuilder; |
|
10
|
|
|
use CodeGenerationUtils\Visitor\ClassRenamerVisitor; |
|
11
|
|
|
use GeneratedHydrator\Configuration; |
|
12
|
|
|
use PhpParser\NodeTraverser; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use ReflectionClass; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Integration tests for {@see \GeneratedHydrator\Factory\HydratorFactory} |
|
18
|
|
|
* |
|
19
|
|
|
* @group Functional |
|
20
|
|
|
*/ |
|
21
|
|
|
class HydratorFactoryFunctionalTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** @var Configuration */ |
|
24
|
|
|
protected $config; |
|
25
|
|
|
|
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
protected $generatedClassName; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritDoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function setUp() : void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->generatedClassName = UniqueIdentifierGenerator::getIdentifier('foo'); |
|
35
|
|
|
$this->config = new Configuration($this->generatedClassName); |
|
36
|
|
|
$generatorStrategy = new EvaluatingGeneratorStrategy(); |
|
37
|
|
|
$reflection = new ReflectionClass('GeneratedHydratorTestAsset\ClassWithMixedProperties'); |
|
38
|
|
|
$generator = new ClassBuilder(); |
|
39
|
|
|
$traverser = new NodeTraverser(); |
|
40
|
|
|
$renamer = new ClassRenamerVisitor($reflection, $this->generatedClassName); |
|
41
|
|
|
|
|
42
|
|
|
$traverser->addVisitor($renamer); |
|
43
|
|
|
|
|
44
|
|
|
// evaluating the generated class |
|
45
|
|
|
//die(var_dump($traverser->traverse($generator->fromReflection($reflection)))); |
|
46
|
|
|
$ast = $traverser->traverse($generator->fromReflection($reflection)); |
|
47
|
|
|
$generatorStrategy->generate($ast); |
|
48
|
|
|
|
|
49
|
|
|
$this->config->setGeneratorStrategy($generatorStrategy); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @covers \GeneratedHydrator\Factory\HydratorFactory::__construct |
|
54
|
|
|
* @covers \GeneratedHydrator\Factory\HydratorFactory::getHydratorClass |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testWillGenerateValidClass() : void |
|
57
|
|
|
{ |
|
58
|
|
|
$generatedClass = $this->config->createFactory()->getHydratorClass(); |
|
59
|
|
|
|
|
60
|
|
|
self::assertInstanceOf('Zend\Hydrator\HydratorInterface', new $generatedClass()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @covers \GeneratedHydrator\Factory\HydratorFactory::__construct |
|
65
|
|
|
* @covers \GeneratedHydrator\Factory\HydratorFactory::getHydrator |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testWillInstantiateValidHydrator(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$factory = $this->config->createFactory(); |
|
70
|
|
|
$hydratorClass = $factory->getHydratorClass(); |
|
71
|
|
|
$hydrator = $factory->getHydrator(); |
|
72
|
|
|
|
|
73
|
|
|
self::assertEquals(new $hydratorClass(), $hydrator); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|