You are here

public function AcquiaSearchApiClientTest::setUp in Acquia Search 3.x

Overrides UnitTestCase::setUp

File

tests/src/Unit/AcquiaSearchApiClientTest.php, line 46

Class

AcquiaSearchApiClientTest
@coversDefaultClass \Drupal\acquia_search\AcquiaSearchApiClient @group Acquia Search Solr

Namespace

Drupal\Tests\acquia_search\Unit

Code

public function setUp() {
  parent::setUp();

  // \Drupal::state().
  $state = $this
    ->prophesize(State::class);
  $state
    ->set(Argument::type('string'), Argument::type('string'))
    ->will(function ($arguments) use ($state) {
    $state
      ->get($arguments[0], Argument::any())
      ->willReturn($arguments[1]);
  });
  $state
    ->get('acquia_search.version')
    ->willReturn(NULL);

  // \Drupal::time().
  $time = $this
    ->prophesize(Time::class);
  $time
    ->getRequestTime()
    ->willReturn(1234567000000);

  // \Drupal::logger().
  $logger_factory = $this
    ->prophesize(LoggerChannelFactory::class);
  $logger = $this
    ->prophesize(LoggerChannel::class);
  $logger
    ->error(Argument::any(), Argument::any())
    ->willReturn();
  $logger_factory
    ->get('acquia_search')
    ->willReturn($logger
    ->reveal());
  $config_factory = $this
    ->prophesize(ConfigFactoryInterface::class);
  $config = $this
    ->prophesize(ImmutableConfig::class);
  $config
    ->get('override_search_core')
    ->willReturn(NULL);
  $config
    ->get('read_only')
    ->willReturn(FALSE);
  $config
    ->get('api_host')
    ->willReturn('https://example.com');
  $config_editable = $this
    ->prophesize(Config::class);
  $config_editable
    ->set('api_host', 'https://example.com')
    ->willReturn($config_editable
    ->reveal());
  $config_editable
    ->save()
    ->willReturn($config_editable);
  $config_factory
    ->get('acquia_search.settings')
    ->willReturn($config
    ->reveal());
  $config_factory
    ->getEditable('acquia_search.settings')
    ->willReturn($config_editable
    ->reveal());
  $container = new ContainerBuilder();
  $container
    ->set('state', $state
    ->reveal());
  $container
    ->set('datetime.time', $time
    ->reveal());
  $container
    ->set('logger.factory', $logger_factory
    ->reveal());
  $container
    ->set('config.factory', $config_factory
    ->reveal());
  \Drupal::setContainer($container);
  $storage = new Storage();
  $storage
    ->setApiHost('https://example.com');
  $storage
    ->setApiKey('XXXXXXXXXXyyyyyyyyyyXXXXXXXXXXyyyyyyyyyy');
  $storage
    ->setIdentifier('WXYZ-12345');
  $uuid = new Php();
  $storage
    ->setUuid($uuid
    ->generate());
  $json = json_encode([
    [
      'key' => 'WXYZ-12345',
      'secret_key' => 'secret_key',
      'product_policies' => [
        'salt' => 'salt',
      ],
      'host' => 'example.com',
    ],
    [
      'key' => 'WXYZ-12345.dev.drupal8',
      'secret_key' => 'secret_key',
      'product_policies' => [
        'salt' => 'salt',
      ],
      'host' => 'example.com',
    ],
  ]);
  $stream = $this
    ->prophesize(StreamInterface::class);
  $stream
    ->getSize()
    ->willReturn(1000);
  $stream
    ->read(1000)
    ->willReturn($json);
  $response = $this
    ->prophesize(ResponseInterface::class);
  $response
    ->getStatusCode()
    ->willReturn(200);
  $response
    ->getBody()
    ->willReturn($stream);
  $this->guzzleClient = $this
    ->prophesize(Client::class);
  $uri = Storage::getApiHost() . '/v2/index/configure?network_id=' . Storage::getIdentifier();
  $this->guzzleClient
    ->get($uri, Argument::any())
    ->willReturn($response);
  $this->guzzleClient
    ->get(Argument::any(), Argument::any())
    ->willReturn();
  $this->cacheBackend = $this
    ->prophesize(CacheBackendInterface::class);
}