inspirum/phpunit-extension
Composer 安装命令:
composer require --dev inspirum/phpunit-extension
包简介
PHPUnit extension with additional assertions
README 文档
README
PHPUnit extension with additional assertions and other helpers.
- Support some deprecated functionality
- Easy to implement
Features
Supports deprecated assertion method withConsecutive
Before PHPUnit 10.0
use PHPUnit\Framework\TestCase; final class CalculatorTest extends TestCase { public function testMultiply(): void { $mock = $this->createMock(Calculator::class); $arguments = [[1,2,3], [4,5,6]] $responses = [6, 120] $mock->expects($this->exactly(count($arguments)))->method('multiply') ->withConsecutive(...$arguments) ->willReturnOnConsecutiveCalls(...$responses); // ... test } }
After PHPUnit 10.0
use Inspirum\PHPUnit\Extension; use PHPUnit\Framework\TestCase; final class CalculatorTest extends TestCase { use Extension; public function testMultiply(): void { $mock = $this->createMock(Calculator::class); $arguments = [[1,2,3], [4,5,6]] $responses = [6, 120] $mock->expects($this->exactly(count($arguments)))->method('multiply') ->will(self::withConsecutive($arguments, $responses)); // ... test } }
System requirements
Installation
Run composer require command
$ composer require inspirum/phpunit-extension
or add requirement to your composer.json
"inspirum/phpunit-extension": "^1.0"
Usage
Validate arguments and responses:
$mock->expects($this->exactly(2))->method('example') ->will(self::withConsecutive( arguments: [ [1, 2, 0.1], [2, 3, 0.01], ], responses: [ true, false, ], )); self::assertTrue($mock->example(1, 2, 0.1)); self::assertFalse($mock->example(2, 3, 0.01));
Optional responses:
$mock->expects($this->exactly(2))->method('example') ->will(self::withConsecutive( arguments: [ [1, 2, 0.1], [2, 3, 0.01], ], )); $mock->example(1, 2, 0.1); $mock->example(2, 3, 0.01);
Simplification for same response for each call
$mock->expects($this->exactly(2))->method('example') ->will(self::withConsecutive( arguments: [ [1, 2, 0.1], [2, 3, 0.01], ], responses: true, )); self::assertTrue($mock->example(1, 2, 0.1)); self::assertTrue($mock->example(2, 3, 0.01));
Supports throwing exceptions:
$mock->expects($this->exactly(2))->method('example') ->will(self::withConsecutive( arguments: [ [1, 2, 0.1], [2, 3, 0.01], ], responses: [ true, new RuntimeException('Custom error'), ], )); self::assertTrue($mock->example(1, 2, 0.1)); try { $mock->example(2, 3, 0.01); } catch (RuntimeException $exception) { self::assertSame('Custom error', $exception->getMessage()); }
Testing
To run unit tests, run:
$ composer test:test
To show coverage, run:
$ composer test:coverage
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email tomas.novotny@inspirum.cz instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
inspirum/phpunit-extension 适用场景与选型建议
inspirum/phpunit-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 424 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「testing」 「phpunit」 「extension」 「assertions」 「with-consecutive」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 inspirum/phpunit-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inspirum/phpunit-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 inspirum/phpunit-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HiDev plugin for PHPUnit
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
统计信息
- 总下载量: 424
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-17