class ProtectedPrivatesSubclass
Same name in other branches
- 4.0.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 extends \Drupal\phpunit_example\ProtectedPrivates
Expanded class hierarchy of ProtectedPrivatesSubclass
Related topics
1 file declares its use of ProtectedPrivatesSubclass
- ProtectedPrivatesTest.php in modules/
phpunit_example/ tests/ src/ Unit/ ProtectedPrivatesTest.php
File
-
modules/
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
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ProtectedPrivates::privateAdd | private | function | A simple addition method with validity checking. |
ProtectedPrivates::protectedAdd | protected | function | A simple addition method with validity checking. |
ProtectedPrivatesSubclass::subclassProtectedAdd | public | function | A stub class so we can access a protected method. |