acquia_dam-1.0.0-rc1/tests/src/Unit/AcquiaDamClientTest.php

tests/src/Unit/AcquiaDamClientTest.php
<?php

declare(strict_types=1);

namespace Drupal\Tests\acquia_dam\Unit;

use Drupal\acquia_dam\Client\AcquiaDamClient;
use Drupal\Component\Datetime\Time;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Tests\UnitTestCase;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\Psr7\Response;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * @group acquia_dam
 */
final class AcquiaDamClientTest extends UnitTestCase {

  /**
   * Tests getting an asset from the client leverages caching.
   */
  public function testGetAsset(): void {
    $mock_data = file_get_contents(__DIR__ . '/../../fixtures/a56fb261-8ad5-4e0d-8323-0e8a3659ed39.json');
    self::assertNotFalse($mock_data);
    $backend = $this->createMock(CacheBackendInterface::class);
    $backend->expects($this->exactly(2))
      ->method('get')
      ->with('asset:foo:bar')
      ->willReturn(FALSE, (object) [
        'data' => $mock_data,
      ]);
    $backend->expects($this->once())
      ->method('set')
      ->with('asset:foo:bar', $mock_data, 1649256864, [
        'acquia-dam-asset',
        'acquia-dam-asset:foo',
      ]);

    $time = new Time(new RequestStack());
    $config = $this->createMock(ImmutableConfig::class);
    $logger = $this->createMock(LoggerInterface::class);
    $client = new AcquiaDamClient(
      $backend,
      $time,
      $config,
      [
        'handler' => new MockHandler([
          new Response(200, [], $mock_data),
        ]),
      ],
      $logger
    );
    $first = $client->getAsset('foo', 'bar');
    self::assertEquals(Json::decode($mock_data), $first);
    $second = $client->getAsset('foo', 'bar');
    self::assertEquals(Json::decode($mock_data), $second);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc