function ContrivedControllerTest::testHandCountIsolated

Test hand count isolated.

@dataProvider providerTestHandCountIsolated

File

modules/testing_example/tests/src/Unit/Controller/ContrivedControllerTest.php, line 101

Class

ContrivedControllerTest
The class to test ContrivedController.

Namespace

Drupal\Tests\testing_example\Unit\Controller

Code

public function testHandCountIsolated($expected, $sum) {
  // Mock a ContrivedController, using a mocked translation service.
  $controller = $this->getMockBuilder(ContrivedController::class)
    ->setConstructorArgs([
    $this->getStringTranslationStub(),
  ])
    ->onlyMethods([
    'add',
  ])
    ->getMock();
  // Mock add() so that it returns our $sum when it's called with (0,0).
  $controller->expects($this->once())
    ->method('add')
    ->with($this->equalTo(0), $this->equalTo(0))
    ->willReturn($sum);
  // Use reflection to make handCount() public.
  $ref_hand_count = new \ReflectionMethod($controller, 'handCount');
  // Invoke handCount().
  $message = (string) $ref_hand_count->invokeArgs($controller, [
    0,
    0,
  ]);
  // Assert our expectations.
  $this->assertEquals($expected, $message);
}