Skip to content

Commit 7c3f1d5

Browse files
committed
Add test for case when attribute declared both on class and method
1 parent 72ef3dd commit 7c3f1d5

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ responses in the given cassette.
6161
```
6262

6363
* When declared on a test method, only requests in that methods will be intercepted and stored in the given cassette.
64-
Note that it can applied on multiple test methods with different cassettes.
64+
Note that it can be declared on multiple test methods with different cassettes.
6565

6666
```php
6767
use Angelov\PHPUnitPHPVcr\UseCassette;
@@ -82,3 +82,24 @@ Note that it can applied on multiple test methods with different cassettes.
8282
public function recorded(): void { ... }
8383
}
8484
```
85+
86+
* When declared both on the class and on a specific method, the name from the attribute declared on the method will be
87+
used for that method. In this example, the responses from the requests made in the `example()` method will be stored in
88+
`example.yml` and the ones from `recorded()` in `example_2.yml`.
89+
90+
```php
91+
use Angelov\PHPUnitPHPVcr\UseCassette;
92+
use PHPUnit\Framework\Attributes\Test;
93+
use PHPUnit\Framework\TestCase;
94+
95+
#[UseCassette("example.yml")]
96+
class ExampleTest extends TestCase
97+
{
98+
#[Test]
99+
public function example(): void { ... }
100+
101+
#[Test]
102+
#[UseCassette("example_2.yml")]
103+
public function recorded(): void { ... }
104+
}
105+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Angelov\PHPUnitPHPVcr\Tests;
6+
7+
use Angelov\PHPUnitPHPVcr\UseCassette;
8+
use PHPUnit\Framework\Attributes\Test;
9+
use PHPUnit\Framework\TestCase;
10+
11+
#[UseCassette("combined_on_class.yml")]
12+
class AttributeDeclaredBothOnClassAndMethodTest extends TestCase
13+
{
14+
#[Test]
15+
#[UseCassette("on_methods.yml")]
16+
public function it_uses_cassette_from_method_when_declared_on_both_places(): void
17+
{
18+
$content = file_get_contents("https://example.com");
19+
20+
$this->assertSame("Example body.", $content);
21+
}
22+
}

0 commit comments

Comments
 (0)