Skip to content

Commit

Permalink
Test change vendor dir search
Browse files Browse the repository at this point in the history
  • Loading branch information
l-vo committed May 28, 2019
1 parent 5494b45 commit 2835bcb
Showing 1 changed file with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,30 @@

namespace Symfony\Bridge\PhpUnit\Tests\DeprecationErrorHandler;

use Composer\Autoload\ClassLoader;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV5;

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

mkdir($vendorDir.'/myfakevendor/myfakepackage1', 0777, true);
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);
}

public function testItCanDetermineTheClassWhereTheDeprecationHappened()
{
$deprecation = new Deprecation('💩', $this->debugBacktrace(), __FILE__);
Expand Down Expand Up @@ -91,51 +109,53 @@ public function providerIsSelf(): array
/**
* @dataProvider providerIsSelf
*/
public function testIsSelf(bool $expectedIsSelf, string $message, string $traceClass, string $file): void
/*public function testIsSelf(bool $expectedIsSelf, string $message, string $traceClass, string $file): void
{
$trace = [
['class' => 'MyClass1', 'function' => 'myMethod'],
['class' => $traceClass, 'function' => 'myMethod'],
];
$deprecation = new Deprecation($message, $trace, $file);
$this->assertEquals($expectedIsSelf, $deprecation->isSelf());
}
}*/

public function providerIsIndirectUsesRightTrace(): array
{
$vendorDir = self::getVendorDir();

return [
[false, '', [['function' => 'myfunc1'], ['function' => 'myfunc2']]],
[
'no_file_in_stack' => [false, '', [['function' => 'myfunc1'], ['function' => 'myfunc2']]],
'files_in_stack_from_various_packages' => [
true,
'',
[
['function' => 'myfunc1', 'file' => __DIR__.'/../../../../../../vendor/composer/ClassLoader.php'],
['function' => 'myfunc2', 'file' => __DIR__.'/../../../../../../vendor/bin/simple-phpunit'],
['function' => 'myfunc1', 'file' => $vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile1.php'],
['function' => 'myfunc2', 'file' => $vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php'],
],
],
[
'serialized_stack_files_from_same_package' => [
false,
serialize([
'deprecation' => 'My deprecation message',
'class' => 'MyClass',
'method' => 'myMethod',
'files_stack' => [
__DIR__.'/../../../../../../vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php',
__DIR__.'/../../../../../../vendor/bin/simple-phpunit',
$vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile1.php',
$vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php',
],
]),
[['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV5::class, 'method' => 'mymethod']],
],
[
'serialized_stack_files_from_various_packages' => [
true,
serialize([
'deprecation' => 'My deprecation message',
'class' => 'MyClass',
'method' => 'myMethod',
'files_stack' => [
__DIR__.'/../../../../../../vendor/composer/ClassLoader.php',
__DIR__.'/../../../../../../vendor/bin/simple-phpunit',
],
$vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile1.php',
$vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php',
],
]),
[['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV5::class, 'method' => 'mymethod']],
],
Expand All @@ -145,11 +165,11 @@ public function providerIsIndirectUsesRightTrace(): array
/**
* @dataProvider providerIsIndirectUsesRightTrace
*/
public function testIsIndirectUsesRightTrace(bool $expectedIsIndirect, string $message, array $trace): void
/*public function testIsIndirectUsesRightTrace(bool $expectedIsIndirect, string $message, array $trace): void
{
$deprecation = new Deprecation($message, $trace, '');
$this->assertEquals($expectedIsIndirect, $deprecation->isIndirect());
}
}*/

/**
* This method is here to simulate the extra level from the piece of code
Expand All @@ -159,4 +179,22 @@ public function debugBacktrace(): array
{
return debug_backtrace();
}

private static function removeDir($dir): void
{
$files = glob($dir.'/*');
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
} else {
self::removeDir($file);
}
}
rmdir($dir);
}

public static function tearDownAfterClass(): void
{
self::removeDir(self::getVendorDir().'/myfakevendor');
}
}

0 comments on commit 2835bcb

Please sign in to comment.