class AddClass in Examples for Developers 3.x
Same name and namespace in other branches
- 8 phpunit_example/src/AddClass.php \Drupal\phpunit_example\AddClass
A class with features to show how to do unit testing.
Hierarchy
- class \Drupal\phpunit_example\AddClass
Expanded class hierarchy of AddClass
Related topics
1 file declares its use of AddClass
- AddClassTest.php in modules/
phpunit_example/ tests/ src/ Unit/ AddClassTest.php
File
- modules/
phpunit_example/ src/ AddClass.php, line 10
Namespace
Drupal\phpunit_exampleView source
class AddClass {
/**
* A simple addition method with validity checking.
*
* @param int|float $a
* A number to add.
* @param int|float $b
* Another number to add.
*
* @return int|float
* The sum of $a and $b.
*
* @throws \InvalidArgumentException
* If either $a or $b is non-numeric, we can't add, so we throw.
*/
public function add($a, $b) {
// Check whether the arguments are numeric.
foreach ([
$a,
$b,
] as $argument) {
if (!is_numeric($argument)) {
throw new \InvalidArgumentException('Arguments must be numeric.');
}
}
return $a + $b;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AddClass:: |
public | function | A simple addition method with validity checking. |