darling/php-unit-test-utilities
Composer 安装命令:
composer require darling/php-unit-test-utilities
包简介
A collection of Traits that define methods to aide in the implementation of phpunit tests.
README 文档
README
The PHPUnitTestUtilities library provides traits that define methods
to aide in the implementation of phpunit tests.
Overview
Installation
composer require darling/php-unit-test-utilities
Traits
Darling\PHPUnitTestUtilities\traits\PHPUnitConfigurationTests
This trait defines the following test methods:
/** * Test that phpunit tests run. * * If this test does not run then phpunit is not set up * correctly. * */ public function test_php_unit_tests_are_run(): void;
Note: More detailed documentation can be found in the trait itself:
tests/PHPUnitTestUtilities/traits/PHPUnitConfigurationTests.php
Darling\PHPUnitTestUtilities\traits\PHPUnitTestMessages
This trait defines the following methods to return formatted strings
that can be used to output messages from phpunit tests,for example,
when a test fails.
/** * Return a message that indicates the failure of a test. * */ protected function testFailedMessage( object $testedInstance, string $testedMethod, string $expectation ): void;
Note: More detailed documentation can be found in the trait itself:
tests/PHPUnitTestUtilities/traits/PHPUnitTestMessages.php
Darling\PHPUnitTestUtilities\traits\PHPUnitRandomValues
The PHPUnitRandomValues trait defines the following methods that
return random values of various types.
/** * Return a string composed of a random number of randomly * generated characters. * */ protected function randomChars(): string /** * Return a random float. * */ protected function randomFloat(): float /** * Return a random fully qualified class name, or object instance. * */ protected function randomClassStringOrObjectInstance(): string|object /** * Return a random object instance. * */ protected function randomObjectInstance(): object
Note: More detailed documentation can be found in the trait itself:
tests/PHPUnitTestUtilities/traits/PHPUnitRandomValues.php
Example
The following is a hypothetical example of how the traits provided by
the PHPUnitTestUtilities library can be used in a class that
implements phpunit tests.
<?php namespace Darling\PHPUnitTestUtilities\Tests; use PHPUnit\Framework\TestCase; use Darling\PHPUnitTestUtilities\traits\PHPUnitConfigurationTests; use Darling\PHPUnitTestUtilities\traits\PHPUnitTestMessages; use Darling\PHPUnitTestUtilities\traits\PHPUnitRandomValues; class ExampleTest extends TestCase { use PHPUnitConfigurationTests; use PHPUnitTestMessages; use PHPUnitRandomValues; public function testArrayIsEmpty() { $testedInstance = (object) [ 'foo' => [ $this->randomChars(), $this->randomFloat(), $this->randomClassStringOrObjectInstance(), $this->randomObjectInstance(), ] ]; $this->assertEmpty( $testedInstance->foo, $this->testFailedMessage( $testedInstance, '', 'The array assigned to the foo property must be empty' ) ); } }
The example test above would result in the following failing test
when phpunit is run:
...
There was 1 failure:
1) tests\ExampleTest::testArrayIsEmpty
The stdClass implementation fails to fulfill the following expectation:
The array assigned to the foo property must be empty.
Failed asserting that an array is empty.
...
darling/php-unit-test-utilities 适用场景与选型建议
darling/php-unit-test-utilities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.53k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 darling/php-unit-test-utilities 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 darling/php-unit-test-utilities 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 15
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-10