By lendude on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.4.x
Introduced in version:
8.4.4
Description:
getMock() is removed in PHPUnit 6 and createMock() doesn't exist in PHPUnit 4.8, the use of getMock() in any PHPUnit based tests has been deprecated in favour of createMock() or getMockBuilder().
See https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-f...
To smooth over the transition to PHPUnit 6 and later, a forward and backward compatibility layer is provided in the form of \Drupal\Tests\PhpunitCompatibilityTrait. This will allow the use of createMock while running PHPUnit 4, and maintain backward compatibility when moving to PHPUnit 6 and later.
Before:
$this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
After:
$this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
Impacts:
Module developers
Comments
Use getMockBuilder to the do
Use getMockBuilder to the do the partial mock after getMock is deprecated.
For example I have a class called
JwtService. I want to test this class but mockcreateJwtBuildermethod of it. I can doCheck more examples here:
https://phpunit.de/manual/6.5/en/test-doubles.html#test-doubles.mock-obj...