1 | <?php |
||||||
2 | /** |
||||||
3 | * Copyright (C) 2017 Gerrit Addiks. |
||||||
4 | * This package (including this file) was released under the terms of the GPL-3.0. |
||||||
5 | * You should have received a copy of the GNU General Public License along with this program. |
||||||
6 | * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy. |
||||||
7 | * @license GPL-3.0 |
||||||
8 | * @author Gerrit Addiks <[email protected]> |
||||||
9 | */ |
||||||
10 | |||||||
11 | namespace Addiks\RDMBundle\Tests\Mapping; |
||||||
12 | |||||||
13 | use PHPUnit\Framework\TestCase; |
||||||
14 | use Addiks\RDMBundle\Mapping\FieldMapping; |
||||||
15 | use Doctrine\DBAL\Schema\Column; |
||||||
16 | use Addiks\RDMBundle\Hydration\HydrationContextInterface; |
||||||
17 | use Doctrine\ORM\EntityManagerInterface; |
||||||
18 | use Doctrine\DBAL\Connection; |
||||||
19 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
||||||
20 | use Doctrine\DBAL\Types\Type; |
||||||
21 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||||||
22 | |||||||
23 | final class FieldMappingTest extends TestCase |
||||||
24 | { |
||||||
25 | |||||||
26 | /** |
||||||
27 | * @var FieldMapping |
||||||
28 | */ |
||||||
29 | private $fieldMapping; |
||||||
30 | |||||||
31 | /** |
||||||
32 | * @var Column |
||||||
33 | */ |
||||||
34 | private $dbalColumn; |
||||||
35 | |||||||
36 | public function setUp(): void |
||||||
37 | { |
||||||
38 | $this->dbalColumn = $this->createMock(Column::class); |
||||||
0 ignored issues
–
show
|
|||||||
39 | |||||||
40 | $this->fieldMapping = new FieldMapping($this->dbalColumn, "some origin"); |
||||||
41 | } |
||||||
42 | |||||||
43 | /** |
||||||
44 | * @test |
||||||
45 | */ |
||||||
46 | public function shouldStoreDBALColumn() |
||||||
47 | { |
||||||
48 | $this->assertSame($this->dbalColumn, $this->fieldMapping->getDBALColumn()); |
||||||
49 | } |
||||||
50 | |||||||
51 | /** |
||||||
52 | * @test |
||||||
53 | */ |
||||||
54 | public function shouldStoreOrigin() |
||||||
55 | { |
||||||
56 | $this->assertSame("some origin", $this->fieldMapping->describeOrigin()); |
||||||
57 | } |
||||||
58 | |||||||
59 | /** |
||||||
60 | * @test |
||||||
61 | */ |
||||||
62 | public function shouldCollectDBALColumns() |
||||||
63 | { |
||||||
64 | $this->assertSame([$this->dbalColumn], $this->fieldMapping->collectDBALColumns()); |
||||||
65 | } |
||||||
66 | |||||||
67 | /** |
||||||
68 | * @test |
||||||
69 | */ |
||||||
70 | public function shouldResolveFieldValue() |
||||||
71 | { |
||||||
72 | /** @var HydrationContextInterface $context */ |
||||||
73 | $context = $this->createMock(HydrationContextInterface::class); |
||||||
74 | $context->method('getEntityClass')->willReturn(EntityExample::class); |
||||||
0 ignored issues
–
show
The method
method() does not exist on Addiks\RDMBundle\Hydrati...drationContextInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() The type
Addiks\RDMBundle\Tests\Mapping\EntityExample was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
75 | $context->method('getEntityManager')->willReturn($this->createEntityManagerMock()); |
||||||
76 | |||||||
77 | /** @var string $expectedResult */ |
||||||
78 | $expectedResult = 'bar'; |
||||||
79 | |||||||
80 | $this->dbalColumn->method('getName')->willReturn('foo'); |
||||||
0 ignored issues
–
show
The method
method() does not exist on Doctrine\DBAL\Schema\Column .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
81 | $this->dbalColumn->method('getType')->willReturn(Type::getType('string')); |
||||||
82 | |||||||
83 | /** @var mixed $actualResult */ |
||||||
84 | $actualResult = $this->fieldMapping->resolveValue( |
||||||
85 | $context, |
||||||
86 | [ |
||||||
87 | 'foo' => $expectedResult |
||||||
88 | ] |
||||||
89 | ); |
||||||
90 | |||||||
91 | $this->assertSame($expectedResult, $actualResult); |
||||||
92 | } |
||||||
93 | |||||||
94 | /** |
||||||
95 | * @test |
||||||
96 | */ |
||||||
97 | public function shouldRevertFieldValue() |
||||||
98 | { |
||||||
99 | /** @var HydrationContextInterface $context */ |
||||||
100 | $context = $this->createMock(HydrationContextInterface::class); |
||||||
101 | $context->method('getEntityClass')->willReturn(EntityExample::class); |
||||||
102 | $context->method('getEntityManager')->willReturn($this->createEntityManagerMock()); |
||||||
103 | |||||||
104 | $this->dbalColumn->method('getName')->willReturn('foo'); |
||||||
105 | $this->dbalColumn->method('getType')->willReturn(Type::getType('string')); |
||||||
106 | |||||||
107 | $this->assertEquals( |
||||||
108 | ['foo' => "Lorem ipsum"], |
||||||
109 | $this->fieldMapping->revertValue($context, "Lorem ipsum") |
||||||
110 | ); |
||||||
111 | } |
||||||
112 | |||||||
113 | /** |
||||||
114 | * @test |
||||||
115 | */ |
||||||
116 | public function shouldAssertFieldValue() |
||||||
117 | { |
||||||
118 | /** @var HydrationContextInterface $context */ |
||||||
119 | $context = $this->createMock(HydrationContextInterface::class); |
||||||
120 | $context->method('getEntityClass')->willReturn(EntityExample::class); |
||||||
121 | $context->method('getEntityManager')->willReturn($this->createEntityManagerMock()); |
||||||
122 | |||||||
123 | $this->assertSame(null, $this->fieldMapping->assertValue( |
||||||
0 ignored issues
–
show
Are you sure the usage of
$this->fieldMapping->ass...ontext, array(), 'Foo') targeting Addiks\RDMBundle\Mapping...dMapping::assertValue() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||
124 | $context, |
||||||
125 | [], |
||||||
126 | "Foo" |
||||||
127 | )); |
||||||
128 | } |
||||||
129 | |||||||
130 | private function createEntityManagerMock(): EntityManagerInterface |
||||||
131 | { |
||||||
132 | /** @var EntityManagerInterface $entityManager */ |
||||||
133 | $entityManager = $this->createMock(EntityManagerInterface::class); |
||||||
134 | |||||||
135 | /** @var Connection $connection */ |
||||||
136 | $connection = $this->createMock(Connection::class); |
||||||
137 | |||||||
138 | $entityManager->method('getConnection')->willReturn($connection); |
||||||
0 ignored issues
–
show
The method
method() does not exist on Doctrine\ORM\EntityManagerInterface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
139 | |||||||
140 | /** @var AbstractPlatform $platform */ |
||||||
141 | $platform = $this->createMock(AbstractPlatform::class); |
||||||
142 | |||||||
143 | $connection->method('getDatabasePlatform')->willReturn($platform); |
||||||
0 ignored issues
–
show
The method
method() does not exist on Doctrine\DBAL\Connection .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
144 | |||||||
145 | return $entityManager; |
||||||
146 | } |
||||||
147 | |||||||
148 | /** |
||||||
149 | * @test |
||||||
150 | */ |
||||||
151 | public function shouldWakeUpInnerMapping() |
||||||
152 | { |
||||||
153 | /** @var ContainerInterface $container */ |
||||||
154 | $container = $this->createMock(ContainerInterface::class); |
||||||
155 | |||||||
156 | $this->assertNull($this->fieldMapping->wakeUpMapping($container)); |
||||||
0 ignored issues
–
show
Are you sure the usage of
$this->fieldMapping->wakeUpMapping($container) targeting Addiks\RDMBundle\Mapping...apping::wakeUpMapping() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||||||
157 | } |
||||||
158 | |||||||
159 | } |
||||||
160 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..