/**
     * Test so 201 statuscode will update the location on the resource.
     *
     * @return void
     */
    public function testApplyPost201UpdatedLocation()
    {
        $curl = new Klarna_Checkout_HTTP_TransportStub;

        $payload = '{"flobadob":["bobcat","wookie"]}';
        $location = 'not localhost';

        $data = array(
            'code' => 201,
            'headers' => array('Location' => $location),
            'payload' => $payload
        );
        $curl->addResponse($data);

        $this->orderStub->parse(json_decode($payload, true));

        $expected = 'stnaeu\eu2341aoaaoae==';

        $this->digest->expects($this->once())
            ->method('create')
            ->with("{$payload}aboogie")
            ->will($this->returnValue($expected));

        $object = new Klarna_Checkout_BasicConnector(
            $curl,
            $this->digest,
            'aboogie'
        );

        $this->assertNull($this->orderStub->getLocation(), 'Original Location');

        $result = $object->apply('POST', $this->orderStub);

        $this->assertEquals($payload, $result->getData(), 'Response payload');
        $this->assertEquals(
            "Klarna {$expected}",
            $curl->request->getHeader('Authorization'),
            'Header'
        );

        $this->assertEquals(
            $location,
            $this->orderStub->getLocation(),
            'Location should have beet updated'
        );

        $this->assertEquals(
            json_decode($payload, true),
            $this->orderStub->marshal(),
            'The data on the resource should not be updated!'
        );

        $this->assertEquals(
            $this->orderStub->getContentType(),
            $curl->request->getHeader('Accept'),
            'Accept Content Type'
        );
    }
    /**
     * Test apply with a 200 code
     *
     * @return void
     */
    public function testApplyGet200()
    {
        $curl = new Klarna_Checkout_HTTP_TransportStub;

        $payload = '{"flobadob":["bobcat","wookie"]}';
        $data = array(
            'code' => 200,
            'headers' => array(),
            'payload' => $payload
        );
        $curl->addResponse($data);

        $expectedDigest = 'stnaeu\eu2341aoaaoae==';

        $this->digest->expects($this->once())
            ->method('create')
            ->with('aboogie')
            ->will($this->returnValue($expectedDigest));

        $object = new Klarna_Checkout_BasicConnector(
            $curl,
            $this->digest,
            'aboogie'
        );
        $result = $object->apply('GET', $this->orderStub);

        $this->assertEquals($payload, $result->getData(), 'Response payload');
        $this->assertEquals(
            "Klarna {$expectedDigest}",
            $curl->request->getHeader('Authorization'),
            'Header'
        );

        $this->assertEquals(
            json_decode($payload, true),
            $this->orderStub->marshal(),
            'Content'
        );

        $this->assertEquals(
            $this->orderStub->getContentType(),
            $curl->request->getHeader('Accept'),
            'Accept Content Type'
        );
    }
    /**
     * Get the data to use
     *
     * @param Klarna_Checkout_ResourceInterface $resource resource
     * @param array                             $options  Options
     *
     * @return array data to use for HTTP requests
     */
    protected function getData(
        Klarna_Checkout_ResourceInterface $resource, array $options
    ) {
        if (array_key_exists('data', $options)) {
            return $options['data'];
        }

        return $resource->marshal();
    }