-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathSelfValueTransformerTest.php
103 lines (90 loc) · 2.96 KB
/
SelfValueTransformerTest.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
<?php
declare(strict_types=1);
/*
* Go! AOP framework
*
* @copyright Copyright 2018, Lisachenko Alexander <[email protected]>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*/
namespace Go\Instrument\Transformer;
use Go\Core\AspectContainer;
use Go\Core\AspectKernel;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class SelfValueTransformerTest extends TestCase
{
protected SelfValueTransformer $transformer;
protected ?StreamMetaData $metadata;
/**
* {@inheritDoc}
*/
public function setUp(): void
{
$this->transformer = new SelfValueTransformer(
$this->getKernelMock([
'cacheDir' => __DIR__,
'appDir' => dirname(__DIR__),
])
);
}
/**
* Returns a mock for kernel
*
* @return MockObject|AspectKernel
*/
protected function getKernelMock(array $options): AspectKernel
{
$mock = $this->createMock(AspectKernel::class);
$mock
->method('getOptions')
->willReturn($options);
$mock
->method('getContainer')
->willReturn($this->createMock(AspectContainer::class));
return $mock;
}
#[DataProvider("filesDataProvider")]
public function testTransformerProcessFiles(
string $sourceFileWithContent,
string $fileWithExpectedContent,
): void {
try {
$sourceFile = fopen($sourceFileWithContent, 'rb');
$sourceContent = stream_get_contents($sourceFile);
$sourceMetadata = new StreamMetaData($sourceFile, $sourceContent);
$this->transformer->transform($sourceMetadata);
$expected = file_get_contents($fileWithExpectedContent);
$this->assertSame($expected, $sourceMetadata->source);
} finally {
if (isset($sourceFile) && is_resource($sourceFile)) {
fclose($sourceFile);
}
}
}
public static function filesDataProvider(): \Generator
{
yield 'file-with-self.php' => [
__DIR__ . '/_files/file-with-self.php',
__DIR__ . '/_files/file-with-self-transformed.php'
];
yield 'file-with-self-no-namespace.php' => [
__DIR__ . '/_files/file-with-self-no-namespace.php',
__DIR__ . '/_files/file-with-self-no-namespace-transformed.php'
];
yield 'php80-file.php' => [
__DIR__ . '/_files/php80-file.php',
__DIR__ . '/_files/php80-file-transformed.php'
];
yield 'php81-file.php' => [
__DIR__ . '/_files/php81-file.php',
__DIR__ . '/_files/php81-file-transformed.php'
];
yield 'php82-file.php' => [
__DIR__ . '/_files/php82-file.php',
__DIR__ . '/_files/php82-file-transformed.php'
];
}
}