Skip to content

Commit

Permalink
Merge pull request #46 from makstech/php_8_support
Browse files Browse the repository at this point in the history
PHP 8 support
  • Loading branch information
sethobey authored Sep 8, 2022
2 parents 9211e41 + 87fe4c1 commit 44722fb
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 399 deletions.
20 changes: 3 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
language: php

dist: trusty

php:
- 7.1
- 7.2
- 7.3
- 7.4

env:
- HTTPMOCK_VERSION="^0.13.0"

matrix:
include:
- php: 5.5
env: HTTPMOCK_VERSION="0.10.1"
- php: 5.6
env: HTTPMOCK_VERSION="0.10.1"
- php: 7.0
env: HTTPMOCK_VERSION="0.10.1"
- 8.0
- 8.1.0

before_script:
- composer self-update
- composer require "internations/http-mock:${HTTPMOCK_VERSION}" --no-update
- composer install

script: php vendor/bin/phpunit test/specs/.
script: composer tests
19 changes: 14 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@
}
],
"require": {
"php": ">=5.5.0",
"php": "^7.2|^8.0",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.0.2|^7.0.1"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
"internations/http-mock": "^0.13.0",
"silex/silex": "2.2.2"
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": { "TaxJar\\" : "lib/" }
"psr-4": {
"TaxJar\\" : "lib/"
}
},
"autoload-dev": {
"psr-4": {
"TaxJar\\Tests\\": "test/"
}
},
"scripts": {
"tests": "phpunit"
}
}
5 changes: 0 additions & 5 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ public static function withApiKey($key)
return new Client($key);
}

public function __construct($key)
{
parent::__construct($key);
}

/**
* Get tax categories
* https://developers.taxjar.com/api/reference/?php#get-list-tax-categories
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap = "vendor/autoload.php"
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false">

<testsuites>
<testsuite name="taxjar-php">
<directory>test</directory>
</testsuite>
</testsuites>
</phpunit>
40 changes: 20 additions & 20 deletions test/TaxJarTest.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
<?php
require 'vendor/autoload.php';

class TaxJarTest extends PHPUnit_Framework_TestCase
namespace TaxJar\Tests;

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use PHPUnit\Framework\TestCase;
use TaxJar\Client;

abstract class TaxJarTest extends TestCase
{
protected $client;
protected $history = [];

use \InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
/** @var MockHandler */
protected $http;

public static function setUpBeforeClass()
{
static::setUpHttpMockBeforeClass('8082', 'localhost');
}
/** @var Client */
protected $client;

public static function tearDownAfterClass()
public function setUp(): void
{
static::tearDownHttpMockAfterClass();
}
$this->http = new MockHandler();
$handler = HandlerStack::create($this->http);
$handler->push(Middleware::history($this->history));

public function setUp()
{
$this->setUpHttpMock();
$this->client = TaxJar\Client::withApiKey('test');
$this->client = Client::withApiKey('test');
$this->client->setApiConfig('handler', $handler);
$this->client->setApiConfig('base_uri', 'http://localhost:8082');
}

public function tearDown()
{
$this->tearDownHttpMock();
}
}
27 changes: 14 additions & 13 deletions test/specs/CategoryTest.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?php
if (!class_exists('TaxJarTest')) {
require __DIR__ . '/../TaxJarTest.php';
}

namespace TaxJar\Tests\specs;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use TaxJar\Tests\TaxJarTest;

class CategoryTest extends TaxJarTest
{
public function testCategories()
{
$this->http->mock
->when()
->methodIs('GET')
->pathIs('/categories')
->then()
->statusCode(200)
->body(file_get_contents(__DIR__ . "/../fixtures/categories.json"))
->end();

$this->http->setUp();
$this->http->append(new Response(200, [], file_get_contents(__DIR__ . "/../fixtures/categories.json")));

$response = $this->client->categories();

$this->assertCount(1, $this->history);

/** @var Request $request */
$request = reset($this->history)['request'];
$this->assertSame('GET', $request->getMethod());
$this->assertSame('/categories', $request->getUri()->getPath());

$this->assertJsonStringEqualsJsonFile(__DIR__ . '/../fixtures/categories.json', json_encode([
"categories" => $response
]));
Expand Down
7 changes: 4 additions & 3 deletions test/specs/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
if (!class_exists('TaxJarTest')) {
require __DIR__ . '/../TaxJarTest.php';
}

namespace TaxJar\Tests\specs;

use TaxJar\Tests\TaxJarTest;

class ConfigTest extends TaxJarTest
{
Expand Down
99 changes: 46 additions & 53 deletions test/specs/CustomerTest.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,52 @@
<?php
if (!class_exists('TaxJarTest')) {
require __DIR__ . '/../TaxJarTest.php';
}

namespace TaxJar\Tests\specs;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use TaxJar\Tests\TaxJarTest;

class CustomerTest extends TaxJarTest
{
public function testListCustomers()
{
$this->http->mock
->when()
->methodIs('GET')
->pathIs('/customers')
->then()
->statusCode(200)
->body(file_get_contents(__DIR__ . "/../fixtures/customers/list.json"))
->end();

$this->http->setUp();
$this->http->append(new Response(200, [], file_get_contents(__DIR__ . "/../fixtures/customers/list.json")));

$response = $this->client->listCustomers();

$this->assertCount(1, $this->history);

/** @var Request $request */
$request = reset($this->history)['request'];
$this->assertSame('GET', $request->getMethod());
$this->assertSame('/customers', $request->getUri()->getPath());

$this->assertJsonStringEqualsJsonFile(__DIR__ . '/../fixtures/customers/list.json', json_encode([
"customers" => $response
]));
}

public function testShowCustomer()
{
$this->http->mock
->when()
->methodIs('GET')
->pathIs('/customers/123')
->then()
->statusCode(200)
->body(file_get_contents(__DIR__ . "/../fixtures/customers/show.json"))
->end();

$this->http->setUp();
$this->http->append(new Response(200, [], file_get_contents(__DIR__ . "/../fixtures/customers/show.json")));

$response = $this->client->showCustomer(123);

$this->assertCount(1, $this->history);

/** @var Request $request */
$request = reset($this->history)['request'];
$this->assertSame('GET', $request->getMethod());
$this->assertSame('/customers/123', $request->getUri()->getPath());

$this->assertJsonStringEqualsJsonFile(__DIR__ . '/../fixtures/customers/show.json', json_encode([
"customer" => $response
]));
}

public function testCreateCustomer()
{
$this->http->mock
->when()
->methodIs('POST')
->pathIs('/customers')
->then()
->statusCode(201)
->body(file_get_contents(__DIR__ . "/../fixtures/customers/show.json"))
->end();

$this->http->setUp();
$this->http->append(new Response(201, [], file_get_contents(__DIR__ . "/../fixtures/customers/show.json")));

$response = $this->client->createCustomer([
'customer_id' => '123',
Expand All @@ -79,23 +69,21 @@ public function testCreateCustomer()
'street' => '1725 Slough Avenue'
]);

$this->assertCount(1, $this->history);

/** @var Request $request */
$request = reset($this->history)['request'];
$this->assertSame('POST', $request->getMethod());
$this->assertSame('/customers', $request->getUri()->getPath());

$this->assertJsonStringEqualsJsonFile(__DIR__ . '/../fixtures/customers/show.json', json_encode([
"customer" => $response
]));
}

public function testUpdateCustomer()
{
$this->http->mock
->when()
->methodIs('PUT')
->pathIs('/customers/123')
->then()
->statusCode(200)
->body(file_get_contents(__DIR__ . "/../fixtures/customers/show.json"))
->end();

$this->http->setUp();
$this->http->append(new Response(200, [], file_get_contents(__DIR__ . "/../fixtures/customers/show.json")));

$response = $this->client->updateCustomer([
'customer_id' => '123',
Expand All @@ -114,26 +102,31 @@ public function testUpdateCustomer()
'street' => '405 Madison Ave'
]);

$this->assertCount(1, $this->history);

/** @var Request $request */
$request = reset($this->history)['request'];
$this->assertSame('PUT', $request->getMethod());
$this->assertSame('/customers/123', $request->getUri()->getPath());

$this->assertJsonStringEqualsJsonFile(__DIR__ . '/../fixtures/customers/show.json', json_encode([
"customer" => $response
]));
}

public function testDeleteCustomer()
{
$this->http->mock
->when()
->methodIs('DELETE')
->pathIs('/customers/123')
->then()
->statusCode(200)
->body(file_get_contents(__DIR__ . "/../fixtures/customers/show.json"))
->end();

$this->http->setUp();
$this->http->append(new Response(200, [], file_get_contents(__DIR__ . "/../fixtures/customers/show.json")));

$response = $this->client->deleteCustomer(123);

$this->assertCount(1, $this->history);

/** @var Request $request */
$request = reset($this->history)['request'];
$this->assertSame('DELETE', $request->getMethod());
$this->assertSame('/customers/123', $request->getUri()->getPath());

$this->assertJsonStringEqualsJsonFile(__DIR__ . '/../fixtures/customers/show.json', json_encode([
"customer" => $response
]));
Expand Down
27 changes: 14 additions & 13 deletions test/specs/NexusRegionTest.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<?php
if (!class_exists('TaxJarTest')) {
require __DIR__ . '/../TaxJarTest.php';
}

namespace TaxJar\Tests\specs;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use TaxJar\Tests\TaxJarTest;

class NexusRegionTest extends TaxJarTest
{
public function testNexusRegions()
{
$this->http->mock
->when()
->methodIs('GET')
->pathIs('/nexus/regions')
->then()
->statusCode(200)
->body(file_get_contents(__DIR__ . "/../fixtures/nexus_regions.json"))
->end();

$this->http->setUp();
$this->http->append(new Response(200, [], file_get_contents(__DIR__ . "/../fixtures/nexus_regions.json")));

$response = $this->client->nexusRegions();

$this->assertCount(1, $this->history);

/** @var Request $request */
$request = reset($this->history)['request'];
$this->assertSame('GET', $request->getMethod());
$this->assertSame('/nexus/regions', $request->getUri()->getPath());

$this->assertJsonStringEqualsJsonFile(__DIR__ . '/../fixtures/nexus_regions.json', json_encode([
"regions" => $response,
]));
Expand Down
Loading

0 comments on commit 44722fb

Please sign in to comment.