|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
|
6
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataInfo; |
|
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\CodeHelper; |
|
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\AbstractGenerator; |
|
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\UsesPHPMetaDataInterface; |
|
10
|
|
|
use gossi\codegen\model\PhpClass; |
|
11
|
|
|
use gossi\codegen\model\PhpMethod; |
|
12
|
|
|
use gossi\codegen\model\PhpParameter; |
|
13
|
|
|
use gossi\codegen\model\PhpProperty; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class MappingHelperIntegrationTest |
|
17
|
|
|
* |
|
18
|
|
|
* @package EdmondsCommerce\DoctrineStaticMeta |
|
19
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
20
|
|
|
*/ |
|
21
|
|
|
class MappingHelperIntegrationTest extends AbstractFunctionalTest |
|
22
|
|
|
{ |
|
23
|
|
|
public const WORK_DIR = AbstractIntegrationTest::VAR_PATH.'/'.self::TEST_TYPE.'/MappingHelperIntegrationTest/'; |
|
24
|
|
|
|
|
25
|
|
|
protected const TEST_ENTITY_FQN_BASE = AbstractIntegrationTest::TEST_PROJECT_ROOT_NAMESPACE |
|
26
|
|
|
.'\\'.AbstractGenerator::ENTITIES_FOLDER_NAME |
|
27
|
|
|
.'\\MappingEntity'; |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
public function testInvalidBoolThrowsException() |
|
31
|
|
|
{ |
|
32
|
|
|
$entityFqn = self::TEST_ENTITY_FQN_BASE.'Bool'; |
|
33
|
|
|
$this->getEntityGenerator() |
|
34
|
|
|
->generateEntity($entityFqn); |
|
35
|
|
|
$builder = new ClassMetadataBuilder(new ClassMetadataInfo($entityFqn)); |
|
36
|
|
|
|
|
37
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
38
|
|
|
MappingHelper::setSimpleBooleanFields(['test'], $builder, 3); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testInvalidStringThrowsException() |
|
42
|
|
|
{ |
|
43
|
|
|
$entityFqn = self::TEST_ENTITY_FQN_BASE.'String'; |
|
44
|
|
|
$this->getEntityGenerator() |
|
45
|
|
|
->generateEntity($entityFqn); |
|
46
|
|
|
$builder = new ClassMetadataBuilder(new ClassMetadataInfo($entityFqn)); |
|
47
|
|
|
|
|
48
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
49
|
|
|
MappingHelper::setSimpleStringFields(['test'], $builder, 3); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testInvalidDateTimeThrowsException() |
|
53
|
|
|
{ |
|
54
|
|
|
$entityFqn = self::TEST_ENTITY_FQN_BASE.'DateTime'; |
|
55
|
|
|
$this->getEntityGenerator() |
|
56
|
|
|
->generateEntity($entityFqn); |
|
57
|
|
|
$builder = new ClassMetadataBuilder(new ClassMetadataInfo($entityFqn)); |
|
58
|
|
|
|
|
59
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
60
|
|
|
MappingHelper::setSimpleDatetimeFields(['test'], $builder, 3); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testInvalidFloatThrowsException() |
|
64
|
|
|
{ |
|
65
|
|
|
$entityFqn = self::TEST_ENTITY_FQN_BASE.'Float'; |
|
66
|
|
|
$this->getEntityGenerator() |
|
67
|
|
|
->generateEntity($entityFqn); |
|
68
|
|
|
$builder = new ClassMetadataBuilder(new ClassMetadataInfo($entityFqn)); |
|
69
|
|
|
|
|
70
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
71
|
|
|
MappingHelper::setSimpleFloatFields(['test'], $builder, 'cheese'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testInvalidDecimalThrowsException() |
|
75
|
|
|
{ |
|
76
|
|
|
$entityFqn = self::TEST_ENTITY_FQN_BASE.'Decimal'; |
|
77
|
|
|
$this->getEntityGenerator() |
|
78
|
|
|
->generateEntity($entityFqn); |
|
79
|
|
|
$builder = new ClassMetadataBuilder(new ClassMetadataInfo($entityFqn)); |
|
80
|
|
|
|
|
81
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
82
|
|
|
MappingHelper::setSimpleDecimalFields(['test'], $builder, 'cheese'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testInvalidTextThrowsException() |
|
86
|
|
|
{ |
|
87
|
|
|
$entityFqn = self::TEST_ENTITY_FQN_BASE.'Text'; |
|
88
|
|
|
$this->getEntityGenerator() |
|
89
|
|
|
->generateEntity($entityFqn); |
|
90
|
|
|
$builder = new ClassMetadataBuilder(new ClassMetadataInfo($entityFqn)); |
|
91
|
|
|
|
|
92
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
93
|
|
|
MappingHelper::setSimpleTextFields(['test'], $builder, true); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testInvalidIntegerThrowsException() |
|
97
|
|
|
{ |
|
98
|
|
|
$entityFqn = self::TEST_ENTITY_FQN_BASE.'Integer'; |
|
99
|
|
|
$this->getEntityGenerator() |
|
100
|
|
|
->generateEntity($entityFqn); |
|
101
|
|
|
$builder = new ClassMetadataBuilder(new ClassMetadataInfo($entityFqn)); |
|
102
|
|
|
|
|
103
|
|
|
$this->expectException(\InvalidArgumentException::class); |
|
104
|
|
|
MappingHelper::setSimpleIntegerFields(['test'], $builder, 'cheese'); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|