Coming from an old version of PHPUnit, let's see what the current supported version (8) deprecates, removes and what you need to change when writing your tests.
<!-- Before -->
<blacklist>
<directory>./config</directory>
</blacklist>
<!-- After -->
<whitelist>
<exclude>
<directory>./config</directory>
</exclude>
</whitelist>
As a rule of thumb, underscores can be replaced with a backslash
// Before
use PHPUnit_Framework_TestCase;
use PHPUnit_Framework_MockObject_MockObject;
use PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls;
use PHPUnit_Framework_MockObject_InvocationMocker;
// After
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Stub\ConsecutiveCalls;
use PHPUnit\Framework\MockObject\InvocationMocker;
...etc
// Before
public function setUp()
public function tearDown()
public static function setUpBeforeClass()
public static function tearDownAfterClass()
// After
public function setUp(): void
public function tearDown(): void
public static function setUpBeforeClass(): void
public static function tearDownAfterClass(): void
// Before
$serviceMock = $this->getMock(
'Service',
array('update'),
$params,
'',
false
);
// After
$serviceMock = $this->getMockBuilder('Service')
->setMethods(array('update'))
->setConstructorArgs($params)
->setMockClassName('')
->disableOriginalConstructor()
->getMock();
);
// Before
/**
* Test that an exception is thrown when an unsupported form type is specified
*
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid!
*/
public function testInstantiateContactFormThrowsException()
{
(new ContactForm('foo'));
}
public function testInstantiateContactFormThrowsException()
{
$this->setExpectedException('InvalidArgumentException', 'Invalid!');
(new ContactForm('foo'));
}
// After
/**
* Test that an exception is thrown when an unsupported form type is specified
*/
public function testInstantiateContactFormThrowsException()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid!');
(new ContactForm('foo'));
}
// Before
$this->assertContains('needle', 'haystack');
$this->assertNotContains('needle', 'haystack');
// After
$this->assertStringContainsString('needle', 'haystack');
$this->assertStringNotContainsString('needle', 'haystack');
// Before
public function testDataProvider()
{
}
/**
* @dataProvider testDataProvider
*/
public function testPayload()
{
}
// After
public function myDataProvider()
{
}
/**
* @dataProvider myDataProvider
*/
public function testPayload()
{
}
// Before
$this->assertNull(null, $iAmNull);
// After
$this->assertNull($iAmNull);
https://github.com/sebastianbergmann/phpunit/issues/3338