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