|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\TestModel; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Xml\ModelInstanceInterface; |
|
7
|
|
|
use Xml\Impl\Parser\AbstractModelParser; |
|
8
|
|
|
use Tests\TestModel\TestModelParser; |
|
9
|
|
|
use Tests\TestModel\Instance\{ |
|
10
|
|
|
Animal, |
|
11
|
|
|
Bird, |
|
12
|
|
|
RelationshipDefinition, |
|
13
|
|
|
Egg |
|
14
|
|
|
}; |
|
15
|
|
|
|
|
16
|
|
|
abstract class TestModelTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
protected $modelParser; |
|
19
|
|
|
|
|
20
|
|
|
protected $modelInstance; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $test |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function parseModel(string $test) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->modelParser = new TestModelParser(); |
|
28
|
|
|
$xml = fopen('tests/TestModel/Resources/TestModel/' . $test . '.xml', 'r+'); |
|
29
|
|
|
$this->modelInstance = $this->modelParser->parseModelFromStream($xml); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function createBird(ModelInstanceInterface $modelInstance, string $id, string $gender): Bird |
|
33
|
|
|
{ |
|
34
|
|
|
$bird = $modelInstance->newInstance(Bird::class, $id); |
|
35
|
|
|
$bird->setGender($gender); |
|
|
|
|
|
|
36
|
|
|
$animals = $modelInstance->getDocumentElement(); |
|
37
|
|
|
$animals->addAnimal($bird); |
|
|
|
|
|
|
38
|
|
|
return $bird; |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
protected function createRelationshipDefinition( |
|
42
|
|
|
ModelInstanceInterface $modelInstance, |
|
43
|
|
|
Animal $animalInRelationshipWith, |
|
44
|
|
|
string $relationshipDefinitionClass |
|
45
|
|
|
): RelationshipDefinition { |
|
46
|
|
|
$relationshipDefinition = $modelInstance->newInstance( |
|
47
|
|
|
$relationshipDefinitionClass, |
|
48
|
|
|
"relationship-" . $animalInRelationshipWith->getId() |
|
49
|
|
|
); |
|
50
|
|
|
$relationshipDefinition->setAnimal($animalInRelationshipWith); |
|
|
|
|
|
|
51
|
|
|
return $relationshipDefinition; |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
protected function addRelationshipDefinition( |
|
55
|
|
|
Animal $animalWithRelationship, |
|
56
|
|
|
RelationshipDefinition $relationshipDefinition |
|
57
|
|
|
): void { |
|
58
|
|
|
$animalInRelationshipWith = $relationshipDefinition->getAnimal(); |
|
59
|
|
|
$relationshipDefinition->setId($animalWithRelationship->getId() . "-" . $animalInRelationshipWith->getId()); |
|
60
|
|
|
$animalWithRelationship->addRelationship($relationshipDefinition); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function createEgg(ModelInstanceInterface $modelInstance, string $id): Egg |
|
64
|
|
|
{ |
|
65
|
|
|
$egg = $modelInstance->newInstance(Egg::class, $id); |
|
66
|
|
|
return $egg; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|