You are here

protected function AssetRefreshManagerTest::setupMediaEntityExpectations in Media: Acquia DAM 8

Setups the media entity query execution expectations.

Parameters

array $expected_asset_ids: The list of expected asset ids.

int $expected_total: The expected number of media entities to add to the queue.

2 calls to AssetRefreshManagerTest::setupMediaEntityExpectations()
AssetRefreshManagerTest::testInterruptedFetch in tests/src/Unit/AssetRefreshManagerTest.php
Tests an "interrupted API fetch (a result set exceeds the limit)" scenario.
AssetRefreshManagerTest::testNonInterruptedFetch in tests/src/Unit/AssetRefreshManagerTest.php
Tests a "non-interrupted API fetch" scenario.

File

tests/src/Unit/AssetRefreshManagerTest.php, line 526

Class

AssetRefreshManagerTest
AssetRefreshManager Service test.

Namespace

Drupal\Tests\media_acquiadam\Unit

Code

protected function setupMediaEntityExpectations(array $expected_asset_ids, int $expected_total) {
  $this->entityQuery
    ->expects($this
    ->any())
    ->method('orConditionGroup')
    ->will($this
    ->returnSelf());
  $this->entityQuery
    ->expects($this
    ->any())
    ->method('condition')
    ->withConsecutive([
    $this
      ->equalTo('bundle'),
    $this
      ->equalTo('test_bundle'),
  ], [
    $this
      ->equalTo('field_1'),
    $this
      ->equalTo($expected_asset_ids),
  ])
    ->will($this
    ->returnSelf());
  if (!$expected_asset_ids) {
    return;
  }
  $this->entityQuery
    ->expects($this
    ->any())
    ->method('execute')
    ->willReturn(range(1, $expected_total));
  $unit_test = $this;
  $expected_queue_items = array_map(function ($value) use ($unit_test) {
    return [
      $unit_test
        ->equalTo([
        'media_id' => $value,
      ]),
    ];
  }, range(1, $expected_total));
  $this->queue
    ->expects($this
    ->any())
    ->method('createItem')
    ->withConsecutive(...$expected_queue_items);
}