webimpress / phpunit-migration
Migrate your tests to the newest PHPUnit version
Fund package maintenance!
michalbundyra
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 11
Watchers: 2
Forks: 2
Open Issues: 2
pkg:composer/webimpress/phpunit-migration
Requires
- php: ^7.3 || ^8.0
- ext-json: *
- composer/semver: ^1.7.1 || ^2.0 || ^3.2.4
- symfony/console: ^4.4.16 || ^5.1.8
Requires (Dev)
- phpunit/phpunit: ^9.4.3
- webimpress/coding-standard: ^1.2
This package is auto-updated.
Last update: 2023-03-29 00:18:35 UTC
README
PHPUnit migration tool
Migrate project to the newest version of PHPUnit.
[Work In Progress] Use it on the own risk :)
How to use the tool?
Clone the project:
$ git clone https://github.com/webimpress/phpunit-migration.git
Go into the directory and install dependencies:
$ cd phpunit-migration $ composer install
To update your project to the newest version of PHPUnit go to your project directory and run:
$ ../path/to/phpunit-migration/bin/phpunit-migration migrate
What the tool is changing?
- compose dependencies to the latest PHPUnit versions,
\PHPUnit_Framework_TestCaseto namespaced\PHPUnit\Framework\TestCase,setExpectedExceptiontoexpectException*,setUpandtearDowntoprotectedand correct case (setup=>setUpetc.),- FQCN in
@covertag (i.e.@covers MyClassto@covers \MyClass), assertInternalTypeandassertNotInternalTypeto more specific assertion method (PHPUnit 7.5+),getMocktogetMockBuilderwith other required function calls (PHPUnit 5.4+),getMockBuilder(...)->...->getMock()tocreateMock(...)if possible (PHPUnit 5.4+),assertEquals()andassertNotEquals()with$delta,$maxDepth,$canonicalizeand$ignoreCaseparameters to more specific assertion method (PHPUnit 7.5+),- add void return type to the following methods:
setUp(),tearDown(),setUpBeforeClass(),tearDownAfterClass(),assertPreConditions(),assertPostConditions(),onNotSuccessfulTest(\Throwable $th)(PHPUnit 8.0+), expectExceptionMessageRegExptoexpectExceptionMessageMatches(PHPUnit 8.4+),- use new (more readable) assertion names:
assertNotIsReadablereplaced byassertIsNotReadable',assertNotIsWritablereplaced byassertIsNotWritable',assertDirectoryNotExistsreplaced byassertDirectoryDoesNotExist',assertDirectoryNotIsReadablereplaced byassertDirectoryIsNotReadable',assertDirectoryNotIsWritablereplaced byassertDirectoryIsNotWritable',assertFileNotExistsreplaced byassertFileDoesNotExist',assertFileNotIsReadablereplaced byassertFileIsNotReadable',assertFileNotIsWritablereplaced byassertFileIsNotWritable',assertRegExpreplaced byassertMatchesRegularExpression',assertNotRegExpreplaced byassertDoesNotMatchRegularExpression'. (PHPUnit 9.1+),
- TODO:
getMockBuilder(...)->...->setMethods(...)->getMock()tocreatePartialMock(...)if possible (PHPUnit 5.5.3+), - TODO:
assertContains()andassertNotContains()onstringhaystack to more specific assertion method (PHPUnit 7.5+), - TODO:
$this->asserttoself::assert.
What the tool is NOT doing?
- changing
PHPUnit_Framework_Error_*classes - probably other things I don't remember now ;-)
Note
Please remember it is developer tool and it should be used only as a helper to migrate your tests to newer version of PHPUnit. Always after migration run all your test to verify if applied changes are right and your tests are still working!