covergenius/phpunit-testlistener-vcr

将 PHPUnit 与 PHP-VCR 集成。

v4.1.0 2024-08-01 01:56 UTC

README

CI Tests License Development Version Monthly Installs

使用注解将 PHPUnit 与 PHP-VCR 集成。

PHP-VCR

使用 @vcr cassette_name 在测试中自动开启和关闭 VCR。

使用示例

use PHPUnit\Framework\TestCase;

class VCRTest extends TestCase
{
    /**
     * @vcr unittest_annotation_test
     */
    public function testInterceptsWithAnnotations()
    {
        // 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 annotations).');
    }
}

安装

  1. 使用 composer 安装
composer require --dev covergenius/phpunit-testlistener-vcr

对于 phpunit 版本 10+

  1. 将监听器添加到您的 phpunit.xml
<extensions>
    <bootstrap class="VCR\PHPUnit\TestListener\VCRTestListener" />
</extensions>

对于 phpunit 版本 9 及以下

<listeners>
    <listener class="VCR\PHPUnit\TestListener\VCRTestListener" file="vendor/covergenius/phpunit-testlistener-vcr/src/VCRTestListener.php" />
</listeners>

依赖项

PHPUnit-Testlistener-VCR 依赖于以下内容;

版本 4

  • PHP 8.1+
  • PHPUnit >=10

版本 3

  • PHP 7.1+
  • PHPUnit <10

运行测试

要运行所有测试,您需要使用 composer 获取开发依赖项

composer install
./vendor/bin/phpunit

变更日志

变更日志在 PHPUnit testlistener for PHP-VCR 发布页面 上管理。

版权

版权所有 © 2013-2018 Adrian Philipp。在 MIT 许可证的条款下发布。有关详细信息,请参阅 LICENSE。 贡献者