You are here

public function SalesforceControllerTest::setUp in Salesforce Suite 8.3

Set up for each test.

Overrides UnitTestCase::setUp

File

tests/src/Unit/SalesforceControllerTest.php, line 27

Class

SalesforceControllerTest
@coversDefaultClass \Drupal\salesforce\Controller\SalesforceController @group salesforce

Namespace

Drupal\Tests\salesforce\Unit

Code

public function setUp() {
  parent::setUp();
  $this->example_url = 'https://example.com';
  $this->httpClient = $this
    ->getMock('\\GuzzleHttp\\Client', [
    'post',
  ]);
  $this->httpClient
    ->expects($this
    ->once())
    ->method('post')
    ->willReturn(new Response());
  $this->configFactory = $this
    ->getMockBuilder('\\Drupal\\Core\\Config\\ConfigFactory')
    ->disableOriginalConstructor()
    ->getMock();
  $this->state = $this
    ->getMockBuilder('\\Drupal\\Core\\State\\State')
    ->disableOriginalConstructor()
    ->getMock();
  $this->cache = $this
    ->getMock('\\Drupal\\Core\\Cache\\CacheBackendInterface');
  $this->json = $this
    ->getMock(Json::CLASS);
  $this->time = $this
    ->getMock(TimeInterface::CLASS);
  $args = [
    $this->httpClient,
    $this->configFactory,
    $this->state,
    $this->cache,
    $this->json,
    $this->time,
  ];
  $this->client = $this
    ->getMock(RestClient::class, [
    'getConsumerKey',
    'getConsumerSecret',
    'getAuthCallbackUrl',
    'getAuthTokenUrl',
    'handleAuthResponse',
  ], $args);
  $this->client
    ->expects($this
    ->once())
    ->method('getConsumerKey')
    ->willReturn($this
    ->randomMachineName());
  $this->client
    ->expects($this
    ->once())
    ->method('getConsumerSecret')
    ->willReturn($this
    ->randomMachineName());
  $this->client
    ->expects($this
    ->once())
    ->method('getAuthCallbackUrl')
    ->willReturn($this->example_url);
  $this->client
    ->expects($this
    ->once())
    ->method('getAuthTokenUrl')
    ->willReturn($this->example_url);
  $this->client
    ->expects($this
    ->once())
    ->method('handleAuthResponse')
    ->willReturn($this->client);
  $this->request = new Request([
    'code' => $this
      ->randomMachineName(),
  ]);
  $this->request_stack = $this
    ->getMock(RequestStack::class);
  $this->request_stack
    ->expects($this
    ->exactly(2))
    ->method('getCurrentRequest')
    ->willReturn($this->request);
  $this->url_generator = $this
    ->prophesize(MetadataBubblingUrlGenerator::class);
  $this->url_generator
    ->generateFromRoute('salesforce.authorize', [], [
    "absolute" => TRUE,
  ], FALSE)
    ->willReturn('foo/bar');
  $container = new ContainerBuilder();
  $container
    ->set('salesforce.client', $this->client);
  $container
    ->set('http_client', $this->httpClient);
  $container
    ->set('request_stack', $this->request_stack);
  $container
    ->set('url.generator', $this->url_generator
    ->reveal());
  $container
    ->set('datetime.time', $this->time);
  \Drupal::setContainer($container);
}