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 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\MediaBundle\Tests\Command; |
||
15 | |||
16 | use Gaufrette\Filesystem; |
||
17 | use PHPUnit\Framework\MockObject\MockObject; |
||
18 | use Sonata\MediaBundle\Command\RemoveThumbsCommand; |
||
19 | use Sonata\MediaBundle\Model\MediaManagerInterface; |
||
20 | use Sonata\MediaBundle\Provider\FileProvider; |
||
21 | use Sonata\MediaBundle\Provider\Pool; |
||
22 | use Sonata\MediaBundle\Tests\Entity\Media; |
||
23 | use Sonata\MediaBundle\Tests\Fixtures\FilesystemTestCase; |
||
24 | use Symfony\Component\Console\Application; |
||
25 | use Symfony\Component\Console\Tester\CommandTester; |
||
26 | use Symfony\Component\DependencyInjection\Container; |
||
27 | |||
28 | /** |
||
29 | * @author Anton Dyshkant <[email protected]> |
||
30 | * |
||
31 | * @requires function Symfony\Component\Console\Tester\CommandTester::setInputs |
||
32 | */ |
||
33 | final class RemoveThumbsCommandTest extends FilesystemTestCase |
||
34 | { |
||
35 | /** |
||
36 | * @var Container |
||
37 | */ |
||
38 | private $container; |
||
39 | |||
40 | /** |
||
41 | * @var Application |
||
42 | */ |
||
43 | private $application; |
||
44 | |||
45 | /** |
||
46 | * @var RemoveThumbsCommand |
||
47 | */ |
||
48 | private $command; |
||
49 | |||
50 | /** |
||
51 | * @var CommandTester |
||
52 | */ |
||
53 | private $tester; |
||
54 | |||
55 | /** |
||
56 | * @var Pool|MockObject |
||
57 | */ |
||
58 | private $pool; |
||
59 | |||
60 | /** |
||
61 | * @var MediaManagerInterface|MockObject |
||
62 | */ |
||
63 | private $mediaManager; |
||
64 | |||
65 | protected function setUp(): void |
||
66 | { |
||
67 | parent::setUp(); |
||
68 | |||
69 | $this->mediaManager = $this->createStub(MediaManagerInterface::class); |
||
70 | $this->pool = $this->createStub(Pool::class); |
||
71 | |||
72 | $this->command = new RemoveThumbsCommand($this->mediaManager, $this->pool); |
||
73 | |||
74 | $this->application = new Application(); |
||
75 | $this->application->add($this->command); |
||
76 | |||
77 | $this->tester = new CommandTester($this->application->find('sonata:media:remove-thumbnails')); |
||
78 | } |
||
79 | |||
80 | public function testExecuteWithoutArguments(): void |
||
81 | { |
||
82 | $this->filesystem->mkdir($this->workspace.\DIRECTORY_SEPARATOR.'foo'); |
||
83 | $this->filesystem->touch($this->workspace.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'thumb_1_foo.ext'); |
||
84 | $this->filesystem->touch($this->workspace.\DIRECTORY_SEPARATOR.'foo'.\DIRECTORY_SEPARATOR.'thumb_2_bar.ext'); |
||
85 | |||
86 | $context = [ |
||
87 | 'providers' => [], |
||
88 | 'formats' => [], |
||
89 | 'download' => [], |
||
90 | ]; |
||
91 | |||
92 | $formats = [ |
||
93 | 'small' => [], |
||
94 | ]; |
||
95 | |||
96 | $fileProvider = $this->createMock(FileProvider::class); |
||
97 | |||
98 | $fileProvider |
||
99 | ->method('getName') |
||
100 | ->willReturn('fooprovider'); |
||
101 | $fileProvider->expects($this->once()) |
||
102 | ->method('getFormats') |
||
103 | ->willReturn($formats); |
||
104 | $fileProvider->expects($this->exactly(2)) |
||
105 | ->method('removeThumbnails'); |
||
106 | $fileProvider->expects($this->exactly(2)) |
||
107 | ->method('getFilesystem') |
||
108 | ->willReturn($this->createMock(Filesystem::class)); |
||
109 | |||
110 | $this->pool->expects($this->once()) |
||
0 ignored issues
–
show
|
|||
111 | ->method('getContexts') |
||
112 | ->willReturn(['foo' => $context]); |
||
113 | $this->pool->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\MediaBundle\Provider\Pool> .
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. ![]() |
|||
114 | ->method('getProviders') |
||
115 | ->willReturn(['fooprovider' => $fileProvider]); |
||
116 | $this->pool->expects($this->once()) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\MediaBundle\Provider\Pool> .
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. ![]() |
|||
117 | ->method('getProvider') |
||
118 | ->willReturn($fileProvider); |
||
119 | |||
120 | $medias = []; |
||
121 | |||
122 | $media = new Media(); |
||
123 | $media->setId(1); |
||
124 | $media->setName('foo'); |
||
125 | $medias[] = $media; |
||
126 | |||
127 | $media = new Media(); |
||
128 | $media->setId(2); |
||
129 | $media->setName('bar'); |
||
130 | $medias[] = $media; |
||
131 | |||
132 | $findByReturnCallback = static function ( |
||
133 | array $criteria, |
||
134 | ?array $orderBy = null, |
||
135 | $limit = null, |
||
136 | $offset = null |
||
137 | ) use ($medias) { |
||
138 | if (null !== $offset && $offset > 0) { |
||
139 | return []; |
||
140 | } |
||
141 | |||
142 | return $medias; |
||
143 | }; |
||
144 | |||
145 | $this->mediaManager->expects($this->exactly(2)) |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<Sonata\MediaBundl...\MediaManagerInterface> .
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. ![]() |
|||
146 | ->method('findBy') |
||
147 | ->willReturnCallback($findByReturnCallback); |
||
148 | |||
149 | $this->tester->setInputs(['fooprovider', 'foo', 'small']); |
||
150 | |||
151 | $statusCode = $this->tester->execute(['command' => $this->command->getName()]); |
||
152 | |||
153 | $this->assertStringEndsWith('Done (total medias processed: 2).'.PHP_EOL, $this->tester->getDisplay()); |
||
154 | |||
155 | $this->assertSame(0, $statusCode); |
||
156 | } |
||
157 | } |
||
158 |
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.