forked from TYPO3/class-alias-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIncludeFileTest.php
More file actions
102 lines (89 loc) · 2.97 KB
/
IncludeFileTest.php
File metadata and controls
102 lines (89 loc) · 2.97 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
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
<?php
declare(strict_types=1);
namespace TYPO3\ClassAliasLoader\Test\Unit;
/*
* This file is part of the class alias loader package.
*
* (c) Helmut Hummel <info@helhum.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Composer\Composer;
use Composer\Config as ComposerConfig;
use Composer\IO\IOInterface;
use Composer\Package\PackageInterface;
use Composer\Package\RootPackageInterface;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use TYPO3\ClassAliasLoader\IncludeFile;
final class IncludeFileTest extends TestCase
{
/**
* @var IncludeFile
*/
private $subject;
/**
* @var IOInterface|MockObject
*/
private $ioMock;
/**
* @var PackageInterface|MockObject
*/
private $packageMock;
/**
* @var Composer|MockObject
*/
private $composerMock;
private $testDir = __DIR__;
public function setUp(): void
{
$this->ioMock = $this->getMockBuilder(IOInterface::class)->getMock();
$this->packageMock = $this->getMockBuilder(RootPackageInterface::class)->getMock();
$this->composerMock = $this->getMockBuilder(Composer::class)->getMock();
$configMock = $this->getMockBuilder(ComposerConfig::class)->getMock();
$testDir = $this->testDir;
$configMock->expects($this->any())
->method('get')
->willReturnCallback(function ($key) use ($testDir) {
switch ($key) {
case 'prepend-autoloader':
return true;
case 'vendor-dir':
return $testDir;
default:
throw new \RuntimeException('Not expected to be called with ' . $key);
}
});
mkdir($testDir . '/typo3');
$this->composerMock->expects($this->any())
->method('getPackage')
->willReturn($this->packageMock);
$this->composerMock->expects($this->any())
->method('getConfig')
->willReturn($configMock);
$this->subject = new IncludeFile(
$this->ioMock,
$this->composerMock,
[
new IncludeFile\SuffixToken('asdf'),
new IncludeFile\PrependToken($configMock),
]
);
}
public function tearDown(): void
{
unlink($this->testDir . IncludeFile::INCLUDE_FILE);
rmdir(dirname($this->testDir . IncludeFile::INCLUDE_FILE));
}
#[Test]
public function includeFileCanBeWritten(): void
{
$this->subject->register();
self::assertFileExists($this->testDir . IncludeFile::INCLUDE_FILE);
$contents = file_get_contents($this->testDir . IncludeFile::INCLUDE_FILE);
self::assertIsString($contents);
self::assertStringContainsString('ClassAliasLoaderStaticInitasdf', $contents);
}
}