Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef93d28

Browse files
authored
Merge pull request magento#4807 from eduard13/patch-depends-annotation
Adding the depends annotation to Integration Tests
2 parents 5f4f3b9 + ae2f35a commit ef93d28

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed

_data/toc/testing.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pages:
1313
url: /test/integration/annotations.html
1414
children:
1515

16+
- label: '@depends'
17+
url: /test/integration/annotations/depends.html
18+
1619
- label: '@magentoAppArea'
1720
url: /test/integration/annotations/magento-app-area.html
1821

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
group: testing
3+
title: Depends Annotation
4+
---
5+
6+
The `@depends` annotation helps you to define some dependencies between methods.
7+
8+
## Format
9+
10+
```php
11+
/**
12+
* @depends methodName
13+
*/
14+
```
15+
16+
{:.bs-callout .bs-callout-warning}
17+
Please note that dependencies don't define the order in which the test methods are executed, so you still have to keep to proper order for your methods.
18+
19+
### Example 1
20+
21+
Let's check the following basic example.
22+
23+
```php
24+
/**
25+
* @return int
26+
*/
27+
public function testOne(): int
28+
{
29+
$number = 2;
30+
$this->assertEquals(2, $number);
31+
32+
return $number;
33+
}
34+
35+
/**
36+
* @depends testOne
37+
*
38+
* @param $number
39+
*/
40+
public function testNumber($number)
41+
{
42+
$this->assertEquals(2, $number);
43+
}
44+
```
45+
46+
### Example 2
47+
48+
{:.bs-callout .bs-callout-info}
49+
If using multiple dependencies, arguments are passed in the annotations' defined order.
50+
51+
```php
52+
/**
53+
* @return int
54+
*/
55+
public function testTwo(): int
56+
{
57+
$number = 2;
58+
$this->assertEquals(2, $number);
59+
60+
return $number;
61+
}
62+
63+
/**
64+
* @return int
65+
*/
66+
public function testOne(): int
67+
{
68+
$number = 1;
69+
$this->assertEquals(1, $number);
70+
71+
return $number;
72+
}
73+
74+
/**
75+
* @depends testOne
76+
* @depends testTwo
77+
*
78+
* @param $one
79+
* @param $two
80+
*/
81+
public function testNumber(int $one, int $two)
82+
{
83+
$this->assertEquals(1, $one);
84+
$this->assertEquals(2, $two);
85+
}
86+
```
87+
88+
### Example 3
89+
90+
Let's check the following practical example, where we'll be checking the customer email by customer ID.
91+
92+
```php
93+
use Magento\Customer\Api\CustomerRepositoryInterface;
94+
use Magento\Customer\Api\Data\CustomerInterface;
95+
use Magento\TestFramework\Helper\Bootstrap;
96+
...
97+
98+
/**
99+
* @magentoDataFixture Magento/Customer/_files/customer.php
100+
*/
101+
public function testLoadCustomer(): CustomerInterface
102+
{
103+
$customerId = 1;
104+
$objectManager = Bootstrap::getObjectManager();
105+
$customerRepository = $objectManager->create(CustomerRepositoryInterface::class);
106+
107+
return $customerRepository->getById($customerId);
108+
}
109+
110+
/**
111+
* @depends testLoadCustomer
112+
*
113+
* @param CustomerInterface $customer
114+
*/
115+
public function testEmail(CustomerInterface $customer)
116+
{
117+
$this->assertEquals('[email protected]', $customer->getEmail());
118+
}
119+
```
120+
121+
You can read more about PHPUnit dependency annotation [here](https://phpunit.readthedocs.io/en/8.2/annotations.html#depends){:target="_blank"}.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../v2.1/test/integration/annotations/depends.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../v2.2/test/integration/annotations/depends.md

0 commit comments

Comments
 (0)