|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GeneratedHydratorTest; |
|
6
|
|
|
|
|
7
|
|
|
use CodeGenerationUtils\Autoloader\AutoloaderInterface; |
|
8
|
|
|
use CodeGenerationUtils\GeneratorStrategy\GeneratorStrategyInterface; |
|
9
|
|
|
use CodeGenerationUtils\Inflector\ClassNameInflectorInterface; |
|
10
|
|
|
use GeneratedHydrator\ClassGenerator\HydratorGenerator; |
|
11
|
|
|
use GeneratedHydrator\Configuration; |
|
12
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
use function is_dir; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Tests for {@see \GeneratedHydrator\Configuration} |
|
18
|
|
|
*/ |
|
19
|
|
|
class ConfigurationTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var Configuration */ |
|
22
|
|
|
protected $configuration; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritDoc} |
|
26
|
|
|
* |
|
27
|
|
|
* @covers \GeneratedHydrator\Configuration::__construct |
|
28
|
|
|
*/ |
|
29
|
|
|
public function setUp() : void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->configuration = new Configuration('test'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @covers \GeneratedHydrator\Configuration::setHydratedClassName |
|
36
|
|
|
* @covers \GeneratedHydrator\Configuration::getHydratedClassName |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testGetSetHydratedClassName() : void |
|
39
|
|
|
{ |
|
40
|
|
|
self::assertSame('test', $this->configuration->getHydratedClassName()); |
|
41
|
|
|
$this->configuration->setHydratedClassName('bar'); |
|
42
|
|
|
self::assertSame('bar', $this->configuration->getHydratedClassName()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @covers \GeneratedHydrator\Configuration::createFactory |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testCreateFactory() : void |
|
49
|
|
|
{ |
|
50
|
|
|
self::assertInstanceOf('GeneratedHydrator\Factory\HydratorFactory', $this->configuration->createFactory()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @covers \GeneratedHydrator\Configuration::doesAutoGenerateProxies |
|
55
|
|
|
* @covers \GeneratedHydrator\Configuration::setAutoGenerateProxies |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testGetSetAutoGenerateProxies() : void |
|
58
|
|
|
{ |
|
59
|
|
|
self::assertTrue($this->configuration->doesAutoGenerateProxies(), 'Default setting check for BC'); |
|
60
|
|
|
|
|
61
|
|
|
$this->configuration->setAutoGenerateProxies(false); |
|
62
|
|
|
self::assertFalse($this->configuration->doesAutoGenerateProxies()); |
|
63
|
|
|
|
|
64
|
|
|
$this->configuration->setAutoGenerateProxies(true); |
|
65
|
|
|
self::assertTrue($this->configuration->doesAutoGenerateProxies()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @covers \GeneratedHydrator\Configuration::getGeneratedClassesNamespace |
|
70
|
|
|
* @covers \GeneratedHydrator\Configuration::setGeneratedClassesNamespace |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testGetSetProxiesNamespace() : void |
|
73
|
|
|
{ |
|
74
|
|
|
self::assertSame( |
|
75
|
|
|
'GeneratedHydratorGeneratedClass', |
|
76
|
|
|
$this->configuration->getGeneratedClassesNamespace(), |
|
77
|
|
|
'Default setting check for BC' |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
$this->configuration->setGeneratedClassesNamespace('foo'); |
|
81
|
|
|
self::assertSame('foo', $this->configuration->getGeneratedClassesNamespace()); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @covers \GeneratedHydrator\Configuration::getClassNameInflector |
|
86
|
|
|
* @covers \GeneratedHydrator\Configuration::setClassNameInflector |
|
87
|
|
|
*/ |
|
88
|
|
|
public function testSetGetClassNameInflector() : void |
|
89
|
|
|
{ |
|
90
|
|
|
self::assertInstanceOf(ClassNameInflectorInterface::class, $this->configuration->getClassNameInflector()); |
|
91
|
|
|
|
|
92
|
|
|
/** @var ClassNameInflectorInterface|MockObject $inflector */ |
|
93
|
|
|
$inflector = $this->createMock(ClassNameInflectorInterface::class); |
|
94
|
|
|
|
|
95
|
|
|
$this->configuration->setClassNameInflector($inflector); |
|
|
|
|
|
|
96
|
|
|
self::assertSame($inflector, $this->configuration->getClassNameInflector()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @covers \GeneratedHydrator\Configuration::getGeneratorStrategy |
|
101
|
|
|
* @covers \GeneratedHydrator\Configuration::setGeneratorStrategy |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testSetGetGeneratorStrategy() : void |
|
104
|
|
|
{ |
|
105
|
|
|
self::assertInstanceOf(GeneratorStrategyInterface::class, $this->configuration->getGeneratorStrategy()); |
|
106
|
|
|
|
|
107
|
|
|
/** @var GeneratorStrategyInterface|MockObject $strategy */ |
|
108
|
|
|
$strategy = $this->createMock(GeneratorStrategyInterface::class); |
|
109
|
|
|
|
|
110
|
|
|
$this->configuration->setGeneratorStrategy($strategy); |
|
|
|
|
|
|
111
|
|
|
self::assertSame($strategy, $this->configuration->getGeneratorStrategy()); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @covers \GeneratedHydrator\Configuration::getGeneratedClassesTargetDir |
|
116
|
|
|
* @covers \GeneratedHydrator\Configuration::setGeneratedClassesTargetDir |
|
117
|
|
|
*/ |
|
118
|
|
|
public function testSetGetProxiesTargetDir() : void |
|
119
|
|
|
{ |
|
120
|
|
|
self::assertTrue(is_dir($this->configuration->getGeneratedClassesTargetDir())); |
|
121
|
|
|
|
|
122
|
|
|
$this->configuration->setGeneratedClassesTargetDir(__DIR__); |
|
123
|
|
|
self::assertSame(__DIR__, $this->configuration->getGeneratedClassesTargetDir()); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @covers \GeneratedHydrator\Configuration::getGeneratedClassAutoloader |
|
128
|
|
|
* @covers \GeneratedHydrator\Configuration::setGeneratedClassAutoloader |
|
129
|
|
|
*/ |
|
130
|
|
|
public function testSetGetGeneratedClassAutoloader() : void |
|
131
|
|
|
{ |
|
132
|
|
|
self::assertInstanceOf(AutoloaderInterface::class, $this->configuration->getGeneratedClassAutoloader()); |
|
133
|
|
|
|
|
134
|
|
|
/** @var AutoloaderInterface|MockObject $autoloader */ |
|
135
|
|
|
$autoloader = $this->createMock(AutoloaderInterface::class); |
|
136
|
|
|
|
|
137
|
|
|
$this->configuration->setGeneratedClassAutoloader($autoloader); |
|
|
|
|
|
|
138
|
|
|
self::assertSame($autoloader, $this->configuration->getGeneratedClassAutoloader()); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @covers \GeneratedHydrator\Configuration::getHydratorGenerator |
|
143
|
|
|
* @covers \GeneratedHydrator\Configuration::setHydratorGenerator |
|
144
|
|
|
*/ |
|
145
|
|
|
public function testSetGetHydratorGenerator() : void |
|
146
|
|
|
{ |
|
147
|
|
|
self::assertInstanceOf(HydratorGenerator::class, $this->configuration->getHydratorGenerator()); |
|
148
|
|
|
|
|
149
|
|
|
/** @var HydratorGenerator $generator*/ |
|
150
|
|
|
$generator = $this->createMock(HydratorGenerator::class); |
|
151
|
|
|
|
|
152
|
|
|
$this->configuration->setHydratorGenerator($generator); |
|
|
|
|
|
|
153
|
|
|
self::assertSame($generator, $this->configuration->getHydratorGenerator()); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.