Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 204e87a

Browse files
Merge branch '4.3' into 4.4
* 4.3: Revert "bug #31730 [PhpUnitBridge] More accurate grouping (greg0ire)"
2 parents f0a6675 + 4814fd3 commit 204e87a

File tree

9 files changed

+69
-114
lines changed

9 files changed

+69
-114
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,10 @@ public function handleError($type, $msg, $file, $line, $context = [])
139139
$group = 'unsilenced';
140140
} elseif ($deprecation->isLegacy(self::$utilPrefix)) {
141141
$group = 'legacy';
142+
} elseif (!$deprecation->isSelf()) {
143+
$group = $deprecation->isIndirect() ? 'remaining indirect' : 'remaining direct';
142144
} else {
143-
$group = [
144-
Deprecation::TYPE_SELF => 'remaining self',
145-
Deprecation::TYPE_DIRECT => 'remaining direct',
146-
Deprecation::TYPE_INDIRECT => 'remaining indirect',
147-
Deprecation::TYPE_UNDETERMINED => 'other',
148-
][$deprecation->getType()];
145+
$group = 'remaining self';
149146
}
150147

151148
if ($this->getConfiguration()->shouldDisplayStackTrace($msg)) {

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php

Lines changed: 40 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@
1818
*/
1919
class Deprecation
2020
{
21-
const PATH_TYPE_VENDOR = 'path_type_vendor';
22-
const PATH_TYPE_SELF = 'path_type_internal';
23-
const PATH_TYPE_UNDETERMINED = 'path_type_undetermined';
24-
25-
const TYPE_SELF = 'type_self';
26-
const TYPE_DIRECT = 'type_direct';
27-
const TYPE_INDIRECT = 'type_indirect';
28-
const TYPE_UNDETERMINED = 'type_undetermined';
29-
3021
/**
3122
* @var array
3223
*/
@@ -48,21 +39,13 @@ class Deprecation
4839
private $originMethod;
4940

5041
/**
51-
* @var string one of the PATH_TYPE_* constants
42+
* @var bool
5243
*/
53-
private $triggeringFilePathType;
44+
private $self;
5445

5546
/** @var string[] absolute paths to vendor directories */
5647
private static $vendors;
5748

58-
/**
59-
* @var string[] absolute paths to source or tests of the project. This
60-
* excludes cache directories, because it is based on
61-
* autoloading rules and cache systems typically do not use
62-
* those.
63-
*/
64-
private static $internalPaths;
65-
6649
/**
6750
* @param string $message
6851
* @param string $file
@@ -76,7 +59,7 @@ public function __construct($message, array $trace, $file)
7659
// No-op
7760
}
7861
$line = $trace[$i];
79-
$this->trigerringFilePathType = $this->getPathType($file);
62+
$this->self = !$this->pathOriginatesFromVendor($file);
8063
if (isset($line['object']) || isset($line['class'])) {
8164
if (isset($line['class']) && 0 === strpos($line['class'], SymfonyTestsListenerFor::class)) {
8265
$parsedMsg = unserialize($this->message);
@@ -87,9 +70,8 @@ public function __construct($message, array $trace, $file)
8770
// \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
8871
// then we need to use the serialized information to determine
8972
// if the error has been triggered from vendor code.
90-
if (isset($parsedMsg['triggering_file'])) {
91-
$this->trigerringFilePathType = $this->getPathType($parsedMsg['triggering_file']);
92-
}
73+
$this->self = isset($parsedMsg['triggering_file'])
74+
&& $this->pathOriginatesFromVendor($parsedMsg['triggering_file']);
9375

9476
return;
9577
}
@@ -119,6 +101,14 @@ public function originatesFromAnObject()
119101
return isset($this->originClass);
120102
}
121103

104+
/**
105+
* @return bool
106+
*/
107+
public function isSelf()
108+
{
109+
return $this->self;
110+
}
111+
122112
/**
123113
* @return string
124114
*/
@@ -173,16 +163,10 @@ public function isLegacy($utilPrefix)
173163
* Tells whether both the calling package and the called package are vendor
174164
* packages.
175165
*
176-
* @return string
166+
* @return bool
177167
*/
178-
public function getType()
168+
public function isIndirect()
179169
{
180-
if (self::PATH_TYPE_SELF === $this->trigerringFilePathType) {
181-
return self::TYPE_SELF;
182-
}
183-
if (self::PATH_TYPE_UNDETERMINED === $this->trigerringFilePathType) {
184-
return self::TYPE_UNDETERMINED;
185-
}
186170
$erroringFile = $erroringPackage = null;
187171
foreach ($this->trace as $line) {
188172
if (\in_array($line['function'], ['require', 'require_once', 'include', 'include_once'], true)) {
@@ -195,28 +179,25 @@ public function getType()
195179
if ('-' === $file || 'Standard input code' === $file || !realpath($file)) {
196180
continue;
197181
}
198-
if (self::PATH_TYPE_SELF === $this->getPathType($file)) {
199-
return self::TYPE_DIRECT;
200-
}
201-
if (self::PATH_TYPE_UNDETERMINED === $this->getPathType($file)) {
202-
return self::TYPE_UNDETERMINED;
182+
if (!$this->pathOriginatesFromVendor($file)) {
183+
return false;
203184
}
204185
if (null !== $erroringFile && null !== $erroringPackage) {
205186
$package = $this->getPackage($file);
206187
if ('composer' !== $package && $package !== $erroringPackage) {
207-
return self::TYPE_INDIRECT;
188+
return true;
208189
}
209190
continue;
210191
}
211192
$erroringFile = $file;
212193
$erroringPackage = $this->getPackage($file);
213194
}
214195

215-
return self::TYPE_DIRECT;
196+
return false;
216197
}
217198

218199
/**
219-
* getPathType() should always be called prior to calling this method.
200+
* pathOriginatesFromVendor() should always be called prior to calling this method.
220201
*
221202
* @param string $path
222203
*
@@ -256,15 +237,6 @@ private static function getVendors()
256237
$v = \dirname(\dirname($r->getFileName()));
257238
if (file_exists($v.'/composer/installed.json')) {
258239
self::$vendors[] = $v;
259-
$loader = require $v.'/autoload.php';
260-
$paths = self::getSourcePathsFromPrefixes(array_merge($loader->getPrefixes(), $loader->getPrefixesPsr4()));
261-
}
262-
}
263-
}
264-
foreach ($paths as $path) {
265-
foreach (self::$vendors as $vendor) {
266-
if (0 !== strpos($path, $vendor)) {
267-
self::$internalPaths[] = $path;
268240
}
269241
}
270242
}
@@ -273,41 +245,24 @@ private static function getVendors()
273245
return self::$vendors;
274246
}
275247

276-
private static function getSourcePathsFromPrefixes(array $prefixesByNamespace)
277-
{
278-
foreach ($prefixesByNamespace as $prefixes) {
279-
foreach ($prefixes as $prefix) {
280-
if (false !== realpath($prefix)) {
281-
yield realpath($prefix);
282-
}
283-
}
284-
}
285-
}
286-
287248
/**
288249
* @param string $path
289250
*
290-
* @return string
251+
* @return bool
291252
*/
292-
private function getPathType($path)
253+
private function pathOriginatesFromVendor($path)
293254
{
294255
$realPath = realpath($path);
295256
if (false === $realPath && '-' !== $path && 'Standard input code' !== $path) {
296-
return self::PATH_TYPE_UNDETERMINED;
257+
return true;
297258
}
298259
foreach (self::getVendors() as $vendor) {
299260
if (0 === strpos($realPath, $vendor) && false !== strpbrk(substr($realPath, \strlen($vendor), 1), '/'.\DIRECTORY_SEPARATOR)) {
300-
return self::PATH_TYPE_VENDOR;
261+
return true;
301262
}
302263
}
303264

304-
foreach (self::$internalPaths as $internalPath) {
305-
if (0 === strpos($realPath, $internalPath)) {
306-
return self::PATH_TYPE_SELF;
307-
}
308-
}
309-
310-
return self::PATH_TYPE_UNDETERMINED;
265+
return false;
311266
}
312267

313268
/**
@@ -326,4 +281,19 @@ public function toString()
326281
"\n".str_replace(' '.getcwd().\DIRECTORY_SEPARATOR, ' ', $exception->getTraceAsString()).
327282
"\n";
328283
}
284+
285+
private function getPackageFromLine(array $line)
286+
{
287+
if (!isset($line['file'])) {
288+
return 'internal function';
289+
}
290+
if (!$this->pathOriginatesFromVendor($line['file'])) {
291+
return 'source code';
292+
}
293+
try {
294+
return $this->getPackage($line['file']);
295+
} catch (\RuntimeException $e) {
296+
return 'unknown';
297+
}
298+
}
329299
}

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/DeprecationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testItCanTellWhetherItIsInternal()
3333
}
3434

3535
$deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__);
36-
$this->assertSame(Deprecation::TYPE_SELF, $deprecation->getType());
36+
$this->assertTrue($deprecation->isSelf());
3737
}
3838

3939
public function testLegacyTestMethodIsDetectedAsSuch()
@@ -52,7 +52,7 @@ public function testItCanBeConvertedToAString()
5252
public function testItRulesOutFilesOutsideVendorsAsIndirect()
5353
{
5454
$deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__);
55-
$this->assertNotSame(Deprecation::TYPE_INDIRECT, $deprecation->getType());
55+
$this->assertFalse($deprecation->isIndirect());
5656
}
5757

5858
/**

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/default.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ Unsilenced deprecation notices (3)
7373
1x: unsilenced bar deprecation
7474
1x in FooTestCase::testNonLegacyBar
7575

76+
Remaining self deprecation notices (1)
77+
78+
1x: silenced bar deprecation
79+
1x in FooTestCase::testNonLegacyBar
80+
7681
Legacy deprecation notices (1)
7782

78-
Other deprecation notices (2)
83+
Other deprecation notices (1)
7984

8085
1x: root deprecation
8186

82-
1x: silenced bar deprecation
83-
1x in FooTestCase::testNonLegacyBar
84-
8587
I get precedence over any exit statements inside the deprecation error handler.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
<?php
22

33
require_once __DIR__.'/composer/autoload_real.php';
4-
5-
return ComposerAutoloaderInitFake::getLoader();
Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
<?php
22

3-
class ComposerLoaderFake
4-
{
5-
public function getPrefixes()
6-
{
7-
return [];
8-
}
9-
10-
public function getPrefixesPsr4()
11-
{
12-
return [];
13-
}
14-
}
15-
163
class ComposerAutoloaderInitFake
174
{
18-
public static function getLoader()
19-
{
20-
return new ComposerLoaderFake();
21-
}
225
}

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/self_on_non_vendor.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ Unsilenced deprecation notices (3)
6161
1x: unsilenced bar deprecation
6262
1x in FooTestCase::testNonLegacyBar
6363

64+
Remaining self deprecation notices (1)
65+
66+
1x: silenced bar deprecation
67+
1x in FooTestCase::testNonLegacyBar
68+
6469
Legacy deprecation notices (1)
6570

66-
Other deprecation notices (2)
71+
Other deprecation notices (1)
6772

6873
1x: root deprecation
6974

70-
1x: silenced bar deprecation
71-
1x in FooTestCase::testNonLegacyBar
72-

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/shutdown_deprecations.phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,17 @@ Unsilenced deprecation notices (3)
7373
1x: unsilenced bar deprecation
7474
1x in FooTestCase::testNonLegacyBar
7575

76+
Remaining self deprecation notices (1)
77+
78+
1x: silenced bar deprecation
79+
1x in FooTestCase::testNonLegacyBar
80+
7681
Legacy deprecation notices (1)
7782

78-
Other deprecation notices (2)
83+
Other deprecation notices (1)
7984

8085
1x: root deprecation
8186

82-
1x: silenced bar deprecation
83-
1x in FooTestCase::testNonLegacyBar
84-
8587
Shutdown-time deprecations:
8688

8789
Other deprecation notices (1)

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_non_vendor.phpt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ Unsilenced deprecation notices (3)
6161
1x: unsilenced bar deprecation
6262
1x in FooTestCase::testNonLegacyBar
6363

64-
Legacy deprecation notices (1)
65-
66-
Other deprecation notices (2)
67-
68-
1x: root deprecation
64+
Remaining self deprecation notices (1)
6965

7066
1x: silenced bar deprecation
7167
1x in FooTestCase::testNonLegacyBar
7268

69+
Legacy deprecation notices (1)
70+
71+
Other deprecation notices (1)
72+
73+
1x: root deprecation
7374

0 commit comments

Comments
 (0)