PptxTest::testWrite()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 19
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Service\Exporter;
6
7
use Application\Model\Card;
8
use Application\Service\Exporter\Pptx;
9
use Application\Service\ImageResizer;
10
use ApplicationTest\Traits\TestWithTransaction;
11
use Imagine\Image\ImagineInterface;
12
use PhpOffice\PhpPresentation\PhpPresentation;
13
use PhpOffice\PhpPresentation\Reader\PowerPoint2007;
14
use ZipArchive;
15
16
class PptxTest extends AbstractWriter
17
{
18
    use TestWithTransaction;
19
20
    public function testWrite(): void
21
    {
22
        global $container;
23
24
        $imagine = $container->get(ImagineInterface::class);
25
26
        $imageResizer = $this->createMock(ImageResizer::class);
27
        $imageResizer->expects(self::atLeastOnce())
28
            ->method('resize')
29
            // Never resize anything
30
            ->willReturnCallback(fn (Card $card, int $maxHeight, bool $useWebp): string => $card->getPath());
0 ignored issues
show
Unused Code introduced by
The parameter $useWebp is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
            ->willReturnCallback(fn (Card $card, int $maxHeight, /** @scrutinizer ignore-unused */ bool $useWebp): string => $card->getPath());

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $maxHeight is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
            ->willReturnCallback(fn (Card $card, /** @scrutinizer ignore-unused */ int $maxHeight, bool $useWebp): string => $card->getPath());

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
32
        $writer = new Pptx($imageResizer, $imagine);
33
        $tempFile = tempnam('data/tmp/', 'Pptx');
34
35
        $this->export($writer, $tempFile);
36
37
        $presentation = $this->readPresentation($tempFile);
38
        self::assertSame(1, $presentation->getSlideCount());
39
    }
40
41
    private function readPresentation(string $filename): PhpPresentation
42
    {
43
        // Assert that it is a valid ZIP file to prevent PhpSpreadsheet from hanging
44
        $zip = new ZipArchive();
45
        $res = $zip->open($filename, ZipArchive::CHECKCONS);
46
        self::assertTrue($res, 'exported Excel should be a valid ZIP file');
47
        $zip->close();
48
49
        // Re-read it
50
        $reader = new PowerPoint2007();
51
        $spreadsheet = $reader->load($filename);
52
        unlink($filename);
53
54
        return $spreadsheet;
55
    }
56
}
57