未加星标

Migrating to PHPUnit 6

字体大小 | |
[开发(php) 所属分类 开发(php) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

The first version of phpUnit 6 was released today. Today also marks the End of Life of PHPUnit 4 . What does this mean for you? The answer to this question depends on which versions of PHP and PHPUnit you currently use.

You currently use PHPUnit 4

Until today, PHPUnit 4.8 was the old stable release of PHPUnit. It was supported on PHP 5.3 , PHP 5.4 , PHP 5.5 , and PHP 5.6 . Active support for PHP 5 ended on December 31, 2016 and PHP 5.3 , PHP 5.4 , PHP 5.5 have already reached their End of Life.

You use a version of PHPUnit that is no longer supported, no bugs will be fixed, and no new releases will be made. If you still use PHP 5.3 , PHP 5.4 , or PHP 5.5 then PHPUnit 4.8 is newest version of PHPUnit you can use. If you use PHP 5.6 , PHP 7.0 , or PHP 7.1 then you should upgrade to PHPUnit 6 (see below).

If you use Composer to manage PHPUnit as a dependency of your project and want to ensure that you stay on PHPUnit 4.8 then you should depend on "phpunit/phpunit": "^4.8" in your composer.json file.

If you use PHPUnit from a PHP archive (PHAR) and want to ensure that you stay on PHPUnit 4.8 then you have to download PHPUnit from https://phar.phpunit.de/phpunit-4.8.phar .

You currently use PHPUnit 5

Until today, PHPUnit 5.7 was the stable release of PHPUnit. Now it has become the old stable release of PHPUnit. It is supported on PHP 5.6 , PHP 7.0 , and PHP 7.1 . PHPUnit 5.7 will receive bugfixes until it reaches its End of Life on February 2, 2018.

You use a version of PHPUnit that is still supported but will not get new features anymore. If you still use PHP 5.6 then PHPUnit 5.7 is newest version of PHPUnit you can use. If you use PHP 7.0 or PHP 7.1 then you should upgrade to PHPUnit 6 (see below).

If you use Composer to manage PHPUnit as a dependency of your project and want to ensure that you stay on PHPUnit 5.7 then you should depend on "phpunit/phpunit": "^5.7" in your composer.json file.

If you use PHPUnit from a PHP archive (PHAR) and want to ensure that you stay on PHPUnit 5.7 then you have to download PHPUnit from https://phar.phpunit.de/phpunit-5.7.phar .

You want to use PHPUnit 6

PHPUnit 6 requires PHP 7.0 or PHP 7.1 . It introduces significant changes that require a migration of your existing test suite to PHPUnit 6 .

If you use Composer to manage PHPUnit as a dependency of your project and want to use PHPUnit 6 then you should depend on "phpunit/phpunit": "^6.0" in your composer.json file.

If you use PHPUnit from a PHP archive (PHAR) and want to use PHPUnit 6 then you can download PHPUnit from https://phar.phpunit.de/phpunit.phar .

Below you find a list of things to do and keep in mind while migrating your existing test suite to PHPUnit 6 :

PHPUnit_Framework_TestCase is now PHPUnit\Framework\TestCase

PHPUnit's units of code are now namespaced. Among other things, this means that your test case classes now need to extend PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase .

While PHPUnit 5.7 has a forward compatibility layer, meaning you can already use PHPUnit\Framework\TestCase with that version, there is no backward compatibility layer in PHPUnit 6 that allows you to use PHPUnit_Framework_TestCase .

Useless Tests

For a long time already, PHPUnit can perform perform optional checks for so-called risky tests while executing a test suite. Starting with PHPUnit 6 , the risky test check for useless tests is active by default.

A useless test is one that does not perform an assertion (such as assertEquals() , for instance), does not expect an exception (using expectException() , for instance), and does not configure an expectation on a mock object.

Simply use the --dont-report-useless-tests commandline option or set beStrictAboutTestsThatDoNotTestAnything="false" in your XML configuration file to disable the risky test check for useless tests.

Global State

Starting with PHPUnit 6 , the global and super-global variables are no longer backed up before and restored after each test by default. In general, this functionality is not required for clean, modern, object-oriented PHP code. This functionality slows down the execution of the test suite and increases memory usage.

Simply use the --globals-backup commandline option or set backupGlobals="true" in your XML configuration file to enable the backup of global and super-global variables before each test and their restoring after each test.

Deprecated APIs

Methods such as getMock() , getMockWithoutInvokingTheOriginalConstructor() , setExpectedException() , setExpectedExceptionRegExp() , or hasPerformedExpectationsOnOutput() that were deprecated before have now been removed from PHPUnit 6.

createMock() , createConfiguredMock() , createPartialMock() , createTestProxy() , and getMockBuilder() should be used instead of getMock() and getMockWithoutInvokingTheOriginalConstructor() . And expectException() should be used instead of setExpectedException() (and @expectException ).

JUnit Logger

The logfile format generated using the --log-junit commandline option and the <log type="junit" target="..."/> configuration directive has been updated to match the current format used by JUnit .

Due to this change you may need to update how your continuous integration server processes test result logfiles generated by PHPUnit.

本文开发(php)相关术语:php代码审计工具 php开发工程师 移动开发者大会 移动互联网开发 web开发工程师 软件开发流程 软件开发工程师

主题: PHPXML
分页:12
转载请注明
本文标题:Migrating to PHPUnit 6
本站链接:http://www.codesec.net/view/530082.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(php) | 评论(0) | 阅读(36)