function ProtectedPrivatesTest::testPrivateAddBadData

Same name in other branches
  1. 4.0.x modules/phpunit_example/tests/src/Unit/ProtectedPrivatesTest.php \Drupal\Tests\phpunit_example\Unit\ProtectedPrivatesTest::testPrivateAddBadData()

Test ProtectedPrivate::privateAdd() with bad data.

This is essentially the same test as testPrivateAdd(), but using non-numeric data. This lets us test the exception-throwing ability of this private method.

@dataProvider addBadDataProvider

File

modules/phpunit_example/tests/src/Unit/ProtectedPrivatesTest.php, line 104

Class

ProtectedPrivatesTest
ProtectedPrivates unit testing of restricted methods.

Namespace

Drupal\Tests\phpunit_example\Unit

Code

public function testPrivateAddBadData($a, $b) {
    // Get a reflected, accessible version of the privateAdd() method.
    $private_method = $this->getAccessibleMethod('Drupal\\phpunit_example\\ProtectedPrivates', 'privateAdd');
    // Create a new ProtectedPrivates object.
    $pp = new ProtectedPrivates();
    // Use the reflection to invoke on the object.
    // This should throw an exception.
    $this->expectException(\InvalidArgumentException::class);
    $private_method->invokeArgs($pp, [
        $a,
        $b,
    ]);
}