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 #388

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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);
}

protected function runCheck(
$configFilePath = null,
bool $stopOnFailure = null,
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]);
};