public function ProtectedPrivatesTest::testProtectedAdd in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/phpunit_example/tests/src/Unit/ProtectedPrivatesTest.php \Drupal\Tests\phpunit_example\Unit\ProtectedPrivatesTest::testProtectedAdd()
Test ProtectedPrivates::protectedAdd() using a stub class.
We could use the same reflection technique to test protected methods, just like we did with private ones.
But sometimes it might make more sense to use a stub class which will have access to the protected method. That's what we'll demonstrate here.
@dataProvider addDataProvider
File
- phpunit_example/
tests/ src/ Unit/ ProtectedPrivatesTest.php, line 129
Class
- ProtectedPrivatesTest
- ProtectedPrivates unit testing of restricted methods.
Namespace
Drupal\Tests\phpunit_example\UnitCode
public function testProtectedAdd($expected, $a, $b) {
$stub = new ProtectedPrivatesSubclass();
$this
->assertEquals($expected, $stub
->subclassProtectedAdd($a, $b));
}