You are here

public function HttpTest::testFetchHttpWithAuth in Migrate Plus 8.5

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/data_fetcher/HttpTest.php \Drupal\Tests\migrate_plus\Unit\data_fetcher\HttpTest::testFetchHttpWithAuth()

Test 'http' data fetcher (with auth) returns an expected response.

File

tests/src/Unit/data_fetcher/HttpTest.php, line 110
PHPUnit tests for the Migrate Plus Http 'data fetcher' plugin.

Class

HttpTest
@coversDefaultClass \Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher\Http

Namespace

Drupal\Tests\migrate_plus\Unit\data_fetcher

Code

public function testFetchHttpWithAuth() : void {
  $migration_config = $this->migrationConfiguration + $this->specificMigrationConfig;
  $plugin = new TestHttp($migration_config, $this->dataFetcherPluginId, $this->pluginDefinition);
  $plugin
    ->mockHttpClient([
    [
      200,
      'application/json',
      $this->testData,
    ],
  ], $this->basicAuthenticator);

  // The Guzzle mock returns an instance of StreamInterface.
  // http://docs.guzzlephp.org/en/latest/psr7.html
  $stream = $plugin
    ->getResponseContent($migration_config['urls'][0]);
  $body = json_decode((string) $stream, TRUE);

  // Compare what we got back from the parser to what we expected to get.
  $expected = json_decode($this->testData, TRUE);
  $this
    ->assertSame($expected, $body);
}