r83dev/test-accessible
Composer 安装命令:
composer require r83dev/test-accessible
包简介
Accessible trait to call protected methods, properties and constants in tests.
README 文档
README
A helper class for testing, especially for unit tests to access inaccessible methods or to get/inject properties.
Installation
Install via composer:
dcrr composer req --dev r83dev/test-accessible
Usage
Use the AccessibleTrait in your test:
class MyTest { use R83Dev\TestAccessible\AccessibleTrait; }
Use one of the helper function to access private or protected stuff of an instantiated object.
Methods
Call inaccessible method
$this->callInaccessibleMethod($object, 'method_name', 'argument1', 'argument2', ...);
Get inaccessible property
$this->getInaccessibleProperty($object, 'property_name');
Set inaccessible property
$this->setInaccessibleProperty($object, 'property_name', 'new_property_value');
Set multiple inaccessible properties
$this->setInaccessibleProperties($object, ['property_name' => 'new_property_value']);
Get inaccessible constant
$this->getInaccessibleConstant($object, 'CONSTANT_NAME');
PHPUnitTest Example
This is just a features demo, not useful in terms of content.
Example of a unit to be tested:
class MyUnit { protected const STATE_ON = 'on'; protected const STATE_OFF = 'off'; private string $state = self::STATE_ON; protected function setState(string $state): void { $this->state = $state; } public function getState(): string { return $this->state; } }
Example unittest:
class MyUnitTest extends PHPUnit\Framework\TestCase { use R83Dev\TestAccessible\AccessibleTrait; private ?MyUnit $unit; protected function setUp(): void { $this->unit = new MyUnit(); } #[\PHPUnit\Framework\Attributes\Test] public function getStateShouldReturnCorrectInitialValue(): void { $this->assertSame( $this->getInaccessibleConstant($this->unit, 'STATE_ON'), $this->getInaccessibleProperty($this->unit, 'state') ); } #[\PHPUnit\Framework\Attributes\Test] public function getStateReturnsNewValueFromSetter(): void { $off = $this->getInaccessibleConstant($this->unit, 'STATE_OFF'); $this->callInaccessibleMethod($this->unit, 'setState', $off) $this->assertSame($off, $this->unit->getState()); } #[\PHPUnit\Framework\Attributes\Test] public function getStateReturnsNewValueFromPropertyAllocation(): void { $this->assertSame( 'unknown', $this->setInaccessibleProperty($this->unit, 'state', 'unknown')->getState() ); } }
r83dev/test-accessible 适用场景与选型建议
r83dev/test-accessible 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.03k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「phpunit」 「accessible」 「testing-tools」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 r83dev/test-accessible 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 r83dev/test-accessible 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 r83dev/test-accessible 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HiDev plugin for PHPUnit
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
A bundle to easily use Accessible in Symfony projects.
PHPUnit DbUnit Native Array-based Fixtures
All in One Accessibility widget improves website ADA compliance and browser experience for ADA, WCAG 2.1 & 2.2, Section 508, Australian DDA, European EAA EN 301 549, UK Equality Act (EA), Israeli Standard 5568, California Unruh, Ontario AODA, Canada ACA, German BITV, France RGAA, Brazilian Inclusion
统计信息
- 总下载量: 5.03k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-30