This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Atrapalo\PHPTools\Tester\Collection; |
||
4 | |||
5 | use Atrapalo\PHPTools\Collection\EntityCollection; |
||
6 | |||
7 | /** |
||
8 | * Class EntityCollectionTester |
||
9 | * @package Atrapalo\PHPTools\Collection |
||
10 | * |
||
11 | * @author Guillermo González <[email protected]> |
||
12 | */ |
||
13 | trait EntityCollectionTester |
||
14 | { |
||
15 | /** |
||
16 | * @return string |
||
17 | */ |
||
18 | abstract protected function entityCollectionClass(): string; |
||
19 | |||
20 | /** |
||
21 | * @test |
||
22 | * @dataProvider invalidEntities |
||
23 | * @param array $elements |
||
24 | */ |
||
25 | public function invalidElementByConstructor(array $elements) |
||
26 | { |
||
27 | /** @var EntityCollection $entityCollectionClass */ |
||
28 | $entityCollectionClass = $this->entityCollectionClass(); |
||
29 | $exception = $entityCollectionClass::customInvalidEntityException(); |
||
30 | |||
31 | $this->expectException(get_class($exception)); |
||
0 ignored issues
–
show
|
|||
32 | $this->expectExceptionMessage($exception->getMessage()); |
||
0 ignored issues
–
show
It seems like
expectExceptionMessage() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
33 | |||
34 | new $entityCollectionClass($elements); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @return array |
||
39 | */ |
||
40 | public function invalidEntities() |
||
41 | { |
||
42 | return [ |
||
43 | [[1]], |
||
44 | [['element']], |
||
45 | [[new \stdClass()]], |
||
46 | [[new \stdClass(), new \stdClass()]], |
||
47 | [[null]], |
||
48 | [[false]] |
||
49 | ]; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @test |
||
54 | */ |
||
55 | public function emptyConstructor() |
||
56 | { |
||
57 | /** @var EntityCollection $entityCollectionClass */ |
||
58 | $entityCollectionClass = $this->entityCollectionClass(); |
||
59 | |||
60 | /** @var EntityCollection $collection */ |
||
61 | $collection = new $entityCollectionClass(); |
||
62 | |||
63 | $this->assertSame(0, $collection->count()); |
||
0 ignored issues
–
show
It seems like
assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
64 | $this->assertTrue($collection->isEmpty()); |
||
0 ignored issues
–
show
It seems like
assertTrue() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @test |
||
69 | */ |
||
70 | public function invalidAddElement() |
||
71 | { |
||
72 | /** @var EntityCollection $entityCollectionClass */ |
||
73 | $entityCollectionClass = $this->entityCollectionClass(); |
||
74 | $exception = $entityCollectionClass::customInvalidEntityException(); |
||
75 | |||
76 | $this->expectException(get_class($exception)); |
||
0 ignored issues
–
show
It seems like
expectException() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
77 | $this->expectExceptionMessage($exception->getMessage()); |
||
0 ignored issues
–
show
It seems like
expectExceptionMessage() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
78 | |||
79 | /** @var EntityCollection $collection */ |
||
80 | $collection = new $entityCollectionClass([], true); |
||
81 | $collection->add([]); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @test |
||
86 | */ |
||
87 | public function validChildrenElementByConstructor() |
||
88 | { |
||
89 | /** @var EntityCollection $entityCollectionClass */ |
||
90 | $entityCollectionClass = $this->entityCollectionClass(); |
||
91 | $exception = $entityCollectionClass::customInvalidEntityException(); |
||
92 | |||
93 | $this->expectException(get_class($exception)); |
||
0 ignored issues
–
show
It seems like
expectException() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
94 | $this->expectExceptionMessage($exception->getMessage()); |
||
0 ignored issues
–
show
It seems like
expectExceptionMessage() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
95 | |||
96 | new $entityCollectionClass([$this->prophesize($entityCollectionClass::entityClass())->reveal()]); |
||
0 ignored issues
–
show
It seems like
prophesize() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @test |
||
101 | */ |
||
102 | public function validElementByConstructor() |
||
103 | { |
||
104 | /** @var EntityCollection $entityCollectionClass */ |
||
105 | $entityCollectionClass = $this->entityCollectionClass(); |
||
106 | |||
107 | /** @var EntityCollection $collection */ |
||
108 | $collection = new $entityCollectionClass([$this->prophesize($entityCollectionClass::entityClass())->reveal()], true); |
||
0 ignored issues
–
show
It seems like
prophesize() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
109 | |||
110 | $this->assertSame(1, $collection->count()); |
||
0 ignored issues
–
show
It seems like
assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
111 | $this->assertInstanceOf($entityCollectionClass::entityClass(), $collection->current()); |
||
0 ignored issues
–
show
It seems like
assertInstanceOf() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @test |
||
116 | */ |
||
117 | public function addTwoValidElement() |
||
118 | { |
||
119 | /** @var EntityCollection $entityCollectionClass */ |
||
120 | $entityCollectionClass = $this->entityCollectionClass(); |
||
121 | |||
122 | /** @var EntityCollection $collection */ |
||
123 | $collection = new $entityCollectionClass([$this->prophesize($entityCollectionClass::entityClass())->reveal()], true); |
||
0 ignored issues
–
show
It seems like
prophesize() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
124 | |||
125 | |||
126 | /** @var \Prophecy\Prophecy\ObjectProphecy $entity */ |
||
127 | $entity = $this->prophesize($entityCollectionClass::entityClass()); |
||
0 ignored issues
–
show
It seems like
prophesize() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
128 | $collection->add($entity->reveal()); |
||
129 | $collection->add($entity->reveal()); |
||
130 | |||
131 | $this->assertSame(3, $collection->count()); |
||
0 ignored issues
–
show
It seems like
assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
132 | foreach ($collection as $element) { |
||
133 | $this->assertInstanceOf($entityCollectionClass::entityClass(), $element); |
||
0 ignored issues
–
show
It seems like
assertInstanceOf() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
134 | } |
||
135 | } |
||
136 | } |
||
137 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.