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); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
36 | $animals = $modelInstance->getDocumentElement(); |
||||||
37 | $animals->addAnimal($bird); |
||||||
0 ignored issues
–
show
The method
addAnimal() does not exist on Xml\Instance\ModelElementInstanceInterface . It seems like you code against a sub-type of Xml\Instance\ModelElementInstanceInterface such as Tests\TestModel\Instance\Animals .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
38 | return $bird; |
||||||
0 ignored issues
–
show
|
|||||||
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); |
||||||
0 ignored issues
–
show
The method
setAnimal() does not exist on Xml\Instance\ModelElementInstanceInterface . It seems like you code against a sub-type of Xml\Instance\ModelElementInstanceInterface such as Tests\TestModel\Instance\RelationshipDefinition .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
51 | return $relationshipDefinition; |
||||||
0 ignored issues
–
show
|
|||||||
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; |
||||||
0 ignored issues
–
show
|
|||||||
67 | } |
||||||
68 | } |
||||||
69 |