PHP built-in attributes
PHP built-in attributes help to declare context in your code. Attributes can be used alone or together with Annotations to help to declare context in your code.
Quick overview
The following attributes are available in integration tests:
Name | Attribute | Description |
---|---|---|
Application Isolation | Enables or disables application isolation when you run tests. When enabled, an application state after a test run will be the same as before the test run. For example, you should enable it when you want to create sessions in a test, but you don't want them to affect other tests. | |
Configuration Fixture | Sets up configuration settings for a particular test. The list of settings is stored in the core_config_data database table. Multiple configuration parameters can be set with a single command. After test execution, the settings revert to their original state. | |
Database Isolation | Enables or disables database isolation. Disabled by default, unless you are using the DataFixture() attribute, in which case it is enabled by default. All data required for a test live during transaction only. Test results won't be written to the database. | |
Data Fixture | Points to a class or a method that creates testing entities (fixtures) for test execution. These are applied during the transaction. | |
Data Fixture Before Transaction | Points to a class or a method that creates testing entities (fixtures) for test execution before the transaction begins. You must implement a rollback method for changes made here. | |
Application Area | Configures test environment in the context of specified application area. | |
Enable/Disable Cache | Enables or disables certain cache segment (or all of them) to prevent isolation problems. | |
Indexer Dimension Mode | Sets the indexer dimension mode for the test run. More information can be found in the DevBlog. | |
Register Components | Registers fixture components from the specified directory (recursively). Unregisters the components after the test is finished. |
Applying annotations
The application-specific annotations for integration tests are applied in the following order:
AppIsolation
DbIsolation
DataFixtureBeforeTransaction
DataFixture
IndexerDimensionMode
ComponentsDir
AppArea
Cache
Config
This order is necessary to meet the requirement of setting up the store-scoped configuration values for fixture stores (stores that are created by data fixtures).
PHP built-in attributes are only available with PHP8 and above.