1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Helper; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Helper\Migrator; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class MigratorTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function testMappingOnlyContainExistingClasses() |
11
|
|
|
{ |
12
|
|
|
$migrator = new Migrator(); |
13
|
|
|
|
14
|
|
|
foreach ($migrator->getMapping() as $classname) { |
15
|
|
|
if (substr_count($classname, '\\')) { |
16
|
|
|
self::assertTrue(class_exists($classname) || interface_exists($classname), 'mapping is wrong, class does not exists in project: ' . $classname); |
17
|
|
|
} |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testReplace() |
22
|
|
|
{ |
23
|
|
|
$input = <<<'STRING' |
24
|
|
|
<?php |
25
|
|
|
|
26
|
|
|
namespace Foo; |
27
|
|
|
|
28
|
|
|
use PHPExcel; |
29
|
|
|
use PHPExcel_Worksheet; |
30
|
|
|
|
31
|
|
|
class Bar |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @param PHPExcel $workbook |
35
|
|
|
* @param PHPExcel_Worksheet $sheet |
36
|
|
|
* |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public function baz(PHPExcel $workbook, PHPExcel_Worksheet $sheet) |
40
|
|
|
{ |
41
|
|
|
PHPExcel::class; |
42
|
|
|
\PHPExcel::class; |
43
|
|
|
$PHPExcel->do(); |
44
|
|
|
$fooobjPHPExcel->do(); |
45
|
|
|
$objPHPExcel->do(); |
46
|
|
|
$this->objPHPExcel->do(); |
47
|
|
|
$this->PHPExcel->do(); |
48
|
|
|
|
49
|
|
|
return \PHPExcel_Cell::stringFromColumnIndex(9); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
STRING; |
53
|
|
|
|
54
|
|
|
$expected = <<<'STRING' |
55
|
|
|
<?php |
56
|
|
|
|
57
|
|
|
namespace Foo; |
58
|
|
|
|
59
|
|
|
use \PhpOffice\PhpSpreadsheet\Spreadsheet; |
60
|
|
|
use \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; |
61
|
|
|
|
62
|
|
|
class Bar |
63
|
|
|
{ |
64
|
|
|
/** |
65
|
|
|
* @param \PhpOffice\PhpSpreadsheet\Spreadsheet $workbook |
66
|
|
|
* @param \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function baz(\PhpOffice\PhpSpreadsheet\Spreadsheet $workbook, \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet $sheet) |
71
|
|
|
{ |
72
|
|
|
\PhpOffice\PhpSpreadsheet\Spreadsheet::class; |
73
|
|
|
\PhpOffice\PhpSpreadsheet\Spreadsheet::class; |
74
|
|
|
$PHPExcel->do(); |
75
|
|
|
$fooobjPHPExcel->do(); |
76
|
|
|
$objPHPExcel->do(); |
77
|
|
|
$this->objPHPExcel->do(); |
78
|
|
|
$this->PHPExcel->do(); |
79
|
|
|
|
80
|
|
|
return \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex(9); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
STRING; |
84
|
|
|
|
85
|
|
|
$migrator = new Migrator(); |
86
|
|
|
self::assertSame($expected, $migrator->replace($input)); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|