|
11 | 11 |
|
12 | 12 | namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;
|
13 | 13 |
|
14 |
| -use Composer\Autoload\ClassLoader; |
15 | 14 | use PHPUnit\Framework\TestCase;
|
16 | 15 | use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
|
17 |
| -use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV5; |
18 | 16 |
|
19 | 17 | class DeprecationTest extends TestCase
|
20 | 18 | {
|
21 |
| - public static function setUpBeforeClass(): void |
22 |
| - { |
23 |
| - $vendorDir = self::getVendorDir(); |
24 |
| - |
25 |
| - mkdir($vendorDir.'/myfakevendor/myfakepackage1', 0777, true); |
26 |
| - mkdir($vendorDir.'/myfakevendor/myfakepackage2'); |
27 |
| - touch($vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile1.php'); |
28 |
| - touch($vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php'); |
29 |
| - touch($vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php'); |
30 |
| - } |
31 |
| - |
32 |
| - private static function getVendorDir(): string |
33 |
| - { |
34 |
| - $reflection = new \ReflectionClass(ClassLoader::class); |
35 |
| - return dirname($reflection->getFileName(), 2); |
36 |
| - } |
37 |
| - |
38 | 19 | public function testItCanDetermineTheClassWhereTheDeprecationHappened()
|
39 | 20 | {
|
40 | 21 | $deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__);
|
@@ -68,133 +49,12 @@ public function testItRulesOutFilesOutsideVendorsAsIndirect()
|
68 | 49 | $this->assertFalse($deprecation->isIndirect());
|
69 | 50 | }
|
70 | 51 |
|
71 |
| - public function providerIsSelf(): array |
72 |
| - { |
73 |
| - return [ |
74 |
| - [true, '', 'MyClass1', ''], |
75 |
| - [false, '', 'MyClass1', 'dummy_vendor_path'], |
76 |
| - [ |
77 |
| - true, |
78 |
| - serialize(['class' => '', 'method' => '', 'deprecation' => '', 'files_stack' => []]), |
79 |
| - SymfonyTestsListenerForV5::class, |
80 |
| - '', |
81 |
| - ], |
82 |
| - [ |
83 |
| - true, |
84 |
| - serialize([ |
85 |
| - 'class' => '', |
86 |
| - 'method' => '', |
87 |
| - 'deprecation' => '', |
88 |
| - 'triggering_file' => '', |
89 |
| - 'files_stack' => [], |
90 |
| - ]), |
91 |
| - SymfonyTestsListenerForV5::class, |
92 |
| - '', |
93 |
| - ], |
94 |
| - [ |
95 |
| - false, |
96 |
| - serialize([ |
97 |
| - 'class' => '', |
98 |
| - 'method' => '', |
99 |
| - 'deprecation' => '', |
100 |
| - 'triggering_file' => 'dummy_vendor_path', |
101 |
| - 'files_stack' => [], |
102 |
| - ]), |
103 |
| - SymfonyTestsListenerForV5::class, |
104 |
| - '', |
105 |
| - ], |
106 |
| - ]; |
107 |
| - } |
108 |
| - |
109 |
| - /** |
110 |
| - * @dataProvider providerIsSelf |
111 |
| - */ |
112 |
| - /*public function testIsSelf(bool $expectedIsSelf, string $message, string $traceClass, string $file): void |
113 |
| - { |
114 |
| - $trace = [ |
115 |
| - ['class' => 'MyClass1', 'function' => 'myMethod'], |
116 |
| - ['class' => $traceClass, 'function' => 'myMethod'], |
117 |
| - ]; |
118 |
| - $deprecation = new Deprecation($message, $trace, $file); |
119 |
| - $this->assertEquals($expectedIsSelf, $deprecation->isSelf()); |
120 |
| - }*/ |
121 |
| - |
122 |
| - public function providerIsIndirectUsesRightTrace(): array |
123 |
| - { |
124 |
| - $vendorDir = self::getVendorDir(); |
125 |
| - |
126 |
| - return [ |
127 |
| - 'no_file_in_stack' => [false, '', [['function' => 'myfunc1'], ['function' => 'myfunc2']]], |
128 |
| - 'files_in_stack_from_various_packages' => [ |
129 |
| - true, |
130 |
| - '', |
131 |
| - [ |
132 |
| - ['function' => 'myfunc1', 'file' => $vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile1.php'], |
133 |
| - ['function' => 'myfunc2', 'file' => $vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php'], |
134 |
| - ], |
135 |
| - ], |
136 |
| - 'serialized_stack_files_from_same_package' => [ |
137 |
| - false, |
138 |
| - serialize([ |
139 |
| - 'deprecation' => 'My deprecation message', |
140 |
| - 'class' => 'MyClass', |
141 |
| - 'method' => 'myMethod', |
142 |
| - 'files_stack' => [ |
143 |
| - $vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile1.php', |
144 |
| - $vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php', |
145 |
| - ], |
146 |
| - ]), |
147 |
| - [['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV5::class, 'method' => 'mymethod']], |
148 |
| - ], |
149 |
| - 'serialized_stack_files_from_various_packages' => [ |
150 |
| - true, |
151 |
| - serialize([ |
152 |
| - 'deprecation' => 'My deprecation message', |
153 |
| - 'class' => 'MyClass', |
154 |
| - 'method' => 'myMethod', |
155 |
| - 'files_stack' => [ |
156 |
| - $vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile1.php', |
157 |
| - $vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php', |
158 |
| - ], |
159 |
| - ]), |
160 |
| - [['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV5::class, 'method' => 'mymethod']], |
161 |
| - ], |
162 |
| - ]; |
163 |
| - } |
164 |
| - |
165 |
| - /** |
166 |
| - * @dataProvider providerIsIndirectUsesRightTrace |
167 |
| - */ |
168 |
| - /*public function testIsIndirectUsesRightTrace(bool $expectedIsIndirect, string $message, array $trace): void |
169 |
| - { |
170 |
| - $deprecation = new Deprecation($message, $trace, ''); |
171 |
| - $this->assertEquals($expectedIsIndirect, $deprecation->isIndirect()); |
172 |
| - }*/ |
173 |
| - |
174 | 52 | /**
|
175 | 53 | * This method is here to simulate the extra level from the piece of code
|
176 |
| - * triggering an error to the error handler. |
| 54 | + * triggering an error to the error handler |
177 | 55 | */
|
178 | 56 | public function debugBacktrace(): array
|
179 | 57 | {
|
180 | 58 | return debug_backtrace();
|
181 | 59 | }
|
182 |
| - |
183 |
| - private static function removeDir($dir): void |
184 |
| - { |
185 |
| - $files = glob($dir.'/*'); |
186 |
| - foreach ($files as $file) { |
187 |
| - if (is_file($file)) { |
188 |
| - unlink($file); |
189 |
| - } else { |
190 |
| - self::removeDir($file); |
191 |
| - } |
192 |
| - } |
193 |
| - rmdir($dir); |
194 |
| - } |
195 |
| - |
196 |
| - public static function tearDownAfterClass(): void |
197 |
| - { |
198 |
| - self::removeDir(self::getVendorDir().'/myfakevendor'); |
199 |
| - } |
200 | 60 | }
|
0 commit comments