Completed
Push — master ( d68033...a5f810 )
by Sylvain
07:36
created

ExcelExportActionTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testExportTransactionLines() 0 24 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Action;
6
7
use Application\Action\ExportTransactionLinesAction;
8
use Application\Model\TransactionLine;
9
use ApplicationTest\Traits\TestWithTransaction;
10
use PHPUnit\Framework\TestCase;
11
12
class ExcelExportActionTest extends TestCase
13
{
14
    use TestWithTransaction;
15
16
    public function testExportTransactionLines(): void
17
    {
18
        // Query to generate the Excel file
19
        $hostname = 'my-ichtus.lan';
20
        $qb = _em()->getRepository(TransactionLine::class)->createQueryBuilder('tl');
21
        $action = new ExportTransactionLinesAction($hostname);
22
        $url = $action->generate($qb->getQuery());
23
24
        $this->assertStringStartsWith('https://' . $hostname . '/export/transactionLines/', $url);
25
26
        // Try to download the Excel file
27
        $ch = curl_init();
28
        curl_setopt($ch, CURLOPT_URL, $url);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

28
        curl_setopt(/** @scrutinizer ignore-type */ $ch, CURLOPT_URL, $url);
Loading history...
29
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30
        curl_setopt($ch, CURLOPT_HEADER, true);
31
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
32
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
33
        $response = curl_exec($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

33
        $response = curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
34
        $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_getinfo() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

34
        $headerSize = curl_getinfo(/** @scrutinizer ignore-type */ $ch, CURLINFO_HEADER_SIZE);
Loading history...
35
        $header = mb_substr($response, 0, $headerSize);
36
37
        $this->assertStringContainsStringIgnoringCase('content-disposition: attachment; filename=Ichtus_compta_ecritures', $header);
38
        $this->assertStringContainsStringIgnoringCase('content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $header);
39
        $this->assertRegExp('/content\-length: [1-9][0-9]+/', $header);
40
    }
41
}
42