diff --git a/src/Analyzer/FileVisitor.php b/src/Analyzer/FileVisitor.php index 35195586..884d9c9e 100644 --- a/src/Analyzer/FileVisitor.php +++ b/src/Analyzer/FileVisitor.php @@ -228,6 +228,7 @@ public function getClassDescriptions(): array public function clearParsedClassDescriptions(): void { $this->classDescriptions = []; + $this->classDescriptionBuilder->clear(); } public function leaveNode(Node $node): void diff --git a/tests/E2E/Cli/CheckCommandTest.php b/tests/E2E/Cli/CheckCommandTest.php index 136d44c5..20649965 100644 --- a/tests/E2E/Cli/CheckCommandTest.php +++ b/tests/E2E/Cli/CheckCommandTest.php @@ -146,6 +146,13 @@ public function test_you_can_ignore_the_default_baseline(): void $this->assertCheckHasErrors($cmdTester); } + public function test_dependencies_should_not_leak_between_files(): void + { + $cmdTester = $this->runCheck(__DIR__.'/../_fixtures/configDependenciesLeak.php'); + + $this->assertCheckHasSuccess($cmdTester); + } + public function test_baseline_line_numbers_can_be_ignored(): void { $configFilePath = __DIR__.'/../_fixtures/configIgnoreBaselineLineNumbers.php'; diff --git a/tests/E2E/_fixtures/DependenciesLeak/FirstModule/Router.php b/tests/E2E/_fixtures/DependenciesLeak/FirstModule/Router.php new file mode 100644 index 00000000..da3f8663 --- /dev/null +++ b/tests/E2E/_fixtures/DependenciesLeak/FirstModule/Router.php @@ -0,0 +1,12 @@ +that(new ResideInOneOfTheseNamespaces('App\DependenciesLeak\SecondModule')) + ->should(new NotDependsOnTheseNamespaces('App\DependenciesLeak\FirstModule')) + ->because('modules should be independent'); + + $config + ->add($dependenciesLeakClassSet, ...[$rule_1]); +};