Skip to content

Commit

Permalink
Ensure ignored paths are realpathed (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored Jan 15, 2024
1 parent 0dc482e commit aacb5f4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Config/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,10 @@ public function ignoreErrorsOnPackageAndPath(string $packageName, string $path,
throw new LogicException('PROD_DEPENDENCY_ONLY_IN_DEV errors cannot be ignored on a path');
}

$previousErrorTypes = $this->ignoredErrorsOnPackageAndPath[$packageName][$path] ?? [];
$this->ignoredErrorsOnPackageAndPath[$packageName][$path] = array_merge($previousErrorTypes, $errorTypes);
$realpath = $this->realpath($path);

$previousErrorTypes = $this->ignoredErrorsOnPackageAndPath[$packageName][$realpath] ?? [];
$this->ignoredErrorsOnPackageAndPath[$packageName][$realpath] = array_merge($previousErrorTypes, $errorTypes);
return $this;
}

Expand Down Expand Up @@ -373,7 +375,16 @@ public function getPathsToExclude(): array
*/
public function getPathsWithIgnore(): array
{
return array_keys($this->ignoredErrorsOnPath);
$paths = array_keys($this->ignoredErrorsOnPath);

foreach ($this->ignoredErrorsOnPackageAndPath as $packagePaths) {
$paths = array_merge(
$paths,
array_keys($packagePaths)
);
}

return $paths;
}

public function shouldScanComposerAutoloadPaths(): bool
Expand Down
28 changes: 28 additions & 0 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types = 1);

namespace ShipMonk\ComposerDependencyAnalyser;

use PHPUnit\Framework\TestCase;
use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;
use const DIRECTORY_SEPARATOR;

class ConfigurationTest extends TestCase
{

public function testPathsWithIgnore(): void
{
$configuration = new Configuration();
$configuration->ignoreErrorsOnPath(__DIR__ . '/app/../', [ErrorType::SHADOW_DEPENDENCY]);
$configuration->ignoreErrorsOnPackageAndPath('vendor/package', __DIR__ . '/../tests/app', [ErrorType::SHADOW_DEPENDENCY]);

self::assertEquals(
[
__DIR__,
__DIR__ . DIRECTORY_SEPARATOR . 'app',
],
$configuration->getPathsWithIgnore()
);
}

}

0 comments on commit aacb5f4

Please sign in to comment.