diff --git a/tests/Allowed/AllowedPathTest.php b/tests/Allowed/AllowedPathTest.php index 4d46ef1..34e7202 100644 --- a/tests/Allowed/AllowedPathTest.php +++ b/tests/Allowed/AllowedPathTest.php @@ -6,6 +6,7 @@ use Generator; use PHPStan\Analyser\ScopeContext; use PHPStan\Analyser\ScopeFactory; +use PHPStan\Analyser\TypeSpecifier; use PHPStan\File\FileHelper; use PHPStan\Reflection\ReflectionProvider; use PHPStan\ShouldNotHappenException; @@ -32,10 +33,11 @@ class AllowedPathTest extends PHPStanTestCase protected function setUp(): void { - $this->allowedPath = new AllowedPath(new FilePath(new FileHelper(__DIR__))); - $this->allowedPathWithRootDir = new AllowedPath(new FilePath(new FileHelper(__DIR__), '/foo/bar')); + $fileHelper = new FileHelper(__DIR__); + $this->allowedPath = new AllowedPath(new FilePath($fileHelper)); + $this->allowedPathWithRootDir = new AllowedPath(new FilePath($fileHelper, '/foo/bar')); $this->reflectionProvider = $this->createReflectionProvider(); - $this->scopeFactory = $this->createScopeFactory($this->reflectionProvider, self::getContainer()->getService('typeSpecifier')); + $this->scopeFactory = $this->createScopeFactory($this->reflectionProvider, self::getContainer()->getByType(TypeSpecifier::class)); } diff --git a/tests/Calls/EchoCallsTest.php b/tests/Calls/EchoCallsTest.php index 3515857..2e7b804 100644 --- a/tests/Calls/EchoCallsTest.php +++ b/tests/Calls/EchoCallsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class EchoCallsTest extends RuleTestCase @@ -24,19 +17,16 @@ class EchoCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new EchoCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'function' => 'echo()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -57,4 +47,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/EmptyCallsTest.php b/tests/Calls/EmptyCallsTest.php index 7d55660..a81d868 100644 --- a/tests/Calls/EmptyCallsTest.php +++ b/tests/Calls/EmptyCallsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class EmptyCallsTest extends RuleTestCase @@ -24,19 +17,16 @@ class EmptyCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new EmptyCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'function' => 'empty()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -57,4 +47,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/EvalCallsTest.php b/tests/Calls/EvalCallsTest.php index 556c549..c1ad987 100644 --- a/tests/Calls/EvalCallsTest.php +++ b/tests/Calls/EvalCallsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class EvalCallsTest extends RuleTestCase @@ -24,19 +17,16 @@ class EvalCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new EvalCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'function' => 'eval()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -57,4 +47,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/ExitDieCallsTest.php b/tests/Calls/ExitDieCallsTest.php index 9e6df46..0bfff64 100644 --- a/tests/Calls/ExitDieCallsTest.php +++ b/tests/Calls/ExitDieCallsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class ExitDieCallsTest extends RuleTestCase @@ -24,13 +17,10 @@ class ExitDieCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new ExitDieCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'function' => [ @@ -38,8 +28,8 @@ protected function getRule(): Rule 'exit()', ], 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -72,4 +62,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/FunctionCallsAllowInFunctionsTest.php b/tests/Calls/FunctionCallsAllowInFunctionsTest.php index 87f760e..c9cf249 100644 --- a/tests/Calls/FunctionCallsAllowInFunctionsTest.php +++ b/tests/Calls/FunctionCallsAllowInFunctionsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class FunctionCallsAllowInFunctionsTest extends RuleTestCase @@ -24,13 +17,10 @@ class FunctionCallsAllowInFunctionsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), $this->createReflectionProvider(), [ [ @@ -63,4 +53,12 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/FunctionCallsAllowInMethodsTest.php b/tests/Calls/FunctionCallsAllowInMethodsTest.php index deb59ec..6946fab 100644 --- a/tests/Calls/FunctionCallsAllowInMethodsTest.php +++ b/tests/Calls/FunctionCallsAllowInMethodsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class FunctionCallsAllowInMethodsTest extends RuleTestCase @@ -24,13 +17,10 @@ class FunctionCallsAllowInMethodsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), $this->createReflectionProvider(), [ [ @@ -72,4 +62,12 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/FunctionCallsDefinedInTest.php b/tests/Calls/FunctionCallsDefinedInTest.php index 6fa55e9..96574cd 100644 --- a/tests/Calls/FunctionCallsDefinedInTest.php +++ b/tests/Calls/FunctionCallsDefinedInTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class FunctionCallsDefinedInTest extends RuleTestCase @@ -24,36 +17,33 @@ class FunctionCallsDefinedInTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__), __DIR__); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), $this->createReflectionProvider(), [ [ 'function' => '\\Foo\\Bar\\Waldo\\f*()', - 'definedIn' => '../libs/Fun*.php', + 'definedIn' => __DIR__ . '/../libs/Fun*.php', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'function' => '\\Foo\\Bar\\Waldo\\b*()', - 'definedIn' => '../libs/ThisFileDoesNotExist.php', + 'definedIn' => __DIR__ . '/../libs/ThisFileDoesNotExist.php', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'function' => '\\Foo\\Bar\\Waldo\\q*x()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -84,4 +74,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/functionCallsDefinedIn.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/FunctionCallsInMultipleNamespacesTest.php b/tests/Calls/FunctionCallsInMultipleNamespacesTest.php index 0aaf3f7..d185be1 100644 --- a/tests/Calls/FunctionCallsInMultipleNamespacesTest.php +++ b/tests/Calls/FunctionCallsInMultipleNamespacesTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class FunctionCallsInMultipleNamespacesTest extends RuleTestCase @@ -24,13 +17,10 @@ class FunctionCallsInMultipleNamespacesTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), $this->createReflectionProvider(), [ [ @@ -86,4 +76,12 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/FunctionCallsNamedParamsTest.php b/tests/Calls/FunctionCallsNamedParamsTest.php index 3afd08f..fc3aed5 100644 --- a/tests/Calls/FunctionCallsNamedParamsTest.php +++ b/tests/Calls/FunctionCallsNamedParamsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; /** @@ -27,20 +20,17 @@ class FunctionCallsNamedParamsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), $this->createReflectionProvider(), [ [ 'function' => 'Foo\Bar\Waldo\foo()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsAnywhereAnyValue' => [ [ @@ -58,8 +48,8 @@ protected function getRule(): Rule [ 'function' => 'Foo\Bar\Waldo\bar()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsAnywhereAnyValue' => [ 1, @@ -71,8 +61,8 @@ protected function getRule(): Rule [ 'function' => 'Foo\Bar\Waldo\baz()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsInAllowed' => [ 2 => 'VALUE', @@ -81,8 +71,8 @@ protected function getRule(): Rule [ 'function' => 'Foo\Bar\Waldo\waldo()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsInAllowed' => [ 'value' => 'VALUE', @@ -208,4 +198,12 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/FunctionCallsTest.php b/tests/Calls/FunctionCallsTest.php index 6c86873..d8cd7f8 100644 --- a/tests/Calls/FunctionCallsTest.php +++ b/tests/Calls/FunctionCallsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; use Waldo\Quux\Blade; @@ -25,21 +18,18 @@ class FunctionCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), $this->createReflectionProvider(), [ [ 'function' => '\var_dump()', 'message' => 'use logger instead', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'errorTip' => 'See docs', ], @@ -47,8 +37,8 @@ protected function getRule(): Rule 'function' => 'print_r()', 'message' => 'nope', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsAnywhere' => [ 2 => true, @@ -57,16 +47,16 @@ protected function getRule(): Rule [ 'function' => 'printf', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'function' => '\Foo\Bar\waldo()', 'message' => 'whoa, a namespace', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowExceptParamsInAllowed' => [ 1 => 123, @@ -78,8 +68,8 @@ protected function getRule(): Rule 'shell_b*()', ], 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], // test param overwriting @@ -89,8 +79,8 @@ protected function getRule(): Rule [ 'function' => 'exe*()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], // test disallowed param values @@ -98,8 +88,8 @@ protected function getRule(): Rule 'function' => 'hash()', 'message' => 'MD4 very bad', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowExceptParams' => [ 1 => 'md4', @@ -109,8 +99,8 @@ protected function getRule(): Rule 'function' => 'hash()', 'message' => 'SHA-1 bad soon™', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'disallowParams' => [ 1 => 'sha1', @@ -120,8 +110,8 @@ protected function getRule(): Rule 'function' => 'hash()', 'message' => 'MD5 bad', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowExceptCaseInsensitiveParams' => [ 1 => 'MD5', @@ -131,8 +121,8 @@ protected function getRule(): Rule 'function' => 'hash()', 'message' => 'SHA-1 bad SOON™', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowExceptCaseInsensitiveParams' => [ 1 => 'SHA1', @@ -141,8 +131,8 @@ protected function getRule(): Rule [ 'function' => 'setcookie()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsAnywhere' => [ 3 => 0, @@ -154,8 +144,8 @@ protected function getRule(): Rule [ 'function' => 'header()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsAnywhereAnyValue' => [ 2, @@ -167,8 +157,8 @@ protected function getRule(): Rule [ 'function' => 'htmlspecialchars()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamFlagsInAllowed' => [ [ @@ -182,8 +172,8 @@ protected function getRule(): Rule 'function' => 'array_filter()', 'message' => 'callback parameter must be given.', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsAnywhereAnyValue' => [ 2, @@ -193,8 +183,8 @@ protected function getRule(): Rule 'function' => '\Foo\Bar\Waldo\mocky()', 'message' => 'mocking Blade is not allowed.', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'disallowParams' => [ 1 => Blade::class, @@ -203,8 +193,8 @@ protected function getRule(): Rule [ 'function' => '\Foo\Bar\Waldo\config()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'disallowParams' => [ 1 => 'string-key', @@ -348,4 +338,12 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/FunctionCallsUnsupportedParamConfigTest.php b/tests/Calls/FunctionCallsUnsupportedParamConfigTest.php index ba31666..febb490 100644 --- a/tests/Calls/FunctionCallsUnsupportedParamConfigTest.php +++ b/tests/Calls/FunctionCallsUnsupportedParamConfigTest.php @@ -3,16 +3,9 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\PHPStanTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class FunctionCallsUnsupportedParamConfigTest extends PHPStanTestCase @@ -25,13 +18,10 @@ public function testUnsupportedArrayInParamConfig(): void { $this->expectException(ShouldNotHappenException::class); $this->expectExceptionMessage('{foo(),bar()}: Parameter #2 $definitelyNotScalar has an unsupported type array specified in configuration'); - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), $this->createReflectionProvider(), [ [ @@ -58,4 +48,12 @@ public function testUnsupportedArrayInParamConfig(): void ); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/MethodCallsDefinedInTest.php b/tests/Calls/MethodCallsDefinedInTest.php index a8693b2..91ad6e8 100644 --- a/tests/Calls/MethodCallsDefinedInTest.php +++ b/tests/Calls/MethodCallsDefinedInTest.php @@ -3,20 +3,11 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedMethodRuleErrors; -use Spaze\PHPStan\Rules\Disallowed\Type\TypeResolver; class MethodCallsDefinedInTest extends RuleTestCase { @@ -26,24 +17,17 @@ class MethodCallsDefinedInTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__), __DIR__ . '/..'); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new MethodCalls( - new DisallowedMethodRuleErrors( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new TypeResolver(), - $formatter - ), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedMethodRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'method' => '*', - 'definedIn' => 'libs/Bl*', + 'definedIn' => __DIR__ . '/../libs/Bl*', 'allowIn' => [ - 'src/disallowed-allow/*.php', - 'src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -70,4 +54,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/methodCallsDefinedIn.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/MethodCallsTest.php b/tests/Calls/MethodCallsTest.php index b0d82b3..87b3937 100644 --- a/tests/Calls/MethodCallsTest.php +++ b/tests/Calls/MethodCallsTest.php @@ -3,20 +3,11 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedMethodRuleErrors; -use Spaze\PHPStan\Rules\Disallowed\Type\TypeResolver; class MethodCallsTest extends RuleTestCase { @@ -26,25 +17,18 @@ class MethodCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new MethodCalls( - new DisallowedMethodRuleErrors( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new TypeResolver(), - $formatter - ), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedMethodRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'method' => 'Waldo\Quux\Blade::run*()', 'message' => "I've seen tests you people wouldn't believe", 'exclude' => 'Waldo\Quux\Blade::runway()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsInAllowed' => [ 1 => 42, @@ -56,72 +40,72 @@ protected function getRule(): Rule 'method' => 'Waldo\Quux\Blade::movie()', 'message' => 'was good', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Waldo\Quux\Blade::sequel()', 'message' => 'too', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Waldo\Quux\Blade::Trinity()', 'message' => 'holy trinity', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Inheritance\Base::x*()', 'message' => 'Base::x*() methods are dangerous', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Interfaces\BaseInterface::x*()', 'message' => 'BaseInterface::x*() methods are dangerous', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Traits\TestTrait::*', 'message' => 'all TestTrait methods are dangerous', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Traits\AnotherTestClass::zzTop()', 'message' => 'method AnotherTestClass::zzTop() is dangerous', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'PhpOption\None::getIterator()', 'message' => 'no PhpOption', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'PhpOption\Some::getIterator()', 'message' => 'no PhpOption', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], // test disallowed param values @@ -129,8 +113,8 @@ protected function getRule(): Rule 'function' => 'DateTime::format()', 'message' => 'why too kay', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowExceptParams' => [ 1 => 'y', @@ -142,7 +126,7 @@ protected function getRule(): Rule 'method' => 'Waldo\Quux\Blade::andSorcery()', 'message' => 'use magic', 'allowExceptIn' => [ - '../src/disallowed/*.php', + __DIR__ . '/../src/disallowed/*.php', ], ], ] @@ -242,4 +226,12 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/NewCallsDefinedInTest.php b/tests/Calls/NewCallsDefinedInTest.php index b221ab9..9791ce4 100644 --- a/tests/Calls/NewCallsDefinedInTest.php +++ b/tests/Calls/NewCallsDefinedInTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class NewCallsDefinedInTest extends RuleTestCase @@ -24,20 +17,17 @@ class NewCallsDefinedInTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__), __DIR__ . '/..'); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new NewCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'method' => '*', - 'definedIn' => 'libs/Bl*', + 'definedIn' => __DIR__ . '/../libs/Bl*', 'allowIn' => [ - 'src/disallowed-allow/*.php', - 'src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -60,4 +50,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/methodCallsDefinedIn.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/NewCallsTest.php b/tests/Calls/NewCallsTest.php index 2524496..5f579f0 100644 --- a/tests/Calls/NewCallsTest.php +++ b/tests/Calls/NewCallsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class NewCallsTest extends RuleTestCase @@ -24,44 +17,41 @@ class NewCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new NewCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'method' => '\Constructor\ClassWithConstructor::__construct()', 'message' => 'class ClassWithConstructor should not be created', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Constructor\ClassWithoutConstructor::__construct()', 'message' => 'class ClassWithoutConstructor should not be created', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Inheritance\Base::__construct()', 'message' => 'all your base are belong to us', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'function' => 'DateTime::__construct()', 'message' => 'no future', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowExceptCaseInsensitiveParams' => [ 1 => 'tomorrow', @@ -101,4 +91,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/methodCalls.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/PrintCallsTest.php b/tests/Calls/PrintCallsTest.php index 46b9621..6ac592e 100644 --- a/tests/Calls/PrintCallsTest.php +++ b/tests/Calls/PrintCallsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class PrintCallsTest extends RuleTestCase @@ -24,19 +17,16 @@ class PrintCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new PrintCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'function' => 'print()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -57,4 +47,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/ShellExecCallsTest.php b/tests/Calls/ShellExecCallsTest.php index c5166ec..e572998 100644 --- a/tests/Calls/ShellExecCallsTest.php +++ b/tests/Calls/ShellExecCallsTest.php @@ -3,17 +3,10 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class ShellExecCallsTest extends RuleTestCase @@ -24,19 +17,16 @@ class ShellExecCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new ShellExecCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedCallsRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'function' => 'shell_*()', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -57,4 +47,12 @@ public function testRule(): void $this->analyse([__DIR__ . '/../src/disallowed-allow/functionCalls.php'], []); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Calls/StaticCallsTest.php b/tests/Calls/StaticCallsTest.php index eb87718..cbb4dd6 100644 --- a/tests/Calls/StaticCallsTest.php +++ b/tests/Calls/StaticCallsTest.php @@ -3,20 +3,11 @@ namespace Spaze\PHPStan\Rules\Disallowed\Calls; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedMethodRuleErrors; -use Spaze\PHPStan\Rules\Disallowed\Type\TypeResolver; class StaticCallsTest extends RuleTestCase { @@ -26,24 +17,17 @@ class StaticCallsTest extends RuleTestCase */ protected function getRule(): Rule { - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); + $container = self::getContainer(); return new StaticCalls( - new DisallowedMethodRuleErrors( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new TypeResolver(), - $formatter - ), - new DisallowedCallFactory($formatter, $normalizer, $allowed), + $container->getByType(DisallowedMethodRuleErrors::class), + $container->getByType(DisallowedCallFactory::class), [ [ 'method' => 'Fiction\Pulp\Royale::withCheese()', 'message' => 'a Quarter Pounder with Cheese?', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsInAllowed' => [], ], @@ -51,8 +35,8 @@ protected function getRule(): Rule 'method' => '\Fiction\Pulp\*::withBad*()', 'message' => 'a Quarter Pounder with Cheese?', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsInAllowed' => [], ], @@ -60,8 +44,8 @@ protected function getRule(): Rule 'method' => 'Fiction\Pulp\Royale::WithoutCheese', 'message' => 'a Quarter Pounder without Cheese!', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'allowParamsInAllowed' => [ 1 => 1, @@ -78,56 +62,56 @@ protected function getRule(): Rule 'method' => 'Inheritance\Base::w*f*r()', 'message' => 'method Base::woofer() is dangerous', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Interfaces\BaseInterface::y*()', 'message' => 'method BaseInterface::y() is dangerous', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Traits\TestTrait::z()', 'message' => 'method TestTrait::z() is dangerous', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'Traits\AnotherTestClass::zz()', 'message' => 'method AnotherTestClass::zz() is dangerous', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'PhpOption\Option::*()', 'message' => 'do not use PhpOption', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'PhpOption\Some::create()', 'message' => 'do not use PhpOption', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'method' => 'PhpOption\None::*()', 'message' => 'do not use PhpOption', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] @@ -206,4 +190,12 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Configs/DangerousConfigEvalCallsTest.php b/tests/Configs/DangerousConfigEvalCallsTest.php index b768fe2..bc5ab68 100644 --- a/tests/Configs/DangerousConfigEvalCallsTest.php +++ b/tests/Configs/DangerousConfigEvalCallsTest.php @@ -3,40 +3,16 @@ namespace Spaze\PHPStan\Rules\Disallowed\Configs; -use Nette\Neon\Neon; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; -use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\Calls\EvalCalls; -use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class DangerousConfigEvalCallsTest extends RuleTestCase { - /** - * @throws ShouldNotHappenException - */ protected function getRule(): Rule { - // Load the configuration from this file - $config = Neon::decode(file_get_contents(__DIR__ . '/../../disallowed-dangerous-calls.neon')); - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); - return new EvalCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), - $config['parameters']['disallowedFunctionCalls'] - ); + return self::getContainer()->getByType(EvalCalls::class); } @@ -49,4 +25,13 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + __DIR__ . '/../../disallowed-dangerous-calls.neon', + ]; + } + } diff --git a/tests/Configs/DangerousConfigFunctionCallsTest.php b/tests/Configs/DangerousConfigFunctionCallsTest.php index c20825c..2c0cf0a 100644 --- a/tests/Configs/DangerousConfigFunctionCallsTest.php +++ b/tests/Configs/DangerousConfigFunctionCallsTest.php @@ -3,41 +3,16 @@ namespace Spaze\PHPStan\Rules\Disallowed\Configs; -use Nette\Neon\Neon; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; -use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\Calls\FunctionCalls; -use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class DangerousConfigFunctionCallsTest extends RuleTestCase { - /** - * @throws ShouldNotHappenException - */ protected function getRule(): Rule { - // Load the configuration from this file - $config = Neon::decode(file_get_contents(__DIR__ . '/../../disallowed-dangerous-calls.neon')); - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); - return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), - $this->createReflectionProvider(), - $config['parameters']['disallowedFunctionCalls'] - ); + return self::getContainer()->getByType(FunctionCalls::class); } @@ -68,4 +43,13 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + __DIR__ . '/../../disallowed-dangerous-calls.neon', + ]; + } + } diff --git a/tests/Configs/ExecutionConfigFunctionCallsTest.php b/tests/Configs/ExecutionConfigFunctionCallsTest.php index af91365..8d2005a 100644 --- a/tests/Configs/ExecutionConfigFunctionCallsTest.php +++ b/tests/Configs/ExecutionConfigFunctionCallsTest.php @@ -3,41 +3,16 @@ namespace Spaze\PHPStan\Rules\Disallowed\Configs; -use Nette\Neon\Neon; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; -use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\Calls\FunctionCalls; -use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class ExecutionConfigFunctionCallsTest extends RuleTestCase { - /** - * @throws ShouldNotHappenException - */ protected function getRule(): Rule { - // Load the configuration from this file - $config = Neon::decode(file_get_contents(__DIR__ . '/../../disallowed-execution-calls.neon')); - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); - return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), - $this->createReflectionProvider(), - $config['parameters']['disallowedFunctionCalls'] - ); + return self::getContainer()->getByType(FunctionCalls::class); } @@ -56,4 +31,13 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + __DIR__ . '/../../disallowed-execution-calls.neon', + ]; + } + } diff --git a/tests/Configs/ExecutionConfigShellExecCallsTest.php b/tests/Configs/ExecutionConfigShellExecCallsTest.php index 623a771..24cf8f8 100644 --- a/tests/Configs/ExecutionConfigShellExecCallsTest.php +++ b/tests/Configs/ExecutionConfigShellExecCallsTest.php @@ -3,40 +3,16 @@ namespace Spaze\PHPStan\Rules\Disallowed\Configs; -use Nette\Neon\Neon; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; -use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\Calls\ShellExecCalls; -use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class ExecutionConfigShellExecCallsTest extends RuleTestCase { - /** - * @throws ShouldNotHappenException - */ protected function getRule(): Rule { - // Load the configuration from this file - $config = Neon::decode(file_get_contents(__DIR__ . '/../../disallowed-execution-calls.neon')); - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); - return new ShellExecCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), - $config['parameters']['disallowedFunctionCalls'] - ); + return self::getContainer()->getByType(ShellExecCalls::class); } @@ -49,4 +25,13 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + __DIR__ . '/../../disallowed-execution-calls.neon', + ]; + } + } diff --git a/tests/Configs/InsecureConfigFunctionCallsTest.php b/tests/Configs/InsecureConfigFunctionCallsTest.php index f7e6db4..be194e8 100644 --- a/tests/Configs/InsecureConfigFunctionCallsTest.php +++ b/tests/Configs/InsecureConfigFunctionCallsTest.php @@ -3,41 +3,16 @@ namespace Spaze\PHPStan\Rules\Disallowed\Configs; -use Nette\Neon\Neon; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; -use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\Calls\FunctionCalls; -use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; class InsecureConfigFunctionCallsTest extends RuleTestCase { - /** - * @throws ShouldNotHappenException - */ protected function getRule(): Rule { - // Load the configuration from this file - $config = Neon::decode(file_get_contents(__DIR__ . '/../../disallowed-insecure-calls.neon')); - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); - return new FunctionCalls( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new DisallowedCallFactory($formatter, $normalizer, $allowed), - $this->createReflectionProvider(), - $config['parameters']['disallowedFunctionCalls'] - ); + return self::getContainer()->getByType(FunctionCalls::class); } @@ -68,4 +43,13 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + __DIR__ . '/../../disallowed-insecure-calls.neon', + ]; + } + } diff --git a/tests/Configs/InsecureConfigMethodCallsTest.php b/tests/Configs/InsecureConfigMethodCallsTest.php index 4fc4f3f..efbcc4d 100644 --- a/tests/Configs/InsecureConfigMethodCallsTest.php +++ b/tests/Configs/InsecureConfigMethodCallsTest.php @@ -3,46 +3,16 @@ namespace Spaze\PHPStan\Rules\Disallowed\Configs; -use Nette\Neon\Neon; -use PHPStan\File\FileHelper; use PHPStan\Rules\Rule; -use PHPStan\ShouldNotHappenException; use PHPStan\Testing\RuleTestCase; -use Spaze\PHPStan\Rules\Disallowed\Allowed\Allowed; -use Spaze\PHPStan\Rules\Disallowed\Allowed\AllowedPath; use Spaze\PHPStan\Rules\Disallowed\Calls\MethodCalls; -use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; -use Spaze\PHPStan\Rules\Disallowed\File\FilePath; -use Spaze\PHPStan\Rules\Disallowed\Formatter\Formatter; -use Spaze\PHPStan\Rules\Disallowed\Identifier\Identifier; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallsRuleErrors; -use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedMethodRuleErrors; -use Spaze\PHPStan\Rules\Disallowed\Type\TypeResolver; class InsecureConfigMethodCallsTest extends RuleTestCase { - /** - * @throws ShouldNotHappenException - */ protected function getRule(): Rule { - // Load the configuration from this file - $config = Neon::decode(file_get_contents(__DIR__ . '/../../disallowed-insecure-calls.neon')); - $normalizer = new Normalizer(); - $formatter = new Formatter($normalizer); - $filePath = new FilePath(new FileHelper(__DIR__)); - $allowed = new Allowed($formatter, $normalizer, new AllowedPath($filePath)); - return new MethodCalls( - new DisallowedMethodRuleErrors( - new DisallowedCallsRuleErrors($allowed, new Identifier(), $filePath, $formatter), - new TypeResolver(), - $formatter - ), - new DisallowedCallFactory($formatter, $normalizer, $allowed), - $config['parameters']['disallowedMethodCalls'] - ); + return self::getContainer()->getByType(MethodCalls::class); } @@ -57,4 +27,13 @@ public function testRule(): void ]); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + __DIR__ . '/../../disallowed-insecure-calls.neon', + ]; + } + } diff --git a/tests/DisallowedSuperglobalFactoryTest.php b/tests/DisallowedSuperglobalFactoryTest.php index e9c5f71..624990c 100644 --- a/tests/DisallowedSuperglobalFactoryTest.php +++ b/tests/DisallowedSuperglobalFactoryTest.php @@ -24,7 +24,7 @@ public function testNonSuperglobalInConfig(string $superglobal, ?string $excepti } else { $this->expectNotToPerformAssertions(); } - (new DisallowedSuperglobalFactory())->getDisallowedVariables([['superglobal' => $superglobal]]); + self::getContainer()->getByType(DisallowedSuperglobalFactory::class)->getDisallowedVariables([['superglobal' => $superglobal]]); } @@ -42,4 +42,12 @@ public static function superglobalsProvider(): Generator yield ['$foo', ShouldNotHappenException::class]; } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../extension.neon', + ]; + } + } diff --git a/tests/File/FilePathTest.php b/tests/File/FilePathTest.php index 9bca887..b06926a 100644 --- a/tests/File/FilePathTest.php +++ b/tests/File/FilePathTest.php @@ -19,8 +19,9 @@ class FilePathTest extends PHPStanTestCase protected function setUp(): void { - $this->filePath = new FilePath(new FileHelper(__DIR__)); - $this->filePathWithRootDir = new FilePath(new FileHelper(__DIR__), '/foo/bar'); + $fileHelper = new FileHelper(__DIR__); + $this->filePath = new FilePath($fileHelper); + $this->filePathWithRootDir = new FilePath($fileHelper, '/foo/bar'); } diff --git a/tests/Formatter/FormatterTest.php b/tests/Formatter/FormatterTest.php index e8753cc..f7256f1 100644 --- a/tests/Formatter/FormatterTest.php +++ b/tests/Formatter/FormatterTest.php @@ -4,7 +4,6 @@ namespace Spaze\PHPStan\Rules\Disallowed\Formatter; use PHPStan\Testing\PHPStanTestCase; -use Spaze\PHPStan\Rules\Disallowed\Normalizer\Normalizer; class FormatterTest extends PHPStanTestCase { @@ -15,7 +14,7 @@ class FormatterTest extends PHPStanTestCase protected function setUp(): void { - $this->formatter = new Formatter(new Normalizer()); + $this->formatter = self::getContainer()->getByType(Formatter::class); } @@ -28,4 +27,12 @@ public function testFormat(): void $this->assertSame('{foo,bar}', $this->formatter->formatIdentifier(['\\foo', '\\bar'])); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Identifier/IdentifierTest.php b/tests/Identifier/IdentifierTest.php index 9d66799..00b4f6a 100644 --- a/tests/Identifier/IdentifierTest.php +++ b/tests/Identifier/IdentifierTest.php @@ -15,7 +15,7 @@ class IdentifierTest extends PHPStanTestCase protected function setUp(): void { - $this->identifier = new Identifier(); + $this->identifier = self::getContainer()->getByType(Identifier::class); } @@ -70,4 +70,12 @@ public static function doesNotMatchProvider(): Generator yield ['foo\\bar', 'foo\\bar', ['n*pe', 'foo\\*']]; } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Normalizer/NormalizerTest.php b/tests/Normalizer/NormalizerTest.php index 5c64485..2bf7516 100644 --- a/tests/Normalizer/NormalizerTest.php +++ b/tests/Normalizer/NormalizerTest.php @@ -15,7 +15,7 @@ class NormalizerTest extends PHPStanTestCase protected function setUp(): void { - $this->normalizer = new Normalizer(); + $this->normalizer = self::getContainer()->getByType(Normalizer::class); } @@ -44,4 +44,12 @@ public function testNormalizeAttribute(): void $this->assertSame('foo\\bar', $this->normalizer->normalizeAttribute('#[\\foo\\bar()]')); } + + public static function getAdditionalConfigFiles(): array + { + return [ + __DIR__ . '/../../extension.neon', + ]; + } + } diff --git a/tests/Usages/ClassConstantUsagesTest.php b/tests/Usages/ClassConstantUsagesTest.php index 894dece..06a2513 100644 --- a/tests/Usages/ClassConstantUsagesTest.php +++ b/tests/Usages/ClassConstantUsagesTest.php @@ -39,8 +39,8 @@ protected function getRule(): Rule 'constant' => 'BELONG', 'message' => 'belong to us', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ @@ -48,8 +48,8 @@ protected function getRule(): Rule 'constant' => 'BELONG', 'message' => 'belong to us', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ @@ -57,8 +57,8 @@ protected function getRule(): Rule 'constant' => 'BELONG', 'message' => 'belong to us', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ @@ -69,8 +69,8 @@ protected function getRule(): Rule ], 'message' => 'not a replicant', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], // test param overwriting @@ -84,8 +84,8 @@ protected function getRule(): Rule 'constant' => 'DECKARD', 'message' => 'maybe a replicant', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ @@ -93,8 +93,8 @@ protected function getRule(): Rule 'constant' => 'NAME', 'message' => 'no PhpOption', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], ] diff --git a/tests/Usages/ConstantUsagesTest.php b/tests/Usages/ConstantUsagesTest.php index dd26d81..052f5a4 100644 --- a/tests/Usages/ConstantUsagesTest.php +++ b/tests/Usages/ConstantUsagesTest.php @@ -37,16 +37,16 @@ protected function getRule(): Rule ], 'message' => 'the cake is a lie', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'constant' => '\FILTER_FLAG_NO_PRIV_RANGE', 'message' => 'the cake is a lie', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'errorTip' => 'Use https://github.com/mlocati/ip-lib instead', ], diff --git a/tests/Usages/NamespaceUsagesTest.php b/tests/Usages/NamespaceUsagesTest.php index 62a489a..8bbfcf5 100644 --- a/tests/Usages/NamespaceUsagesTest.php +++ b/tests/Usages/NamespaceUsagesTest.php @@ -33,8 +33,8 @@ protected function getRule(): Rule 'namespace' => 'Framew*rk\Some*', 'message' => 'no framework some', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'errorTip' => 'Work more on your frames', ], @@ -45,32 +45,32 @@ protected function getRule(): Rule ], 'message' => 'no inheritance sub base', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'namespace' => 'Waldo\Quux\Blade', 'message' => 'no blade', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'class' => 'Waldo\Foo\bar', 'message' => 'no FooBar', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], [ 'namespace' => 'Traits\TestTrait', 'message' => 'no TestTrait', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], // test disallowed paths diff --git a/tests/Usages/SuperglobalUsagesTest.php b/tests/Usages/SuperglobalUsagesTest.php index fccc55c..6a93f62 100644 --- a/tests/Usages/SuperglobalUsagesTest.php +++ b/tests/Usages/SuperglobalUsagesTest.php @@ -32,8 +32,8 @@ protected function getRule(): Rule 'superglobal' => '$GLOBALS', 'message' => 'the cake is a lie', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], 'errorTip' => 'So long and thanks for all the tips', ], @@ -44,8 +44,8 @@ protected function getRule(): Rule ], 'message' => 'the cake is a lie', 'allowIn' => [ - '../src/disallowed-allow/*.php', - '../src/*-allow/*.*', + __DIR__ . '/../src/disallowed-allow/*.php', + __DIR__ . '/../src/*-allow/*.*', ], ], // test disallowed paths