class ProtectedPrivatesSubclass in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/phpunit_example/tests/src/Unit/Subclasses/ProtectedPrivatesSubclass.php \Drupal\Tests\phpunit_example\Unit\Subclasses\ProtectedPrivatesSubclass
A class for testing ProtectedPrivate::protectedAdd().
We could use reflection to test protected methods, just as with private ones. But in some circumstances it might make more sense to make a subclass and then run the tests against it.
This subclass allows us to get access to the protected method.
Hierarchy
- class \Drupal\phpunit_example\ProtectedPrivates
- class \Drupal\Tests\phpunit_example\Unit\Subclasses\ProtectedPrivatesSubclass
Expanded class hierarchy of ProtectedPrivatesSubclass
Related topics
1 file declares its use of ProtectedPrivatesSubclass
- ProtectedPrivatesTest.php in phpunit_example/
tests/ src/ Unit/ ProtectedPrivatesTest.php
File
- phpunit_example/
tests/ src/ Unit/ Subclasses/ ProtectedPrivatesSubclass.php, line 18
Namespace
Drupal\Tests\phpunit_example\Unit\SubclassesView source
class ProtectedPrivatesSubclass extends ProtectedPrivates {
/**
* A stub class so we can access a protected method.
*
* We use a naming convention to make it clear that we are using a
* shimmed method.
*/
public function subclassProtectedAdd($a, $b) {
return $this
->protectedAdd($a, $b);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ProtectedPrivates:: |
private | function | A simple addition method with validity checking. | |
ProtectedPrivates:: |
protected | function | A simple addition method with validity checking. | |
ProtectedPrivatesSubclass:: |
public | function | A stub class so we can access a protected method. |