1 | <?php |
||
31 | class ImageProviderTest extends AbstractProviderTest |
||
32 | { |
||
33 | public function getProvider($allowedExtensions = [], $allowedMimeTypes = [], $box = false) |
||
34 | { |
||
35 | $resizer = $this->createMock(ResizerInterface::class); |
||
36 | $resizer->expects($this->any())->method('resize')->will($this->returnValue(true)); |
||
37 | if ($box) { |
||
38 | $resizer->expects($this->any())->method('getBox')->will($box); |
||
39 | } |
||
40 | |||
41 | $adapter = $this->createMock(Adapter::class); |
||
42 | |||
43 | $filesystem = $this->getMockBuilder(Filesystem::class) |
||
44 | ->setMethods(['get']) |
||
45 | ->setConstructorArgs([$adapter]) |
||
46 | ->getMock(); |
||
47 | $file = $this->getMockBuilder(File::class) |
||
48 | ->setConstructorArgs(['foo', $filesystem]) |
||
49 | ->getMock(); |
||
50 | $filesystem->expects($this->any())->method('get')->will($this->returnValue($file)); |
||
51 | |||
52 | $cdn = new Server('/uploads/media'); |
||
53 | |||
54 | $generator = new DefaultGenerator(); |
||
55 | |||
56 | $thumbnail = new FormatThumbnail('jpg'); |
||
57 | |||
58 | $size = $this->createMock(BoxInterface::class); |
||
59 | $size->expects($this->any())->method('getWidth')->will($this->returnValue(100)); |
||
60 | $size->expects($this->any())->method('getHeight')->will($this->returnValue(100)); |
||
61 | |||
62 | $image = $this->createMock(ImageInterface::class); |
||
63 | $image->expects($this->any())->method('getSize')->will($this->returnValue($size)); |
||
64 | |||
65 | $adapter = $this->createMock(ImagineInterface::class); |
||
66 | $adapter->expects($this->any())->method('open')->will($this->returnValue($image)); |
||
67 | |||
68 | $metadata = $this->createMock(MetadataBuilderInterface::class); |
||
69 | |||
70 | $provider = new ImageProvider('image', $filesystem, $cdn, $generator, $thumbnail, $allowedExtensions, $allowedMimeTypes, $adapter, $metadata); |
||
71 | $provider->setResizer($resizer); |
||
72 | |||
73 | return $provider; |
||
74 | } |
||
75 | |||
76 | public function testProvider(): void |
||
95 | |||
96 | public function testHelperProperties(): void |
||
97 | { |
||
98 | $adminBox = new Box(100, 100); |
||
99 | $mediumBox = new Box(500, 250); |
||
100 | $largeBox = new Box(1000, 500); |
||
101 | |||
102 | $provider = $this->getProvider( |
||
103 | [], |
||
104 | [], |
||
105 | $this->onConsecutiveCalls( |
||
106 | $largeBox, // first properties call |
||
107 | $mediumBox, |
||
108 | $largeBox, |
||
109 | $mediumBox, // second call |
||
110 | $mediumBox, |
||
111 | $largeBox, |
||
112 | $adminBox, // Third call |
||
113 | $largeBox, // Fourth call |
||
114 | $mediumBox, |
||
115 | $largeBox, |
||
116 | $largeBox, // Fifth call |
||
117 | $mediumBox, |
||
118 | $largeBox |
||
119 | )); |
||
120 | |||
121 | $provider->addFormat('admin', ['width' => 100]); |
||
122 | $provider->addFormat('default_medium', ['width' => 500]); |
||
123 | $provider->addFormat('default_large', ['width' => 1000]); |
||
124 | |||
125 | $media = new Media(); |
||
126 | $media->setName('test.png'); |
||
127 | $media->setProviderReference('ASDASDAS.png'); |
||
128 | $media->setId(10); |
||
129 | $media->setHeight(500); |
||
130 | $media->setWidth(1500); |
||
131 | $media->setContext('default'); |
||
132 | |||
133 | $srcSet = '/uploads/media/default/0001/01/thumb_10_default_medium.png 500w, /uploads/media/default/0001/01/thumb_10_default_large.png 1000w, /uploads/media/default/0001/01/ASDASDAS.png 1500w'; |
||
134 | |||
135 | $properties = $provider->getHelperProperties($media, 'default_large'); |
||
136 | |||
137 | $this->assertInternalType('array', $properties); |
||
138 | $this->assertSame('test.png', $properties['title']); |
||
139 | $this->assertSame(1000, $properties['width']); |
||
140 | $this->assertSame($srcSet, $properties['srcset']); |
||
141 | $this->assertSame( |
||
142 | '/uploads/media/default/0001/01/thumb_10_default_large.png', |
||
143 | $properties['src'] |
||
144 | ); |
||
145 | $this->assertSame('(max-width: 1000px) 100vw, 1000px', $properties['sizes']); |
||
146 | |||
147 | $properties = $provider->getHelperProperties($media, 'default_large', ['srcset' => ['default_medium']]); |
||
148 | $this->assertSame($srcSet, $properties['srcset']); |
||
149 | $this->assertSame( |
||
150 | '/uploads/media/default/0001/01/thumb_10_default_large.png', |
||
151 | $properties['src'] |
||
152 | ); |
||
153 | $this->assertSame('(max-width: 500px) 100vw, 500px', $properties['sizes']); |
||
154 | |||
155 | $properties = $provider->getHelperProperties($media, 'admin', [ |
||
156 | 'width' => 150, |
||
157 | ]); |
||
158 | $this->assertArrayNotHasKey('sizes', $properties); |
||
159 | $this->assertArrayNotHasKey('srcset', $properties); |
||
160 | |||
161 | $this->assertSame(150, $properties['width']); |
||
162 | |||
163 | $properties = $provider->getHelperProperties($media, 'default_large', ['picture' => ['default_medium', 'default_large'], 'class' => 'some-class']); |
||
164 | $this->assertArrayHasKey('picture', $properties); |
||
165 | $this->assertArrayNotHasKey('srcset', $properties); |
||
166 | $this->assertArrayNotHasKey('sizes', $properties); |
||
167 | $this->assertArrayHasKey('source', $properties['picture']); |
||
168 | $this->assertArrayHasKey('img', $properties['picture']); |
||
169 | $this->assertArrayHasKey('class', $properties['picture']['img']); |
||
170 | $this->assertArrayHasKey('media', $properties['picture']['source'][0]); |
||
171 | $this->assertSame('(max-width: 500px)', $properties['picture']['source'][0]['media']); |
||
172 | |||
173 | $properties = $provider->getHelperProperties($media, 'default_large', ['picture' => ['(max-width: 200px)' => 'default_medium', 'default_large'], 'class' => 'some-class']); |
||
174 | $this->assertArrayHasKey('picture', $properties); |
||
175 | $this->assertArrayNotHasKey('srcset', $properties); |
||
176 | $this->assertArrayNotHasKey('sizes', $properties); |
||
177 | $this->assertArrayHasKey('source', $properties['picture']); |
||
178 | $this->assertArrayHasKey('img', $properties['picture']); |
||
179 | $this->assertArrayHasKey('class', $properties['picture']['img']); |
||
180 | $this->assertArrayHasKey('media', $properties['picture']['source'][0]); |
||
181 | $this->assertSame('(max-width: 200px)', $properties['picture']['source'][0]['media']); |
||
182 | } |
||
183 | |||
184 | public function testThumbnail(): void |
||
204 | |||
205 | public function testEvent(): void |
||
230 | |||
231 | public function testTransformFormatNotSupported(): void |
||
243 | |||
244 | public function testMetadata(): void |
||
254 | } |
||
255 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.