Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

Tests/unit/Helper/File/PdfHandlerTest.php (2 issues)

Upgrade to new PHP Analysis Engine

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 Kunstmaan\MediaBundle\Tests\Helper\File;
4
5
use Kunstmaan\MediaBundle\Entity\Media;
6
use Kunstmaan\MediaBundle\Helper\File\PdfHandler;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\Filesystem\Filesystem;
9
use Symfony\Component\HttpFoundation\File\File;
10
11
class PdfHandlerTest extends TestCase
12
{
13
    /** @var PdfHandler */
14
    protected $object;
15
16
    protected $pdfTransformer;
17
18
    /** @var string */
19
    protected $filesDir;
20
21
    /**
22
     * Sets up the fixture, for example, opens a network connection.
23
     * This method is called before a test is executed.
24
     */
25
    protected function setUp()
26
    {
27
        $this->pdfTransformer = $this->createMock('Kunstmaan\MediaBundle\Helper\Transformer\PreviewTransformerInterface');
28
        $mockMimeTypeGuesserfactory = $this->createMock('Kunstmaan\MediaBundle\Helper\MimeTypeGuesserFactoryInterface');
29
        $mockExtensionGuesserfactory = $this->createMock('Kunstmaan\MediaBundle\Helper\ExtensionGuesserFactoryInterface');
30
        $this->filesDir = realpath(__DIR__ . '/../../Files');
31
32
        $this->object = new PdfHandler(1, $mockMimeTypeGuesserfactory, $mockExtensionGuesserfactory);
0 ignored issues
show
$mockMimeTypeGuesserfactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\MediaBu...uesserFactoryInterface>.

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...
$mockExtensionGuesserfactory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\MediaBu...uesserFactoryInterface>.

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...
33
        $this->object->setPdfTransformer($this->pdfTransformer);
34
    }
35
36
    public function testGetType()
37
    {
38
        $this->assertEquals(PdfHandler::TYPE, $this->object->getType());
39
    }
40
41
    public function testCanHandlePdfFiles()
42
    {
43
        $media = new Media();
44
        $media->setContent(new File($this->filesDir . '/sample.pdf'));
45
        $media->setContentType('application/pdf');
46
47
        $this->assertTrue($this->object->canHandle($media));
48
    }
49
50
    public function testCannotHandleNonPdfFiles()
51
    {
52
        $media = new Media();
53
        $media->setContentType('image/jpg');
54
55
        $this->assertFalse($this->object->canHandle($media));
56
        $this->assertFalse($this->object->canHandle(new \stdClass()));
57
    }
58
59
    public function testSaveMedia()
60
    {
61
        $media = new Media();
62
        $this->object->saveMedia($media);
63
    }
64
65
    public function testGetImageUrl()
66
    {
67
        $this->pdfTransformer
68
            ->expects($this->any())
69
            ->method('getPreviewFilename')
70
            ->will($this->returnValue('/media.pdf.jpg'));
71
72
        $media = new Media();
73
        $media->setUrl('/path/to/media.pdf');
74
        $this->assertNull($this->object->getImageUrl($media, '/basepath'));
75
76
        $previewFilename = sys_get_temp_dir() . '/media.pdf.jpg';
77
        $fileSystem = new Filesystem();
78
        $fileSystem->touch($previewFilename);
79
        $media->setUrl('/media.pdf');
80
        $this->object->setWebPath(sys_get_temp_dir());
81
        $this->assertEquals('/media.pdf.jpg', $this->object->getImageUrl($media, ''));
82
        $fileSystem->remove($previewFilename);
83
    }
84
}
85