-
-
Notifications
You must be signed in to change notification settings - Fork 247
/
IssuesTest.php
113 lines (105 loc) · 4.21 KB
/
IssuesTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace Rap2hpoutre\FastExcel\Tests;
use Illuminate\Support\Collection;
use Rap2hpoutre\FastExcel\FastExcel;
/**
* Class IssuesTest.
*/
class IssuesTest extends TestCase
{
/**
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\InvalidArgumentException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException
*/
public function testIssue11()
{
$original_collection = $this->collection()->map(function ($v) {
return array_merge($v, ['test' => ['hello', 'hi']]);
});
(new FastExcel(clone $original_collection))->export(__DIR__.'/test2.xlsx');
$this->assertNotEquals($original_collection, (new FastExcel())->import(__DIR__.'/test2.xlsx'));
$this->assertEquals($this->collection(), (new FastExcel())->import(__DIR__.'/test2.xlsx'));
unlink(__DIR__.'/test2.xlsx');
}
/**
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
*/
public function testIssue18()
{
$collection = (new FastExcel())->import(__DIR__.'/test18.csv');
$this->assertInstanceOf(Collection::class, $collection);
}
/**
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\InvalidArgumentException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException
*/
public function testIssue20()
{
chdir(__DIR__);
$path = (new FastExcel($this->collection()))->export('test2.xlsx');
$this->assertEquals(__DIR__.'/test2.xlsx', $path);
unlink($path);
}
/**
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\InvalidArgumentException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
*/
public function testIssue19()
{
chdir(__DIR__);
$path = (new FastExcel(collect([['a' => 1, 'b' => 'n', 'c' => 1.32, 'd' => []]])))->export('test2.xlsx');
$this->assertEquals(collect([['a' => '1', 'b' => 'n', 'c' => '1.32']]), (new FastExcel())->import(__DIR__.'/test2.xlsx'));
unlink($path);
}
/**
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\InvalidArgumentException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException
*/
public function testIssue26()
{
chdir(__DIR__);
foreach ([[[]], null, [null]] as $value) {
$path = (new FastExcel($value))->export('test2.xlsx');
$this->assertEquals(collect([]), (new FastExcel())->import(__DIR__.'/test2.xlsx'));
unlink($path);
}
}
/**
* @throws \Box\Spout\Common\Exception\IOException
* @throws \Box\Spout\Common\Exception\InvalidArgumentException
* @throws \Box\Spout\Common\Exception\UnsupportedTypeException
* @throws \Box\Spout\Reader\Exception\ReaderNotOpenedException
* @throws \Box\Spout\Writer\Exception\WriterNotOpenedException
*/
public function testIssue32()
{
$original_collection = collect([
[
'duration_in_months' => 1,
'expires_at' => '2018-08-06',
],
[
'duration_in_months' => null,
'expires_at' => '1970-01-01',
],
]);
(new FastExcel(clone $original_collection))->export(__DIR__.'/test2.xlsx');
$res = (new FastExcel())->import(__DIR__.'/test2.xlsx');
$this->assertEquals($original_collection[1], $res[1]);
unlink(__DIR__.'/test2.xlsx');
}
}