<?php
//
// WARNING: Do not edit by hand, this file was generated by Crank:
// https://github.com/gocardless/crank
//

namespace GoCardlessPro\Integration;

class PayoutsIntegrationTest extends IntegrationTestBase
{
    public function testResourceModelExists()
    {
        $obj = new \GoCardlessPro\Resources\Payout(array());
        $this->assertNotNull($obj);
    }
    
    public function testPayoutsList()
    {
        $fixture = $this->loadJsonFixture('payouts')->list;
        $this->stub_request($fixture);

        $service = $this->client->payouts();
        $response = call_user_func_array(array($service, 'list'), (array)$fixture->url_params);

        $body = $fixture->body->payouts;
    
        $records = $response->records;
        $this->assertInstanceOf('\GoCardlessPro\Core\ListResponse', $response);
        $this->assertInstanceOf('\GoCardlessPro\Resources\Payout', $records[0]);
        if (!is_null($fixture->body) && property_exists($fixture->body, 'meta') && !is_null($fixture->body->meta)) {
            $this->assertEquals($fixture->body->meta->cursors->before, $response->before);
            $this->assertEquals($fixture->body->meta->cursors->after, $response->after);
        }
    

    
        foreach (range(0, count($body) - 1) as $num) {
            $record = $records[$num];
            
            if (isset($body[$num]->amount)) {
                $this->assertEquals($body[$num]->amount, $record->amount);
            }
            
            if (isset($body[$num]->arrival_date)) {
                $this->assertEquals($body[$num]->arrival_date, $record->arrival_date);
            }
            
            if (isset($body[$num]->created_at)) {
                $this->assertEquals($body[$num]->created_at, $record->created_at);
            }
            
            if (isset($body[$num]->currency)) {
                $this->assertEquals($body[$num]->currency, $record->currency);
            }
            
            if (isset($body[$num]->deducted_fees)) {
                $this->assertEquals($body[$num]->deducted_fees, $record->deducted_fees);
            }
            
            if (isset($body[$num]->fx)) {
                $this->assertEquals($body[$num]->fx, $record->fx);
            }
            
            if (isset($body[$num]->id)) {
                $this->assertEquals($body[$num]->id, $record->id);
            }
            
            if (isset($body[$num]->links)) {
                $this->assertEquals($body[$num]->links, $record->links);
            }
            
            if (isset($body[$num]->metadata)) {
                $this->assertEquals($body[$num]->metadata, $record->metadata);
            }
            
            if (isset($body[$num]->payout_type)) {
                $this->assertEquals($body[$num]->payout_type, $record->payout_type);
            }
            
            if (isset($body[$num]->reference)) {
                $this->assertEquals($body[$num]->reference, $record->reference);
            }
            
            if (isset($body[$num]->status)) {
                $this->assertEquals($body[$num]->status, $record->status);
            }
            
            if (isset($body[$num]->tax_currency)) {
                $this->assertEquals($body[$num]->tax_currency, $record->tax_currency);
            }
            
        }

        $expectedPathRegex = $this->extract_resource_fixture_path_regex($fixture);
        $dispatchedRequest = $this->history[0]['request'];
        $this->assertMatchesRegularExpression($expectedPathRegex, $dispatchedRequest->getUri()->getPath());
    }

    
    public function testPayoutsGet()
    {
        $fixture = $this->loadJsonFixture('payouts')->get;
        $this->stub_request($fixture);

        $service = $this->client->payouts();
        $response = call_user_func_array(array($service, 'get'), (array)$fixture->url_params);

        $body = $fixture->body->payouts;
    
        $this->assertInstanceOf('\GoCardlessPro\Resources\Payout', $response);

        $this->assertEquals($body->amount, $response->amount);
        $this->assertEquals($body->arrival_date, $response->arrival_date);
        $this->assertEquals($body->created_at, $response->created_at);
        $this->assertEquals($body->currency, $response->currency);
        $this->assertEquals($body->deducted_fees, $response->deducted_fees);
        $this->assertEquals($body->fx, $response->fx);
        $this->assertEquals($body->id, $response->id);
        $this->assertEquals($body->links, $response->links);
        $this->assertEquals($body->metadata, $response->metadata);
        $this->assertEquals($body->payout_type, $response->payout_type);
        $this->assertEquals($body->reference, $response->reference);
        $this->assertEquals($body->status, $response->status);
        $this->assertEquals($body->tax_currency, $response->tax_currency);
    

        $expectedPathRegex = $this->extract_resource_fixture_path_regex($fixture);
        $dispatchedRequest = $this->history[0]['request'];
        $this->assertMatchesRegularExpression($expectedPathRegex, $dispatchedRequest->getUri()->getPath());
    }

    
    public function testPayoutsUpdate()
    {
        $fixture = $this->loadJsonFixture('payouts')->update;
        $this->stub_request($fixture);

        $service = $this->client->payouts();
        $response = call_user_func_array(array($service, 'update'), (array)$fixture->url_params);

        $body = $fixture->body->payouts;
    
        $this->assertInstanceOf('\GoCardlessPro\Resources\Payout', $response);

        $this->assertEquals($body->amount, $response->amount);
        $this->assertEquals($body->arrival_date, $response->arrival_date);
        $this->assertEquals($body->created_at, $response->created_at);
        $this->assertEquals($body->currency, $response->currency);
        $this->assertEquals($body->deducted_fees, $response->deducted_fees);
        $this->assertEquals($body->fx, $response->fx);
        $this->assertEquals($body->id, $response->id);
        $this->assertEquals($body->links, $response->links);
        $this->assertEquals($body->metadata, $response->metadata);
        $this->assertEquals($body->payout_type, $response->payout_type);
        $this->assertEquals($body->reference, $response->reference);
        $this->assertEquals($body->status, $response->status);
        $this->assertEquals($body->tax_currency, $response->tax_currency);
    

        $expectedPathRegex = $this->extract_resource_fixture_path_regex($fixture);
        $dispatchedRequest = $this->history[0]['request'];
        $this->assertMatchesRegularExpression($expectedPathRegex, $dispatchedRequest->getUri()->getPath());
    }

    
}
