xp-devs/rector-verify
Composer 安装命令:
composer require xp-devs/rector-verify
包简介
Rector refactoring to migrate from PHPHunit assertions to Codeception/Verify expectations
README 文档
README
This project lets you migrate from PHPUnit assertions to BDD style assertions Codeception/Verify using automated refactoring powered by Rector
Code before:
class GenericEventTest extends TestCase { private GenericEvent $event; private \stdClass $subject; protected function setUp(): void { $this->subject = new \stdClass(); $this->event = new GenericEvent($this->subject, ['name' => 'Event']); } public function testConstruct() { $this->assertEquals(new GenericEvent($this->subject, ['name' => 'Event']), $this->event); } /** * Tests Event->getArgs(). */ public function testGetArguments() { // test getting all $this->assertSame(['name' => 'Event'], $this->event->getArguments()); } public function testSetArguments() { $result = $this->event->setArguments(['foo' => 'bar']); $this->assertSame(['foo' => 'bar'], $this->event->getArguments()); $this->assertSame($this->event, $result); } }
Code after:
class GenericEventTest extends TestCase { private GenericEvent $event; private \stdClass $subject; protected function setUp(): void { $this->subject = new \stdClass(); $this->event = new GenericEvent($this->subject, ['name' => 'Event']); } public function testConstruct() { expect($this->event)->toEqual(new GenericEvent($this->subject, ['name' => 'Event'])); } /** * Tests Event->getArgs(). */ public function testGetArguments() { // test getting all expect($this->event->getArguments())->toBe(['name' => 'Event']); } public function testSetArguments() { $result = $this->event->setArguments(['foo' => 'bar']); expect($this->event->getArguments())->toBe(['foo' => 'bar']); expect($result)->toBe($this->event); } }
Installation
You can install the package as a dev dependency:
composer require --dev xp-devs/rector-verify
Configuration
Add AssertionVerifyRector rule to your Rector config file
<?php declare(strict_types=1); use Rector\Config\RectorConfig; use XpDevs\RectorVerify\AssertionVerifyRector; return RectorConfig::configure() ->withRules([ AssertionVerifyRector::class, ]);
Usage
To see the code migrations that Rector will do, run:
vendor/bin/rector process --dry-run
and when you want to execute the migrations run:
vendor/bin/rector process
Supports expectations
| PHPUnit | Expect |
|---|---|
| assertEquals | toEqual |
| assertNotEquals | notToEqual |
| assertSame | toBe |
| assertNotSame | notToBe |
| assertInstanceOf | toBeInstanceOf |
| assertNotInstanceOf | notToBeInstanceOf |
| assertCount | arrayToHaveCount |
| assertNotCount | arrayNotToHaveCount |
| assertGreaterThan | toBeGreaterThan |
| assertGreaterThanOrEqual | toBeGreaterThanOrEqualTo |
| assertLessThan | toBeLessThan |
| assertLessThanOrEqual | toBeLessThanOrEqualTo |
| assertContainsOnlyInstancesOf | arrayToContainOnlyInstancesOf |
| assertArrayHasKey | arrayToHaveKey |
| assertArrayNotHasKey | arrayNotToHaveKey |
| assertNotContains | arrayNotToContain |
| assertNotContainsEquals | arrayNotToContainEqual |
| assertNotContainsOnly | arrayNotToContainOnly |
| assertNotSameSize | arrayNotToHaveSameSizeAs |
| assertContains | arrayToContain |
| assertContainsEquals | arrayToContainEqual |
| assertContainsOnly | arrayToContainOnly |
| assertSameSize | arrayToHaveSameSizeAs |
| assertObjectNotHasProperty | baseObjectNotToHaveProperty |
| assertObjectHasProperty | baseObjectToHaveProperty |
| assertJsonFileNotEqualsJsonFile | jsonFileNotToEqualJsonFile |
| assertJsonFileEqualsJsonFile | jsonFileToEqualJsonFile |
| assertJsonStringNotEqualsJsonFile | jsonStringNotToEqualJsonFile |
| assertJsonStringNotEqualsJsonString | jsonStringNotToEqualJsonString |
| assertJsonStringEqualsJsonFile | jsonStringToEqualJsonFile |
| assertJsonStringEqualsJsonString | jsonStringToEqualJsonString |
| assertXmlFileNotEqualsXmlFile | xmlFileNotToEqualXmlFile |
| assertXmlFileEqualsXmlFile | xmlFileToEqualXmlFile |
| assertXmlStringNotEqualsXmlFile | xmlStringNotToEqualXmlFile |
| assertXmlStringNotEqualsXmlString | xmlStringNotToEqualXmlString |
| assertXmlStringEqualsXmlFile | xmlStringToEqualXmlFile |
| assertXmlStringEqualsXmlString | xmlStringToEqualXmlString |
| assertStringNotContainsString | stringNotToContainString |
| assertStringNotContainsStringIgnoringCase | stringNotToContainStringIgnoringCase |
| assertStringEndsNotWith | stringNotToEndWith |
| assertStringNotEqualsFile | stringNotToEqualFile |
| assertStringNotEqualsFileCanonicalizing | stringNotToEqualFileCanonicalizing |
| assertStringNotEqualsFileIgnoringCase | stringNotToEqualFileIgnoringCase |
| assertStringNotMatchesFormat | stringNotToMatchFormat |
| assertStringNotMatchesFormatFile | stringNotToMatchFormatFile |
| assertDoesNotMatchRegularExpression | stringNotToMatchRegExp |
| assertStringStartsNotWith | stringNotToStartWith |
| assertJson | stringToBeJson |
| assertStringContainsString | stringToContainString |
| assertStringContainsStringIgnoringCase | stringToContainStringIgnoringCase |
| assertStringEndsWith | stringToEndWith |
| assertStringEqualsFile | stringToEqualFile |
| assertStringEqualsFileCanonicalizing | stringToEqualFileCanonicalizing |
| assertStringEqualsFileIgnoringCase | stringToEqualFileIgnoringCase |
| assertStringMatchesFormat | stringToMatchFormat |
| assertStringMatchesFormatFile | stringToMatchFormatFile |
| assertMatchesRegularExpression | stringToMatchRegExp |
| assertStringStartsWith | stringToStartWith |
| assertNotEqualsCanonicalizing | notToEqualCanonicalizing |
| assertNotEqualsIgnoringCase | notToEqualIgnoringCase |
| assertEqualsCanonicalizing | toEqualCanonicalizing |
| assertEqualsIgnoringCase | toEqualIgnoringCase |
| assertTrue | toBeTrue |
| assertNotTrue | notToBeTrue |
| assertFalse | toBeFalse |
| assertNotFalse | notToBeFalse |
| assertNull | toBeNull |
| assertNotNull | notToBeNull |
| assertEmpty | toBeEmpty |
| assertNotEmpty | notToBeEmpty |
| assertIsArray | toBeArray |
| assertIsBool | toBeBool |
| assertIsFloat | toBeFloat |
| assertIsInt | toBeInt |
| assertIsNumeric | toBeNumeric |
| assertIsObject | toBeObject |
| assertIsResource | toBeResource |
| assertIsString | toBeString |
| assertIsScalar | toBeScalar |
| assertIsCallable | toBeCallable |
| assertIsIterable | toBeIterable |
| assertIsNotArray | notToBeArray |
| assertIsNotBool | notToBeBool |
| assertIsNotFloat | notToBeFloat |
| assertIsNotInt | notToBeInt |
| assertIsNotNumeric | notToBeNumeric |
| assertIsNotObject | notToBeObject |
| assertIsNotResource | notToBeResource |
| assertIsNotString | notToBeString |
| assertIsNotScalar | notToBeScalar |
| assertIsNotCallable | notToBeCallable |
| assertIsNotIterable | notToBeIterable |
| assertDirectoryIsNotReadable | directoryNotToBeReadable |
| assertDirectoryIsNotWritable | directoryNotToBeWritable |
| assertDirectoryDoesNotExist | directoryNotToExist |
| assertDirectoryIsReadable | directoryToBeReadable |
| assertDirectoryIsWritable | directoryToBeWritable |
| assertDirectoryExists | directoryToExist |
| assertFileIsNotReadable | fileNotToBeReadable |
| assertFileIsNotWritable | fileNotToBeWritable |
| assertFileDoesNotExist | fileNotToExist |
| assertFileEquals | fileToBeEqual |
| assertFileEqualsCanonicalizing | fileToBeEqualCanonicalizing |
| assertFileEqualsIgnoringCase | fileToBeEqualIgnoringCase |
| assertFileIsReadable | fileToBeReadable |
| assertFileIsWritable | fileToBeWritable |
| assertFileExists | fileToExist |
| assertFileNotEquals | fileToNotEqual |
| assertFileNotEqualsCanonicalizing | fileToNotEqualCanonicalizing |
| assertFileNotEqualsIgnoringCase | fileToNotEqualIgnoringCase |
| assertIsNotClosedResource | notToBeClosedResource |
| assertIsClosedResource | toBeClosedResource |
| assertFinite | toBeFinite |
| assertInfinite | toBeInfinite |
| assertNan | toBeNan |
License
The MIT License (MIT). Please see License File for more information.
xp-devs/rector-verify 适用场景与选型建议
xp-devs/rector-verify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.41k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 xp-devs/rector-verify 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xp-devs/rector-verify 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-13