|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\CodeGeneration; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
|
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\ReflectionHelper; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\FakerData\String\BusinessIdentifierCodeFakerData; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\FakerData\String\CountryCodeFakerData; |
|
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\BusinessIdentifierCodeFieldTrait; |
|
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\String\CountryCodeFieldTrait; |
|
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest; |
|
12
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\ReflectionHelper |
|
16
|
|
|
* @large |
|
17
|
|
|
*/ |
|
18
|
|
|
class ReflectionHelperTest extends AbstractTest |
|
19
|
|
|
{ |
|
20
|
|
|
public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/NamespaceHelperTest'; |
|
21
|
|
|
|
|
22
|
|
|
private const TEST_ENTITY = self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_PERSON; |
|
23
|
|
|
|
|
24
|
|
|
protected static $buildOnce = true; |
|
25
|
|
|
|
|
26
|
|
|
public function setup() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::setUp(); |
|
29
|
|
|
if (false === self::$built) { |
|
30
|
|
|
$this->getTestCodeGenerator() |
|
31
|
|
|
->copyTo(self::WORK_DIR); |
|
32
|
|
|
self::$built = true; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @test |
|
38
|
|
|
* @large |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getFakerProviderFqnFromFieldTraitReflection(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$expected = [ |
|
43
|
|
|
BusinessIdentifierCodeFieldTrait::class => BusinessIdentifierCodeFakerData::class, |
|
44
|
|
|
CountryCodeFieldTrait::class => CountryCodeFakerData::class, |
|
45
|
|
|
]; |
|
46
|
|
|
$actual = []; |
|
47
|
|
|
foreach (array_keys($expected) as $fieldFqn) { |
|
48
|
|
|
$actual[$fieldFqn] = $this->getHelper()->getFakerProviderFqnFromFieldTraitReflection( |
|
49
|
|
|
new \ts\Reflection\ReflectionClass($fieldFqn) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
self::assertSame($expected, $actual); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @throws \ReflectionException |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testGetEntityNamespaceRootFromEntityReflection(): void |
|
59
|
|
|
{ |
|
60
|
|
|
|
|
61
|
|
|
$entityReflection = new \ts\Reflection\ReflectionClass(self::TEST_ENTITY); |
|
62
|
|
|
$expected = self::TEST_PROJECT_ROOT_NAMESPACE . '\\' . AbstractGenerator::ENTITIES_FOLDER_NAME; |
|
63
|
|
|
$actual = $this->getHelper()->getEntityNamespaceRootFromEntityReflection($entityReflection); |
|
64
|
|
|
self::assertSame($expected, $actual); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function getHelper(): ReflectionHelper |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->container->get(ReflectionHelper::class); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|