Completed
Push — master ( 613542...01b9e4 )
by Yaroslav
03:27 queued 35s
created

ImageOptimizationControllerTest::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Harentius\BlogBundle\Tests\Unit\Controller;
6
7
use Harentius\BlogBundle\Controller\ImageOptimizationController;
8
use Harentius\BlogBundle\FileManagement\Image\ImageOptimizer;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\HttpFoundation\BinaryFileResponse;
11
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
13
class ImageOptimizationControllerTest extends TestCase
14
{
15
    public function testInvoke(): void
16
    {
17
        $filePath = __FILE__;
18
        $imageOptimizer = $this->createMock(ImageOptimizer::class);
19
        $imageOptimizer
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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.

Loading history...
20
            ->method('createPreviewIfNotExists')
21
            ->willReturn($filePath)
22
        ;
23
        $imageOptimizationController = $this->createImageOptimizationController($imageOptimizer);
0 ignored issues
show
Documentation introduced by
$imageOptimizer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Harentius\BlogBun...t\Image\ImageOptimizer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
25
        $response = $imageOptimizationController('image_name');
26
        $this->assertInstanceOf(BinaryFileResponse::class, $response);
27
        $this->assertSame($filePath, $response->getFile()->getPathname());
28
    }
29
30
    public function testInvokeWithException(): void
31
    {
32
        $imageOptimizer = $this->createMock(ImageOptimizer::class);
33
        $imageOptimizationController = $this->createImageOptimizationController($imageOptimizer);
0 ignored issues
show
Documentation introduced by
$imageOptimizer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Harentius\BlogBun...t\Image\ImageOptimizer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
34
35
        $this->expectException(NotFoundHttpException::class);
36
        $imageOptimizationController('image_name');
37
    }
38
39
    private function createImageOptimizationController(ImageOptimizer $imageOptimizer): ImageOptimizationController
40
    {
41
        return new ImageOptimizationController($imageOptimizer);
42
    }
43
}
44