diff --git a/README.md b/README.md index c149789..831d626 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Use `@vcr cassette_name` on your tests to turn VCR automatically on and off. ``` php use PHPUnit\Framework\TestCase; +use VCR\PHPUnit\TestListener\Attributes\Vcr; class VCRTest extends TestCase { @@ -30,6 +31,14 @@ class VCRTest extends TestCase $result = file_get_contents('http://google.com'); $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using annotations).'); } + + #[Vcr('unittest_annotation_test')] + public function testInterceptsWithAttributes(): void + { + // Content of tests/fixtures/unittest_annotation_test: "This is a annotation test dummy". + $result = file_get_contents('http://google.com'); + $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using attributes).'); + } } ``` diff --git a/src/Attributes/Vcr.php b/src/Attributes/Vcr.php new file mode 100644 index 0000000..e763719 --- /dev/null +++ b/src/Attributes/Vcr.php @@ -0,0 +1,35 @@ +cassette = $cassette; + } + + /** + * @return non-empty-string + */ + public function cassette(): string + { + return $this->cassette; + } +} diff --git a/tests/VCRTestListenerTest.php b/tests/VCRTestListenerTest.php index 09c55bf..e297fa0 100644 --- a/tests/VCRTestListenerTest.php +++ b/tests/VCRTestListenerTest.php @@ -4,6 +4,7 @@ namespace Tests\VCR\PHPUnit\TestListener; use PHPUnit\Framework\TestCase; +use VCR\PHPUnit\TestListener\Attributes\Vcr; final class VCRTestListenerTest extends TestCase { @@ -48,6 +49,14 @@ public function testNoVcrAnnotationRunsSuccessfulAndDoesNotProduceWarnings() $this->assertTrue(true, 'just adding an assertion here'); } + #[Vcr('unittest_annotation_test')] + public function testInterceptsWithAttributes(): void + { + // Content of tests/fixtures/unittest_annotation_test: "This is a annotation test dummy". + $result = file_get_contents('http://google.com'); + $this->assertEquals('This is a annotation test dummy.', $result, 'Call was not intercepted (using attributes).'); + } + /** * @return \int[][] */