-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathDelegatedMacroableTest.php
77 lines (62 loc) · 2.03 KB
/
DelegatedMacroableTest.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
<?php
namespace Maatwebsite\Excel\Tests;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\RegistersEventListeners;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\BeforeSheet;
use Maatwebsite\Excel\Sheet;
use Maatwebsite\Excel\Writer;
use PhpOffice\PhpSpreadsheet\Document\Properties;
class DelegatedMacroableTest extends TestCase
{
public function test_can_call_methods_from_delegate()
{
$export = new class implements WithEvents
{
use RegistersEventListeners, Exportable;
public static function beforeExport(BeforeExport $event)
{
// ->getProperties() will be called via __call on the ->getDelegate()
TestCase::assertInstanceOf(Properties::class, $event->writer->getProperties());
}
};
$export->download('some-file.xlsx');
}
public function test_can_use_writer_macros()
{
$called = false;
Writer::macro('test', function () use (&$called) {
$called = true;
});
$export = new class implements WithEvents
{
use RegistersEventListeners, Exportable;
public static function beforeExport(BeforeExport $event)
{
// call macro method
$event->writer->test();
}
};
$export->download('some-file.xlsx');
$this->assertTrue($called);
}
public function test_can_use_sheet_macros()
{
$called = false;
Sheet::macro('test', function () use (&$called) {
$called = true;
});
$export = new class implements WithEvents
{
use RegistersEventListeners, Exportable;
public static function beforeSheet(BeforeSheet $event)
{
// call macro method
$event->sheet->test();
}
};
$export->download('some-file.xlsx');
$this->assertTrue($called);
}
}