Install
composer require --dev phpunit/phpunit ^11
Solve some issues
After upgrade to PHPUnit 11 for 9, got some issues. Here are how I solved them
Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.
//old codes
/**
* Test Migrate profile from vault id
* @depends testCreateProfile
*/
public function testMigrateProfileFromVaultId($result)
//new code to fix the problem
/**
* Test Migrate profile from vault id
*/
#[Depends('testCreateProfile')]
public function testMigrateProfileFromVaultId($result)
ArgumentCountError: Too few arguments to function AuthorizenetTest::testProcessRefund(), 0 passed in /var/www/vendor/phpunit/phpunit/src/Framework/TestCase.php
After use attribute #[Depends('testCreateProfile')], got this error.
//to fix it. add this line in the begin of test class
use PHPUnit\Framework\Attributes\Depends;
Show deprecated details
Need this atribute in phpunit config
displayDetailsOnTestsThatTriggerDeprecations="true"
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitDeprecations="true"
bootstrap="./src/bootstrap.php" colors="true" stopOnFailure="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
cacheDirectory=".phpunit.cache">
......
</phpunit>
--display-phpunit-deprecations
Code Coverage
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
bootstrap="./bootstrap.php" colors="true" stopOnFailure="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage>
<report>
<clover outputFile="ut_build/logs/clover.xml"/>
<html outputDirectory="ut_build/logs/clover.html"/>
<text outputFile="php://stdout" showUncoveredFiles="true" showOnlySummary="true"/>
</report>
</coverage>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./src/bootstrap.php</file>
<directory suffix=".php">./src/Scripts</directory>
</exclude>
</source>
<testsuites>
<testsuite name="rest">
<directory>./tests</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>
coverage and source elements are for code coverage
//in xdebug.ini
xdebug.mode=coverage
No comments:
Post a Comment