11
11
12
12
namespace Symfony \Bridge \PhpUnit \Tests \DeprecationErrorHandler ;
13
13
14
+ use Composer \Autoload \ClassLoader ;
14
15
use PHPUnit \Framework \TestCase ;
15
16
use Symfony \Bridge \PhpUnit \DeprecationErrorHandler \Deprecation ;
16
17
use Symfony \Bridge \PhpUnit \Legacy \SymfonyTestsListenerForV5 ;
17
18
18
19
class DeprecationTest extends TestCase
19
20
{
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
+
20
38
public function testItCanDetermineTheClassWhereTheDeprecationHappened ()
21
39
{
22
40
$ deprecation = new Deprecation ('💩 ' , $ this ->debugBacktrace (), __FILE__ );
@@ -91,51 +109,53 @@ public function providerIsSelf(): array
91
109
/**
92
110
* @dataProvider providerIsSelf
93
111
*/
94
- public function testIsSelf (bool $ expectedIsSelf , string $ message , string $ traceClass , string $ file ): void
112
+ /* public function testIsSelf(bool $expectedIsSelf, string $message, string $traceClass, string $file): void
95
113
{
96
114
$trace = [
97
115
['class' => 'MyClass1', 'function' => 'myMethod'],
98
116
['class' => $traceClass, 'function' => 'myMethod'],
99
117
];
100
118
$deprecation = new Deprecation($message, $trace, $file);
101
119
$this->assertEquals($expectedIsSelf, $deprecation->isSelf());
102
- }
120
+ }*/
103
121
104
122
public function providerIsIndirectUsesRightTrace (): array
105
123
{
124
+ $ vendorDir = self ::getVendorDir ();
125
+
106
126
return [
107
- [false , '' , [['function ' => 'myfunc1 ' ], ['function ' => 'myfunc2 ' ]]],
108
- [
127
+ ' no_file_in_stack ' => [false , '' , [['function ' => 'myfunc1 ' ], ['function ' => 'myfunc2 ' ]]],
128
+ ' files_in_stack_from_various_packages ' => [
109
129
true ,
110
130
'' ,
111
131
[
112
- ['function ' => 'myfunc1 ' , 'file ' => __DIR__ .'/../../../../../../vendor/composer/ClassLoader .php ' ],
113
- ['function ' => 'myfunc2 ' , 'file ' => __DIR__ .'/../../../../../../vendor/bin/simple-phpunit ' ],
132
+ ['function ' => 'myfunc1 ' , 'file ' => $ vendorDir .'/myfakevendor/myfakepackage1/MyFakeFile1 .php ' ],
133
+ ['function ' => 'myfunc2 ' , 'file ' => $ vendorDir .'/myfakevendor/myfakepackage2/MyFakeFile.php ' ],
114
134
],
115
135
],
116
- [
136
+ ' serialized_stack_files_from_same_package ' => [
117
137
false ,
118
138
serialize ([
119
139
'deprecation ' => 'My deprecation message ' ,
120
140
'class ' => 'MyClass ' ,
121
141
'method ' => 'myMethod ' ,
122
142
'files_stack ' => [
123
- __DIR__ .'/../../../../../../vendor/symfony/phpunit-bridge/DeprecationErrorHandler .php ' ,
124
- __DIR__ .'/../../../../../../vendor/bin/simple-phpunit ' ,
143
+ $ vendorDir .'/myfakevendor/myfakepackage1/MyFakeFile1 .php ' ,
144
+ $ vendorDir .'/myfakevendor/myfakepackage1/MyFakeFile2.php ' ,
125
145
],
126
146
]),
127
147
[['function ' => 'myfunc1 ' ], ['class ' => SymfonyTestsListenerForV5::class, 'method ' => 'mymethod ' ]],
128
148
],
129
- [
149
+ ' serialized_stack_files_from_various_packages ' => [
130
150
true ,
131
151
serialize ([
132
152
'deprecation ' => 'My deprecation message ' ,
133
153
'class ' => 'MyClass ' ,
134
154
'method ' => 'myMethod ' ,
135
155
'files_stack ' => [
136
- __DIR__ .'/../../../../../../vendor/composer/ClassLoader .php ' ,
137
- __DIR__ .'/../../../../../../vendor/bin/simple-phpunit ' ,
138
- ],
156
+ $ vendorDir .'/myfakevendor/myfakepackage1/MyFakeFile1 .php ' ,
157
+ $ vendorDir .'/myfakevendor/myfakepackage2/MyFakeFile.php ' ,
158
+ ],
139
159
]),
140
160
[['function ' => 'myfunc1 ' ], ['class ' => SymfonyTestsListenerForV5::class, 'method ' => 'mymethod ' ]],
141
161
],
@@ -145,11 +165,11 @@ public function providerIsIndirectUsesRightTrace(): array
145
165
/**
146
166
* @dataProvider providerIsIndirectUsesRightTrace
147
167
*/
148
- public function testIsIndirectUsesRightTrace (bool $ expectedIsIndirect , string $ message , array $ trace ): void
168
+ /* public function testIsIndirectUsesRightTrace(bool $expectedIsIndirect, string $message, array $trace): void
149
169
{
150
170
$deprecation = new Deprecation($message, $trace, '');
151
171
$this->assertEquals($expectedIsIndirect, $deprecation->isIndirect());
152
- }
172
+ }*/
153
173
154
174
/**
155
175
* This method is here to simulate the extra level from the piece of code
@@ -159,4 +179,22 @@ public function debugBacktrace(): array
159
179
{
160
180
return debug_backtrace ();
161
181
}
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
+ }
162
200
}
0 commit comments