PHP Classes

File: tests/Unit/Aggregators/DependencyAggregatorTest.php

Recommend this page to a friend!
  Classes of DeGraciaMathieu   PHP Class Dependencies Analyzer   tests/Unit/Aggregators/DependencyAggregatorTest.php   Download  
File: tests/Unit/Aggregators/DependencyAggregatorTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Class Dependencies Analyzer
Analyze the dependencies of project classes
Author: By
Last change:
Date: 1 month ago
Size: 1,736 bytes
 

Contents

Class file image Download
<?php

test
('it calculates the instability correctly', function () {

   
$dependencyAggregator = $this->oneDependencyAggregator()
        ->
withManyClassDependencies([
           
$this->oneClassDependencies()->withFqcn('A')->withDependencies(['B', 'C'])->build(),
           
$this->oneClassDependencies()->withFqcn('C')->withDependencies(['D'])->build(),
        ])
        ->
build();

   
$dependencyAggregator->calculateClassesInstability();

   
$metrics = $dependencyAggregator->toArray();

   
expect($metrics['A'])->toMatchArray([
       
'name' => 'A',
       
'instability' => 1.0,
    ]);

   
expect($metrics['C'])->toMatchArray([
       
'name' => 'C',
       
'instability' => 0.5,
    ]);
});

test('it keeps only classes by given filters', function () {

   
$dependencyAggregator = $this->oneDependencyAggregator()
        ->
withManyClassDependencies([
           
$this->oneClassDependencies()->withFqcn('App\Domain\Aggregators\DependencyAggregator')->build(),
        ])
        ->
build();

   
$dependencyAggregator->filterClasses(only: ['Domain']);

   
$dependencies = $dependencyAggregator->toArray();

   
expect($dependencies)->toHaveLength(1);
   
expect($dependencies)->toHaveKey('App\Domain\Aggregators\DependencyAggregator');
});

test('it filters classes by given exclude filters', function () {

   
$dependencyAggregator = $this->oneDependencyAggregator()
        ->
withManyClassDependencies([
           
$this->oneClassDependencies()->withFqcn('App\Application\Analyze\AnalyzeAction')->build(),
        ])
        ->
build();

   
$dependencyAggregator->filterClasses(exclude: ['Application']);

   
$dependencies = $dependencyAggregator->toArray();

   
expect($dependencies)->toHaveLength(0);
});