Skip to content

Commit

Permalink
minor #35601 [PhpUnitBridge] fix getting the vendor/ dir for tests (n…
Browse files Browse the repository at this point in the history
…icolas-grekas)

This PR was submitted for the master branch but it was merged into the 4.4 branch instead.

Discussion
----------

[PhpUnitBridge] fix getting the vendor/ dir for tests

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

341dd5d [PhpUnitBridge] fix getting the vendor/ dir for tests
  • Loading branch information
nicolas-grekas committed Feb 5, 2020
2 parents b6acfae + 341dd5d commit e2dbff5
Showing 1 changed file with 20 additions and 10 deletions.
Expand Up @@ -19,22 +19,32 @@

class DeprecationTest extends TestCase
{
public static function setUpBeforeClass(): void
private static $vendorDir;

private static function getVendorDir(): string
{
$vendorDir = self::getVendorDir();
if (null !== self::$vendorDir) {
return self::$vendorDir;
}

foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
$r = new \ReflectionClass($class);
$vendorDir = \dirname(\dirname($r->getFileName()));
if (file_exists($vendorDir.'/composer/installed.json') && @mkdir($vendorDir.'/myfakevendor/myfakepackage1', 0777, true)) {
break;
}
}
}

mkdir($vendorDir.'/myfakevendor/myfakepackage1', 0777, true);
self::$vendorDir = $vendorDir;
mkdir($vendorDir.'/myfakevendor/myfakepackage2');
touch($vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile1.php');
touch($vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php');
touch($vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php');
}

private static function getVendorDir(): string
{
$reflection = new \ReflectionClass(ClassLoader::class);

return \dirname($reflection->getFileName(), 2);
return self::$vendorDir;
}

public function testItCanDetermineTheClassWhereTheDeprecationHappened()
Expand Down Expand Up @@ -184,7 +194,7 @@ public function testGetTypeDetectsSelf(string $expectedType, string $message, st
['class' => $traceClass, 'function' => 'myMethod'],
];
$deprecation = new Deprecation($message, $trace, $file);
$this->assertEquals($expectedType, $deprecation->getType());
$this->assertSame($expectedType, $deprecation->getType());
}

public function providerGetTypeUsesRightTrace(): array
Expand Down Expand Up @@ -240,7 +250,7 @@ public function testGetTypeUsesRightTrace(string $expectedType, string $message,
$trace,
self::getVendorDir().'/myfakevendor/myfakepackage2/MyFakeFile.php'
);
$this->assertEquals($expectedType, $deprecation->getType());
$this->assertSame($expectedType, $deprecation->getType());
}

/**
Expand Down

0 comments on commit e2dbff5

Please sign in to comment.