You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Application Isolation|`@magentoAppIsolation`|`@magentoAppIsolation enabled|disabled`|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.
17
17
Configuration Fixture|`@magentoConfigFixture`|`@magentoConfigFixture [<store_code>_store] <config_path> <config_value>`|Sets up configuration settings for a particular test. The list of settings is stored in the `core_config_data` database table. After the test execution, the settings revert to their original state.
18
18
Database Isolation|`@magentoDbIsolation`|`@magentoDbIsolation enabled|disabled`|Enables or disables database isolation. Disabled by default, unless you are using `@magentoDataFixture`, in which case it is enabled by default. All data, required for a test, live during transaction only. Any test results won't be written in a database.
19
-
Data Fixture|`@magentoDataFixture`|`@magentoDataFixture <script_filename>|<method_name>`|Points to a class or a method which creates testing entities (fixtures) for test execution. These are applied during the transaction.
19
+
Data Fixture|`@magentoDataFixture`|`@magentoDataFixture <script_filename>|<method_name>|<fully_qualified_class_name> [as:alias | with:{}]`|Points to a class or a method which creates testing entities (fixtures) for test execution. These are applied during the transaction.
20
20
Data Fixture Before Transaction|`@magentoDataFixtureBeforeTransaction`|`@magentoDataFixtureBeforeTransaction <script_filename>|<method_name>`|Points to a class or a method which creates testing entities (fixtures) for test execution before the transaction has begun. You will need to implement a rollback file for changes made here. (e.g. Fixture file my_fixture.php would also require a my_fixture_rollback.php that reverts the original fixture's changed.)
21
+
Data Fixture Data Provider|`@magentoDataFixtureDataProvider`|`@magentoDataFixtureDataProvider <callable>|{}`|Points to a Data Provider callable method or contains an inline JSON string for Parameterized Data Fixtures.
21
22
Application Area|`@magentoAppArea`|`@magentoAppArea adminhtml|frontend|global`|Configures test environment in the context of specified application area.
22
23
Enable/Disable Cache|`@magentoCache`|`@magentoCache <type>|all enabled|disabled`|Enables or disables certain cache segment or all of them to prevent isolation problems.
23
24
Indexer Dimension Mode|`@magentoIndexerDimensionMode`|`@magentoIndexerDimensionMode <indexer> <mode>`|Sets the indexer dimension mode for the test run. More information can be found in the [DevBlog](https://community.magento.com/t5/Magento-DevBlog/Indexers-parallelization-and-optimization/ba-p/104922).
@@ -30,6 +31,7 @@ The Magento-specific annotations for integration tests are applied in the follow
Data Fixture Data Provider is only applicable to Parameterized Data Fixture and is currently only available for Magento Open Source contributors. It will be released for general use with Magento Open Source 2.4.5.
8
+
9
+
Data Fixture Data Provider is any valid PHP callable or valid JSON string that returns an associative array with fixture aliases as key and their respective parameters.
10
+
11
+
Use Data Fixture Data Provider if the parameters exceeds the maximum characters limit on the line with the directive `with`.
12
+
13
+
The following example shows the case when the parameters list exceeds the maximum characters limit on the line with the directive `with`.
14
+
15
+
```php?start_inline=1
16
+
class ProductTest extends \PHPUnit\Framework\TestCase
public function getProductsCountFixtureDataProvider(): array
91
+
{
92
+
return [
93
+
[
94
+
'product1' => [
95
+
'sku' => 'simple1'
96
+
],
97
+
'product2' => [
98
+
'sku' => 'simple2'
99
+
],
100
+
'product3' => [
101
+
'sku' => 'simple3',
102
+
'status' => Status::STATUS_DISABLED,
103
+
],
104
+
]
105
+
];
106
+
}
107
+
}
108
+
```
109
+
110
+
### Test case and test method scopes
111
+
112
+
The `@magentoDataFixtureDataProvider` can be specified for a particular test or for an entire test case.
113
+
The basic rules for Data Fixture Data Provider annotation at different levels are:
114
+
115
+
-`@magentoDataFixtureDataProvider` at a test case level, applies to all fixtures in the test case.
116
+
-`@magentoDataFixtureDataProvider` for a particular test, only applies to the fixtures declared at a test method level.
117
+
118
+
### Restrictions
119
+
120
+
`@magentoDataFixtureDataProvider` does not recursively merge fixtures data, thus if the fixture alias is defined in multiple `@magentoDataFixtureDataProvider`, only the last value will be used. `@magentoDataFixtureDataProvider` will not apply to a fixture that has an inline data provider with `with` directive.
-`<script_filename>` is the filename of the PHP script.
24
24
-`<method_name>` is the name of the method declared in the current class.
25
+
-`<fully_qualified_class_name>` is the fully qualified name of a class that implements
26
+
`Magento\TestFramework\Fixture\DataFixtureInterface` or `Magento\TestFramework\Fixture\RevertibleDataFixtureInterface`.
25
27
26
28
## Principles
27
29
@@ -31,13 +33,16 @@ To set up a date fixture, use the `@magentoDataFixture` annotation.
31
33
1. Fixtures declared at a test level have a higher priority than fixtures declared at a test case level.
32
34
1. Test case fixtures are applied to each test in the test case, unless a test has its own fixtures declared.
33
35
1. Annotation declaration at a test case level does not affect tests that have their own annotation declarations.
36
+
1. Fixture alias SHOULD be camelcase.
37
+
1. Fixture data provider MUST be a valid JSON string.
34
38
35
39
## Usage
36
40
37
-
As mentioned above, there are two ways to declare fixtures:
41
+
As mentioned above, there are three ways to declare fixtures:
38
42
39
43
- as a PHP script file that is used by other tests and test cases.
40
44
- as a local method that is used by other tests in the test cases.
45
+
- as a [Class][parameterizedDataFixture] that implements `Magento\TestFramework\Fixture\DataFixtureInterface` or `Magento\TestFramework\Fixture\RevertibleDataFixtureInterface`.
41
46
42
47
### Fixture as a separate file
43
48
@@ -82,6 +87,89 @@ Test case that uses the above data fixture: [`dev/tests/integration/testsuite/Ma
82
87
83
88
[`dev/tests/integration/testsuite/Magento/Cms/Controller/PageTest.php`][] demonstrates an example of the `testCreatePageWithSameModuleName()` test method that uses data from the `cmsPageWithSystemRouteFixture()` data fixture.
84
89
90
+
### Data Fixture Data Provider
91
+
92
+
{:.bs-callout-info}
93
+
Data Fixture Data Provider is only applicable to Parameterized Data Fixture and is currently only available for Magento Open Source contributors. It will be released for general use with Magento Open Source 2.4.5.
Fixture Alias is only applicable to Parameterized Data Fixture and is currently only available for Magento Open Source contributors. It will be released for general use with Magento Open Source 2.4.5.
124
+
125
+
You can give [Parameterized Data Fixture][parameterizedDataFixture] an alias using the `as` directive. The fixture alias is used as a reference to retrieve the data returned by the fixture and also as a reference in other fixtures parameters.
126
+
127
+
#### Retrieve fixture data in the test
128
+
129
+
A test can retrieve data that was returned by a [Parameterized Data Fixture][parameterizedDataFixture] using `Magento\TestFramework\Fixture\DataFixtureStorageManager` and the fixture alias.
130
+
131
+
The following example shows how to retrieve data that was returned by the fixtures:
132
+
133
+
```php?start_inline=1
134
+
class ProductsList extends \PHPUnit\Framework\TestCase
#### Supply data to parameterized data fixture as a variable
152
+
153
+
It is possible to supply data as a variable from one fixture to another using the fixture alias in one of the following formats:
154
+
155
+
-`$fixtureAlias$` is a reference to the data that was returned by the fixture with alias `fixtureAlias`.
156
+
-`$fixtureAlias.snake_case_property_name$` is a reference to the property `snake_case_property_name` in the data that was returned by the fixture with alias `fixtureAlias`.
157
+
158
+
The following example shows how a fixture can use the data of another fixture:
159
+
160
+
```php?start_inline=1
161
+
class QuoteTest extends \PHPUnit\Framework\TestCase
0 commit comments