webimpress / phpunit-migration
Migrate your tests to the newest PHPUnit version
Fund package maintenance!
michalbundyra
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_TestCase
to namespaced\PHPUnit\Framework\TestCase
,setExpectedException
toexpectException*
,setUp
andtearDown
toprotected
and correct case (setup
=>setUp
etc.),- FQCN in
@cover
tag (i.e.@covers MyClass
to@covers \MyClass
), assertInternalType
andassertNotInternalType
to more specific assertion method (PHPUnit 7.5+),getMock
togetMockBuilder
with other required function calls (PHPUnit 5.4+),getMockBuilder(...)->...->getMock()
tocreateMock(...)
if possible (PHPUnit 5.4+),assertEquals()
andassertNotEquals()
with$delta
,$maxDepth
,$canonicalize
and$ignoreCase
parameters 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+), expectExceptionMessageRegExp
toexpectExceptionMessageMatches
(PHPUnit 8.4+),- use new (more readable) assertion names:
assertNotIsReadable
replaced byassertIsNotReadable'
,assertNotIsWritable
replaced byassertIsNotWritable'
,assertDirectoryNotExists
replaced byassertDirectoryDoesNotExist'
,assertDirectoryNotIsReadable
replaced byassertDirectoryIsNotReadable'
,assertDirectoryNotIsWritable
replaced byassertDirectoryIsNotWritable'
,assertFileNotExists
replaced byassertFileDoesNotExist'
,assertFileNotIsReadable
replaced byassertFileIsNotReadable'
,assertFileNotIsWritable
replaced byassertFileIsNotWritable'
,assertRegExp
replaced byassertMatchesRegularExpression'
,assertNotRegExp
replaced byassertDoesNotMatchRegularExpression'
. (PHPUnit 9.1+),
- TODO:
getMockBuilder(...)->...->setMethods(...)->getMock()
tocreatePartialMock(...)
if possible (PHPUnit 5.5.3+), - TODO:
assertContains()
andassertNotContains()
onstring
haystack to more specific assertion method (PHPUnit 7.5+), - TODO:
$this->assert
toself::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!