Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosas committed Dec 30, 2019
1 parent 392d7f0 commit 0410d96
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 16 deletions.
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@
It provides a natural language abstraction to define your own architectural rules and test them against your software.
You can also integrate *phpat* easily into your toolchain.

Current supported relations:

* **Dependency**: *SomeClass* depends (or not) on *AnotherClass*
* **Inheritance**: *SomeClass* extends (or not) *AnotherClass*
* **Composition**: *SomeClass* implements (or not) *SomeInterface*
* **Mixin**: *SomeClass* includes (or not) *SomeTrait*

There are four groups of supported assertions: **Dependency**, **Inheritance**, **Composition** and **Mixin**.
<h2></h2>

### Installation 💽
Expand Down Expand Up @@ -69,39 +63,43 @@ This is the complete list of options:

### Test definition 📓

There are different ways to choose which classes will intervene in a rule (called Selectors) and many different possibles assertions (called RuleTypes).
Check the complete list of both here:

* [Selectors](doc/SELECTORS.md)
* [RuleTypes](doc/RULE_TYPES.md)

This could be a test with a couple of rules:
```php
<?php
use PhpAT\Rule\Rule;
use PhpAT\Selector\Selector;
use PhpAT\Test\ArchitectureTest;
use App\Domain\WeirdInterface;
use App\Domain\BlackMagicInterface;
class ExampleTest extends ArchitectureTest
{
public function testDomainDoesNotDependOnOtherLayers(): Rule
{
return $this->newRule
->classesThat(Selector::haveClassName('App\Domain\*'))
->excludingClassesThat(Selector::implementInterface(BlackMagicInterface::class))
->canOnlyDependOn()
->classesThat(Selector::havePath('Domain/*'))
->excludingClassesThat(Selector::implementInterface(WeirdInterface::class))
->mustNotDependOn()
->classesThat(Selector::havePath('Application/*'))
->andClassesThat(Selector::havePath('Infrastructure/*'))
->andClassesThat(Selector::havePath('Presentation/*'))
->excludingClassesThat(Selector::haveClassName('App\Application\Shared\Service\KnownBadApproach'))
->andClassesThat(Selector::haveClassName('App\Application\Shared\Service\KnownBadApproach'))
->build();
}
public function testAllHandlersExtendAbstractCommandHandler(): Rule
{
return $this->newRule
->classesThat(Selector::haveClassName('App\Application\*\UseCase\*Handler'))
->classesThat(Selector::havePath('Application/*/UseCase/*Handler.php'))
->excludingClassesThat(Selector::extendClass('App\Application\Shared\UseCase\DifferentHandler'))
->andExcludingClassesThat(Selector::includeTrait('App\Legacy\LegacyTrait'))
->andExcludingClassesThat(Selector::haveClassName(\App\Application\Shared\UseCase\AbstractCommandHandler::class))
->mustExtend()
->classesThat(Selector::havePath('Application/Shared/UseCase/AbstractCommandHandler.php'))
->classesThat(Selector::haveClassName('App\Application\Shared\UseCase\AbstractCommandHandler'))
->build();
}
}
Expand Down
58 changes: 58 additions & 0 deletions doc/RULE_TYPES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# RuleTypes

RuleType are the type of assertion that can be done on the selected classes.

There are four groups of RuleTypes: Dependency, Inheritance, Composition and Mixin.

## Dependency

### `mustDependOn()`
It asserts that the selected classes **depend** on the other selected classes.

### `mustNotDependOn()`
It asserts that the selected classes **does not depend** on the other selected classes.

### `mustOnlyDependOn()`
It asserts that the selected classes **depend only** on the other selected classes **and no others**.

### `canOnlyDependOn()`
It asserts that the selected classes **does not have other depencies** more the selected classes.

## Composition

### `mustImplement()`
It asserts that the selected classes **implement** the selected interfaces.

### `mustNotImplement()`
It asserts that the selected classes **does not implement** the selected interfaces.

### `mustOnlyImplement()`
It asserts that the selected classes **implement only** the selected interfaces **and no others**.

### `canOnlyImplement()`
It asserts that the selected classes **does not implement other interfaces** more than the selected ones.

## Inheritance

### `mustExtend()`
It asserts that the selected classes **extend** the selected class.

### `mustNotExtend()`
It asserts that the selected classes **does not extend** the selected classes.

### `canOnlyExtend()`
It asserts that the selected classes **does not extend other classes** more than the selected ones.

## Mixin

### `mustInclude()`
It asserts that the selected classes **include** the selected traits.

### `mustNotInclude()`
It asserts that the selected classes **does not include** the selected traits.

### `mustOnlyInclude()`
It asserts that the selected classes **include only** the selected traits **and no others**.

### `canOnlyInclude()`
It asserts that the selected classes **does not include other traits** more than the selected ones.
20 changes: 20 additions & 0 deletions doc/SELECTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Selectors

Selectors are the way to tell PHPAT which classes are going to intervene in a rule.

You can always use any amount of `*` in the middle of any selector parameter to select everything that match that expression.

### `ClassNameSelector`
With `Selector::haveClassName()` you can select classes using their Fully Qualified Class Name.

### `PathSelector`
With `Selector::havePath()` you can select classes in those PHP files.

### `ImplementSelector`
With `Selector::implementInterface()` you can select classes that implement a certain interface.

### `ExtendSelector`
With `Selector::extendClass()` you can select classes that extend a certain class.

### `IncludeSelector`
With `Selector::includeTrait()` you can select classes that include a certain trait.

0 comments on commit 0410d96

Please sign in to comment.