PHP code example of kajstrom / dependency-constraints
1. Go to this page and download the library: Download kajstrom/dependency-constraints library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kajstrom / dependency-constraints example snippets
class MyDependencyTest extends TestCase
{
/** @var DependencyConstraints */
private static $dc;
public static function setUpBeforeClass()
{
self::$dc = new DependencyConstraints("/path/to/myproject/src");
}
public function testModuleAIsNotDependentOnModuleX()
{
$moduleA = self::$dc->getModule("MyProject\\ModuleA");
$this->assertFalse(
$moduleA->dependsOnModule("MyProject\\ModuleX"),
$moduleA->describeDependenciesTo("MyProject\\ModuleX"),
);
}
}
public function testBusinessLayerDoesNotDependOnPresentationLayer()
{
$dc = new DependencyConstraints("path/to/my/src");
$business = $dc->getModule("MyProject\\Business");
$this->assertFalse(
$business->dependsOnModule("MyProject\\Presentation"),
$business->describeDependenciesTo("MyProject\\Presentation")
);
}
public function testModuleADoesNotDependUponModuleB()
{
$dc = new DependencyConstraints("path/to/my/src");
$moduleA = $dc->getModule("MyProject\\ModuleA");
$this->assertFalse(
$moduleA->dependsOnModule("MyProject\\ModuleB"),
$moduleA->describeDependenciesTo("MyProject\\ModuleB")
);
}
public function testApplicationLayerDoesNotDependOnSymfonyHttpFoundation()
{
$dc = new DependencyConstraints("path/to/my/src");
$application = $dc->getModule("MyProject\Application");
$this->assertFalse(
$application->dependsOnModule("Symfony\\HttpFoundation"),
$application->describeDependenciesTo("Symfony\\HttpFoundation")
);
}
public function testModuleDoesNotDependOnSingleton()
{
$dc = new DependencyConstraints("path/to/my/src");
$module = $dc->getModule("MyProject\\Module");
$this->assertFalse($module->hasDependencyOn("MyProject\\Utils\\SingletonThatSeemedAGoodIdeaBackThen");
}
$className = "MyProject\\Module\\Class";
$instance = new $className;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.