forked from ClassPreloader/ClassPreloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassPreloaderTest.php
More file actions
55 lines (49 loc) · 1.91 KB
/
Copy pathClassPreloaderTest.php
File metadata and controls
55 lines (49 loc) · 1.91 KB
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
<?php
use ClassPreloader\ClassPreloader;
use ClassPreloader\Parser\NodeTraverser;
use PhpParser\Parser;
use PhpParser\PrettyPrinter\Standard as PrettyPrinter;
class ClassPreloaderTest extends PHPUnit_Framework_TestCase
{
/**
* This tests the correct detection and stripping of strict_types declarations while preloading files.
*/
public function testStripStrictTypeDeclaration()
{
$printer = $this->getMockBuilder(PrettyPrinter::class)
->disableOriginalConstructor()
->setMethods(['prettyPrint']);
$parser = $this->getMockBuilder(Parser::class)
->disableOriginalConstructor()
->setMethods(['parse', 'getErrors']);
$traverser = $this->getMockBuilder(NodeTraverser::class)
->disableOriginalConstructor()
->setMethods(['traverseFile']);
$parserMock = $parser->getMock();
$parserMock->expects($this->once())
->method('parse')
->willReturn([]);
$traverserMock = $traverser->getMock();
$traverserMock->expects($this->once())
->method('traverseFile')
->willReturn([]);
$printerMock = $printer->getMock();
$printerMock->expects($this->once())
->method('prettyPrint')
->willReturn(
file_get_contents(__DIR__.'/stubs/StrictClassWithComments.php')
);
$classPreloader = new ClassPreloader(
$printerMock,
$parserMock,
$traverserMock
);
$code = $classPreloader->getCode(__DIR__.'/stubs/StrictClassWithComments.php');
// $code should not have 'declare(strict_types=1)' declarations.
$this->assertNotRegExp(
'/(.*?)declare\s*\(strict_types\s*=\s*1\)(.*?)/mi',
$code,
'Generated ClassPreloader output should correctly detect and strip strict_type declare statements.'
);
}
}