You are here

public function TestFrameworkKernelTest::testNotStackedMockResponse in Apigee Edge 8

Test integration enabled.

Tests that responses are not fetched from the stacked mocks when integration is enabled.

File

tests/src/Kernel/TestFrameworkKernelTest.php, line 171

Class

TestFrameworkKernelTest
Tests the testing framework for testing offline.

Namespace

Drupal\Tests\apigee_edge\Kernel

Code

public function testNotStackedMockResponse() {
  if (!$this->integration_enabled) {
    $this
      ->markTestSkipped('Integration not enabled, skipping test.');
  }
  $developerStorage = $this->entityTypeManager
    ->getStorage('developer');

  /** @var \Drupal\apigee_edge\Entity\Developer $developer */
  $developer = $developerStorage
    ->create([
    'email' => $this
      ->randomMachineName() . '@example.com',
    'userName' => $this
      ->randomMachineName(),
    'firstName' => $this
      ->getRandomGenerator()
      ->word(8),
    'lastName' => $this
      ->getRandomGenerator()
      ->word(8),
  ]);
  $developerStorage
    ->resetCache([
    $developer
      ->getEmail(),
  ]);

  // Unsaved developer, should not be found (should ignore the mock stack).
  $this
    ->queueDeveloperResponseFromDeveloper($developer);
  $loaded_developer = $developerStorage
    ->load($developer
    ->getEmail());
  $this
    ->isEmpty($loaded_developer);

  // Saved developer, following calls should load from the real API,
  // and ignore all stacked responses.
  $this
    ->queueDeveloperResponseFromDeveloper($developer, 201);
  $developer
    ->save();

  // Add to the array of developers to be deleted in tearDown().
  $this->developers[] = $developer;
  $this
    ->queueDeveloperResponseFromDeveloper($developer);
  $loaded_developer = $developerStorage
    ->load($developer
    ->getEmail());
  $this
    ->assertInstanceOf(Developer::class, $loaded_developer);
  $this
    ->assertEqual($loaded_developer
    ->getEmail(), $developer
    ->getEmail());

  // This line is what actually tests that the mock is not used since the mock template sets this attribute.
  $this
    ->assertEmpty($developer
    ->getAttributeValue('IS_MOCK_CLIENT'));
}