1
|
|
|
<?php |
2
|
|
|
namespace OnurbTest\Bundle\ExcelBundle\Factory; |
3
|
|
|
|
4
|
|
|
use Onurb\Bundle\ExcelBundle\Factory\ExcelFactory as Factory; |
5
|
|
|
use PhpOffice\PhpSpreadsheet\Helper\Html; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\IReader; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\IWriter; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class ExcelFactoryTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var Factory |
16
|
|
|
*/ |
17
|
|
|
private $factory; |
18
|
|
|
|
19
|
|
|
public function setup() |
20
|
|
|
{ |
21
|
|
|
$this->factory = new Factory(); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @covers \Onurb\Bundle\ExcelBundle\Factory\ExcelFactory |
26
|
|
|
*/ |
27
|
|
|
public function testCreate() |
28
|
|
|
{ |
29
|
|
|
$this->assertInstanceOf(Spreadsheet::class, $this->factory->createSpreadsheet()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @covers \Onurb\Bundle\ExcelBundle\Factory\ExcelFactory |
34
|
|
|
*/ |
35
|
|
|
public function testCreateReader() |
36
|
|
|
{ |
37
|
|
|
$this->assertInstanceOf(IReader::class, $this->factory->createReader()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @covers \Onurb\Bundle\ExcelBundle\Factory\ExcelFactory |
42
|
|
|
*/ |
43
|
|
|
public function testCreateWriter() |
44
|
|
|
{ |
45
|
|
|
$this->assertInstanceOf(IWriter::class, $this->factory->createWriter($this->factory->createSpreadsheet())); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @covers \Onurb\Bundle\ExcelBundle\Factory\ExcelFactory |
50
|
|
|
*/ |
51
|
|
|
public function testCreateStreamedResponse() |
52
|
|
|
{ |
53
|
|
|
$writer = $this->createMock(IWriter::class); |
54
|
|
|
$writer->expects($this->once()) |
55
|
|
|
->method('save') |
56
|
|
|
->with('php://output'); |
57
|
|
|
$this->factory->createStreamedResponse($writer)->sendContent(); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @covers \Onurb\Bundle\ExcelBundle\Factory\ExcelFactory |
62
|
|
|
*/ |
63
|
|
|
public function testCreateHelperHtml() |
64
|
|
|
{ |
65
|
|
|
$helperHtml = $this->factory->createHelperHTML(); |
66
|
|
|
|
67
|
|
|
$this->assertInstanceOf(Html::class, $helperHtml); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @covers \Onurb\Bundle\ExcelBundle\Factory\ExcelFactory |
72
|
|
|
*/ |
73
|
|
|
public function testCreateSpreadsheetWorksheetDrawing() |
74
|
|
|
{ |
75
|
|
|
$drawing = $this->factory->createSpreadsheetWorksheetDrawing(); |
76
|
|
|
|
77
|
|
|
$this->assertInstanceOf(Drawing::class, $drawing); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @expectedException \InvalidArgumentException |
83
|
|
|
* @covers \Onurb\Bundle\ExcelBundle\Factory\ExcelFactory |
84
|
|
|
*/ |
85
|
|
|
public function testCreateReaderThrowsExceptionIfTypeIsWrong() |
86
|
|
|
{ |
87
|
|
|
$this->factory->createReader('WrongType'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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: