Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: dependencies leak between files #445

Merged
merged 3 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Analyzer/FileVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ public function getClassDescriptions(): array
public function clearParsedClassDescriptions(): void
{
$this->classDescriptions = [];
$this->classDescriptionBuilder->clear();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlessandroMinoccheri this one line is basically the fix for this issue that I reported 2 years ago 🥹. In order for the tests to run on pipelines I had to run CS Fixer too. Please review

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simivar the build pipeline is fixed and phpcsfixer is pinned to a specific version so this should not produce different result based on the php version anymore. Would you mind rebasing to master and committing only the line that fix the problem you mention? Thanks! 🙇

Copy link
Contributor Author

@simivar simivar Feb 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@micheleorselli the Mr now contains only necessary bugfix changes

}

public function leaveNode(Node $node): void
Expand Down
7 changes: 7 additions & 0 deletions tests/E2E/Cli/CheckCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions tests/E2E/_fixtures/DependenciesLeak/FirstModule/Router.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\DependenciesLeak\FirstModule;

class Router
{
public static function define(): void
{
}
}
7 changes: 7 additions & 0 deletions tests/E2E/_fixtures/DependenciesLeak/FirstModule/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace App\DependenciesLeak\FirstModule;

Router::define();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace App\DependenciesLeak\SecondModule;

class SomeClass
{
}
20 changes: 20 additions & 0 deletions tests/E2E/_fixtures/configDependenciesLeak.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);

use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\NotDependsOnTheseNamespaces;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\Rules\Rule;

return static function (Config $config): void {
$dependenciesLeakClassSet = ClassSet::fromDir(__DIR__.'/DependenciesLeak');

$rule_1 = Rule::allClasses()
->that(new ResideInOneOfTheseNamespaces('App\DependenciesLeak\SecondModule'))
->should(new NotDependsOnTheseNamespaces('App\DependenciesLeak\FirstModule'))
->because('modules should be independent');

$config
->add($dependenciesLeakClassSet, ...[$rule_1]);
};