You are here

class ClientTest in Little helpers 7.2

Test the JSON/REST API-client.

Hierarchy

  • class \Drupal\little_helpers\Rest\ClientTest extends \Upal\DrupalUnitTestCase

Expanded class hierarchy of ClientTest

File

tests/Rest/ClientTest.php, line 10

Namespace

Drupal\little_helpers\Rest
View source
class ClientTest extends DrupalUnitTestCase {

  /**
   * Create a client instance with a stubbed sendRequest() method.
   */
  protected function mockClient(string $endpoint = 'https://example.com', array $options = []) {
    return $this
      ->getMockBuilder(Client::class)
      ->setConstructorArgs([
      $endpoint,
      $options,
    ])
      ->setMethods([
      'sendRequest',
    ])
      ->getMock();
  }

  /**
   * Test that send() adds slashes automatically as needed.
   */
  public function testAddSlash() {
    $client = $this
      ->mockClient();
    $client
      ->expects($this
      ->once())
      ->method('sendRequest')
      ->with('https://example.com/no-slash', $this
      ->anything())
      ->willReturn((object) [
      'data' => '{}',
    ]);
    $client
      ->get('no-slash');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ClientTest::mockClient protected function Create a client instance with a stubbed sendRequest() method.
ClientTest::testAddSlash public function Test that send() adds slashes automatically as needed.