Download the PHP package structuraphp/structura without Composer
On this page you can find all versions of the php package structuraphp/structura. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package structura
Structura
About
Structura is an architectural testing tool for PHP, designed to help developers maintain a clean and consistent code structure.
- Requirements
- Installation
- Usage
- Make test
- First run
- Assertions
- Custom assert
- With PHPUnit
Requirements
PHP version
Version PHP | Structura 0.x |
---|---|
<= 8.1 | â Unsupported |
8.2 / 8.3 / 8.4 | â Supported |
Installation
Using Composer
Usage
Configuration
Create the configuration file required for running the tests:
At the root of your project, add the namespace and directory for your architecture tests:
Make test
After creating and completing your configuration file, you can use the command to create architecture tests:
Here's a simple example of architecture testing for your DTOs:
fromDir() and fromRaw()
Start with the fromDir()
method, which takes the path of the files to be analysed.
It can take a second closure parameter
to customise the finder:
fromRaw()
method can be used to test PHP code in the form of a string:
that()
Specifies rules for targeting class analysis, optional functionality:
except()
Ignores class rules, can be used as a baseline, optional functionality:
should()
List of architecture rules, required functionality:
First run
To run the architecture tests, execute the following command:
Assertions
- đ§Ŧ Types
- toBeAbstract()
- toBeAnonymousClasses()
- toBeClasses()
- toBeEnums()
- toBeBackedEnums()
- toBeFinal()
- toBeInterfaces()
- toBeInvokable()
- toBeReadonly()
- toBeTraits()
- toBeAttribute()
- đ Dependencies
- dependsOnlyOn()
- dependsOnlyOnAttribut()
- dependsOnlyOnImplementation()
- dependsOnlyOnInheritance()
- dependsOnlyOnUseTrait()
- toNotDependsOn()
- dependsOnFunction()
- toNotDependsOnFunction()
- 𧲠Relation
- toExtend()
- toExtendsNothing()
- toImplement()
- toImplementNothing()
- toOnlyImplement()
- toUseTrait()
- toNotUseTrait()
- toOnlyUseTrait()
- toHaveAttribute()
- toHaveNoAttribute()
- toHaveOnlyAttribute()
- đ Method
- toHaveMethod()
- toHaveConstructor()
- toHaveDestructor()
- đļī¸ Naming
- toHavePrefix()
- toHaveSuffix()
- đšī¸ Other
- toUseStrictTypes()
- toUseDeclare()
- toBeInOneOfTheNamespaces()
- notToBeInOneOfTheNamespaces()
- đī¸ Operators
- and()
- or()
toBeAbstract()
toBeAnonymousClasses()
toBeClasses()
toBeEnums()
Must be a valid Unit Enum or Backed Enum.
toBeBackedEnums()
Must be a backed enumeration, if ScalarType
is not specified, int
and string
are accepted.
https://www.php.net/manual/en/language.enumerations.backed.php
toBeFinal()
toBeInterfaces()
toBeInvokable()
toBeReadonly()
toBeTraits()
toBeAttribute()
- Must be a syntax-compliant attribute,
- Must be instantiable by a class reflection,
- And uses valid flags.
dependsOnlyOn()
You can use regexes to select dependencies.
dependsOnlyOnAttribut()
If you use the rule classes toHaveAttribute(), they are included by default in the permitted dependencies.
dependsOnlyOnImplementation()
If you use the rule classes toOnlyImplement() they are included by default in the permitted dependencies.
dependsOnlyOnInheritance()
If you use the rule classes toExtend() they are included by default in the permitted dependencies.
dependsOnlyOnUseTrait()
If you use the rule classes toOnlyUseTrait() they are included by default in the permitted dependencies.
toNotDependsOn()
You can use regexes to select dependencies
dependsOnFunction()
You can use regexes to select dependencies
toNotDependsOnFunction()
Prohibit the use of function.
You can use regexes to select dependencies
toExtend()
toExtendsNothing()
toImplement()
toImplementNothing()
toOnlyImplement()
toUseTrait()
toNotUseTrait()
toOnlyUseTrait()
toHaveAttribute()
toHaveNoAttribute()
toHaveOnlyAttribute()
toHaveMethod()
toHaveConstructor()
toHaveDestructor()
toHavePrefix()
toHaveSuffix()
toUseStrictTypes()
toUseDeclare()
toBeInOneOfTheNamespaces()
Allows you to specifically target classes contained in a namespace.
Information !
Anonymous classes cannot have namespaces
You can use regexes to select namespaces.
notToBeInOneOfTheNamespaces()
Allows you to specifically target classes not contained in a namespace.
Information !
Anonymous classes cannot have namespaces
You can use regexes to select namespaces.
and()
To be valid, all the rules contained in the and()
method must meet the requirements.
or()
To be valid at least one of the rules contained in the or()
method must meet the requirements.
Custom assert
To create a custom rule, implement the StructuraPhp\StructuraContracts\ExprInterface interface:
To use a custom rule, add it using the addExpr()
method.
Use existing rules as an example.
With PHPUnit
Structura can integrate architecture testing with PHPUnit with this project:
All versions of structura with dependencies
nikic/php-parser Version ^5.4
symfony/console Version ^7.2
symfony/filesystem Version ^7.2
symfony/finder Version ^7.2