Zendesk\API\UnitTests\BasicTest::assertRequestIs PHP Method

assertRequestIs() public method

This checks the response with the given index
public assertRequestIs ( $options, integer $index )
$options
$index integer
    public function assertRequestIs($options, $index = 0)
    {
        $this->assertArrayHasKey($index, $this->mockedTransactionsContainer, 'Should have made an API call.');
        $transaction = $this->mockedTransactionsContainer[$index];
        $request = $transaction['request'];
        $response = $transaction['response'];
        $options = array_merge(['statusCode' => 200, 'headers' => ['Accept' => 'application/json', 'Content-Type' => 'application/json']], $options);
        $this->assertEquals($options['statusCode'], $response->getStatusCode());
        if (isset($options['multipart'])) {
            $body = $request->getBody();
            $this->assertInstanceOf(MultipartStream::class, $body);
            $this->assertGreaterThan(0, $body->getSize());
            $this->assertNotEmpty($header = $request->getHeaderLine('Content-Type'));
            $this->assertContains('multipart/form-data', $header);
            unset($options['headers']['Content-Type']);
        }
        if (isset($options['file'])) {
            $body = $request->getBody();
            $this->assertInstanceOf(LazyOpenStream::class, $body);
            $this->assertGreaterThan(0, $body->getSize());
            $this->assertEquals($options['file'], $body->getMetadata('uri'));
            $this->assertNotEmpty($header = $request->getHeaderLine('Content-Type'));
            $this->assertEquals('application/binary', $header);
            unset($options['headers']['Content-Type']);
        }
        if (isset($options['headers']) && is_array($options['headers'])) {
            foreach ($options['headers'] as $headerKey => $value) {
                if ($value) {
                    $this->assertNotEmpty($header = $request->getHeaderLine($headerKey));
                    $this->assertEquals($value, $header);
                }
            }
        }
        if (isset($options['method'])) {
            $this->assertEquals($options['method'], $request->getMethod());
        }
        if (isset($options['endpoint'])) {
            // Truncate the base path from the target
            $apiBasePath = "/{$this->client->getApiBasePath()}";
            $endpoint = preg_replace('/^' . preg_quote($apiBasePath, '/') . '/', '', $request->getUri()->getPath());
            $this->assertEquals($options['endpoint'], $endpoint);
        }
        if (isset($options['queryParams'])) {
            $expectedQueryParams = urldecode(http_build_query($options['queryParams']));
            $this->assertEquals($expectedQueryParams, $request->getUri()->getQuery());
        }
        if (isset($options['postFields'])) {
            $this->assertEquals(json_encode($options['postFields']), $request->getBody()->getContents());
        }
        if (isset($options['requestUri'])) {
            $this->assertEquals($options['requestUri'], $request->getUri()->__toString());
        }
    }