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

namespace GoCardlessPro\Integration;

class TaxRatesIntegrationTest extends IntegrationTestBase
{
    public function testResourceModelExists()
    {
        $obj = new \GoCardlessPro\Resources\TaxRate(array());
        $this->assertNotNull($obj);
    }
    
    public function testTaxRatesList()
    {
        $fixture = $this->loadJsonFixture('tax_rates')->list;
        $this->stub_request($fixture);

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

        $body = $fixture->body->tax_rates;
    
        $records = $response->records;
        $this->assertInstanceOf('\GoCardlessPro\Core\ListResponse', $response);
        $this->assertInstanceOf('\GoCardlessPro\Resources\TaxRate', $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]->end_date)) {
                $this->assertEquals($body[$num]->end_date, $record->end_date);
            }
            
            if (isset($body[$num]->id)) {
                $this->assertEquals($body[$num]->id, $record->id);
            }
            
            if (isset($body[$num]->jurisdiction)) {
                $this->assertEquals($body[$num]->jurisdiction, $record->jurisdiction);
            }
            
            if (isset($body[$num]->percentage)) {
                $this->assertEquals($body[$num]->percentage, $record->percentage);
            }
            
            if (isset($body[$num]->start_date)) {
                $this->assertEquals($body[$num]->start_date, $record->start_date);
            }
            
            if (isset($body[$num]->type)) {
                $this->assertEquals($body[$num]->type, $record->type);
            }
            
        }

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

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

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

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

        $this->assertEquals($body->end_date, $response->end_date);
        $this->assertEquals($body->id, $response->id);
        $this->assertEquals($body->jurisdiction, $response->jurisdiction);
        $this->assertEquals($body->percentage, $response->percentage);
        $this->assertEquals($body->start_date, $response->start_date);
        $this->assertEquals($body->type, $response->type);
    

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

    
}
