From 2adc756dac30b39f752328422c28fa516da92cdc Mon Sep 17 00:00:00 2001 From: Seth Phat Date: Mon, 17 Apr 2023 16:04:58 +0700 Subject: [PATCH] v1.0.0 --- .github/workflows/e2e.yml | 36 ----- .github/workflows/integration.yml | 36 ----- .github/workflows/unit.yml | 47 ------ .php-cs-fixer.php | 93 ----------- phpunit.xml | 28 ---- tests/E2E/E2ETestCase.php | 20 --- .../E2E/Services/CurrencyCloudServiceTest.php | 25 --- .../E2E/Services/CurrencyLayerServiceTest.php | 17 -- .../Services/ExchangerRateHostServiceTest.php | 17 -- .../ExchangerRatesApiIoServiceTest.php | 18 --- tests/E2E/Services/FixerIoServiceTest.php | 17 -- tests/Integration/IntegrationTestCase.php | 16 -- tests/Integration/Laravel/ContainerTest.php | 74 --------- tests/README.md | 10 -- .../Services/CurrencyCloudServiceTest.php | 147 ------------------ .../Services/CurrencyLayerServiceTest.php | 69 -------- .../Services/ExchangerRateHostServiceTest.php | 69 -------- .../ExchangerRatesApiIoServiceTest.php | 69 -------- tests/Unit/Services/FixerIoServiceTest.php | 69 -------- .../HttpClient/CurrencyFxClientTest.php | 63 -------- .../currency-cloud-auth-error.json | 33 ---- .../__fixtures__/currency-cloud-auth.json | 3 - .../currency-cloud-rate-error.json | 12 -- .../__fixtures__/currency-cloud-rate.json | 16 -- .../currency-layer-rate-error.json | 5 - .../__fixtures__/currency-layer-rate.json | 8 - .../exchanger-rate-host-rate-error.json | 5 - .../exchanger-rate-host-rate.json | 9 -- .../exchanger-rates-api-io-rate-error.json | 5 - .../exchanger-rates-api-io-rate.json | 9 -- .../__fixtures__/fixer-io-rate-error.json | 5 - tests/Unit/__fixtures__/fixer-io-rate.json | 9 -- 32 files changed, 1059 deletions(-) delete mode 100644 .github/workflows/e2e.yml delete mode 100644 .github/workflows/integration.yml delete mode 100644 .github/workflows/unit.yml delete mode 100644 .php-cs-fixer.php delete mode 100644 phpunit.xml delete mode 100644 tests/E2E/E2ETestCase.php delete mode 100644 tests/E2E/Services/CurrencyCloudServiceTest.php delete mode 100644 tests/E2E/Services/CurrencyLayerServiceTest.php delete mode 100644 tests/E2E/Services/ExchangerRateHostServiceTest.php delete mode 100644 tests/E2E/Services/ExchangerRatesApiIoServiceTest.php delete mode 100644 tests/E2E/Services/FixerIoServiceTest.php delete mode 100644 tests/Integration/IntegrationTestCase.php delete mode 100644 tests/Integration/Laravel/ContainerTest.php delete mode 100644 tests/README.md delete mode 100644 tests/Unit/Services/CurrencyCloudServiceTest.php delete mode 100644 tests/Unit/Services/CurrencyLayerServiceTest.php delete mode 100644 tests/Unit/Services/ExchangerRateHostServiceTest.php delete mode 100644 tests/Unit/Services/ExchangerRatesApiIoServiceTest.php delete mode 100644 tests/Unit/Services/FixerIoServiceTest.php delete mode 100644 tests/Unit/Services/HttpClient/CurrencyFxClientTest.php delete mode 100644 tests/Unit/__fixtures__/currency-cloud-auth-error.json delete mode 100644 tests/Unit/__fixtures__/currency-cloud-auth.json delete mode 100644 tests/Unit/__fixtures__/currency-cloud-rate-error.json delete mode 100644 tests/Unit/__fixtures__/currency-cloud-rate.json delete mode 100644 tests/Unit/__fixtures__/currency-layer-rate-error.json delete mode 100644 tests/Unit/__fixtures__/currency-layer-rate.json delete mode 100644 tests/Unit/__fixtures__/exchanger-rate-host-rate-error.json delete mode 100644 tests/Unit/__fixtures__/exchanger-rate-host-rate.json delete mode 100644 tests/Unit/__fixtures__/exchanger-rates-api-io-rate-error.json delete mode 100644 tests/Unit/__fixtures__/exchanger-rates-api-io-rate.json delete mode 100644 tests/Unit/__fixtures__/fixer-io-rate-error.json delete mode 100644 tests/Unit/__fixtures__/fixer-io-rate.json diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml deleted file mode 100644 index 36948a4..0000000 --- a/.github/workflows/e2e.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: E2E Test -env: - TESTING_ENV: ${{ secrets.TESTING_ENV }} - -on: - pull_request: - branches: - - 'main' - types: [ opened, synchronize, reopened, ready_for_review ] - push: - branches: - - 'main' - -jobs: - integration: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - if: success() - - - name: Setup PHP with coverage driver - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - coverage: pcov - - - name: Setup - if: success() - run: | - composer install --no-interaction - echo "$TESTING_ENV" > .env.testing - - - name: PHPUnit tests with coverage - if: success() - run: | - composer test-e2e \ No newline at end of file diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml deleted file mode 100644 index d1ead90..0000000 --- a/.github/workflows/integration.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Integration Test -env: - TESTING_ENV: ${{ secrets.TESTING_ENV }} - -on: - pull_request: - branches: - - 'main' - types: [ opened, synchronize, reopened, ready_for_review ] - push: - branches: - - 'main' - -jobs: - integration: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - if: success() - - - name: Setup PHP with coverage driver - uses: shivammathur/setup-php@v2 - with: - php-version: 8.1 - coverage: pcov - - - name: Setup - if: success() - run: | - composer install --no-interaction - echo "$TESTING_ENV" > .env.testing - - - name: PHPUnit tests with coverage - if: success() - run: | - composer test-integration \ No newline at end of file diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml deleted file mode 100644 index f74ef2f..0000000 --- a/.github/workflows/unit.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Unit Test (PHP 8.1, 8.2) -env: - TESTING_ENV: ${{ secrets.TESTING_ENV }} - -on: - pull_request: - branches: - - 'main' - types: [ opened, synchronize, reopened, ready_for_review ] - push: - branches: - - 'main' - -jobs: - unit: - strategy: - fail-fast: false - matrix: - version: [ '8.1', '8.2' ] - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - if: success() - - - name: Setup PHP with coverage driver - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.version }} - coverage: pcov - - - name: Setup - if: success() - run: | - composer install --no-interaction - echo "$TESTING_ENV" > .env.testing - - - name: PHPUnit tests with coverage - if: success() - run: | - composer test-coverage - - - name: upload coverage to codecov.io - if: success() && matrix.version == '8.1' - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - file: ./coverage.xml diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php deleted file mode 100644 index 6887cde..0000000 --- a/.php-cs-fixer.php +++ /dev/null @@ -1,93 +0,0 @@ -in([ - __DIR__ . '/src/', - __DIR__ . '/tests/', - ]); - -$config = new Config(); - -return $config->setFinder($finder) - ->setRules([ - '@PSR12' => true, - 'array_syntax' => ['syntax' => 'short'], - 'combine_consecutive_unsets' => true, - 'multiline_whitespace_before_semicolons' => true, - 'single_quote' => true, - 'binary_operator_spaces' => ['default' => 'single_space'], - 'blank_line_before_statement' => ['statements' => ['return']], - 'braces' => [ - 'allow_single_line_closure' => true, - 'position_after_anonymous_constructs' => 'same', - 'position_after_control_structures' => 'same', - 'position_after_functions_and_oop_constructs' => 'next', - ], - 'combine_consecutive_issets' => true, - 'class_attributes_separation' => ['elements' => ['method' => 'one']], - 'concat_space' => ['spacing' => 'one'], - 'include' => true, - 'no_extra_blank_lines' => [ - 'tokens' => [ - 'curly_brace_block', - 'extra', - 'parenthesis_brace_block', - 'square_brace_block', - 'throw', - 'use', - ], - ], - 'no_multiline_whitespace_around_double_arrow' => true, - 'no_spaces_around_offset' => true, - 'no_unused_imports' => true, - 'no_whitespace_before_comma_in_array' => true, - 'object_operator_without_whitespace' => true, - 'php_unit_fqcn_annotation' => true, - 'phpdoc_no_package' => true, - 'phpdoc_scalar' => true, - 'phpdoc_single_line_var_spacing' => true, - 'protected_to_private' => true, - 'return_assignment' => true, - 'no_useless_return' => true, - 'simplified_null_return' => true, - 'single_line_after_imports' => true, - 'single_line_comment_style' => ['comment_types' => ['hash']], - 'single_class_element_per_statement' => true, - 'trailing_comma_in_multiline' => ['elements' => ['arrays']], - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'whitespace_after_comma_in_array' => true, - 'no_null_property_initialization' => true, - - 'function_typehint_space' => true, - 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], - 'no_empty_statement' => true, - 'no_leading_namespace_whitespace' => true, - 'return_type_declaration' => ['space_before' => 'none'], - - 'method_chaining_indentation' => true, - 'align_multiline_comment' => ['comment_type' => 'all_multiline'], - 'no_superfluous_phpdoc_tags' => [ - 'allow_mixed' => false, - 'remove_inheritdoc' => false, - 'allow_unused_params' => false, - ], - 'phpdoc_trim_consecutive_blank_line_separation' => true, - 'phpdoc_trim' => true, - 'no_empty_phpdoc' => true, - 'clean_namespace' => true, - 'array_indentation' => true, - 'elseif' => true, - 'phpdoc_order' => true, - 'global_namespace_import' => [ - 'import_classes' => true, - 'import_constants' => false, - 'import_functions' => false, - ], - 'fully_qualified_strict_types' => true, - 'no_leading_import_slash' => true, - ]) - ->setLineEnding("\n"); diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 92f178b..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - ./tests/Unit - - - ./tests/Integration - ./tests/Integration/IntegrationTestCase.php - - - ./tests/E2E - ./tests/E2E/E2ETestCase.php - - - - - ./src - - - ./src/Contracts - ./src/Enums - ./src/Laravel/Configs - ./src/Laravel/CurrencyFxServiceProvider.php - - - diff --git a/tests/E2E/E2ETestCase.php b/tests/E2E/E2ETestCase.php deleted file mode 100644 index 0a4c5db..0000000 --- a/tests/E2E/E2ETestCase.php +++ /dev/null @@ -1,20 +0,0 @@ -load(); - } -} \ No newline at end of file diff --git a/tests/E2E/Services/CurrencyCloudServiceTest.php b/tests/E2E/Services/CurrencyCloudServiceTest.php deleted file mode 100644 index 1b54b59..0000000 --- a/tests/E2E/Services/CurrencyCloudServiceTest.php +++ /dev/null @@ -1,25 +0,0 @@ -utc()->isWeekend()) { - $this->markTestSkipped('CurrencyCloud does not support get rates on weekend'); - } - - $rateUsd = app(CurrencyCloudService::class)->getRates('USD', 'SGD'); - - $this->assertTrue($rateUsd->isOk()); - $this->assertGreaterThan(1, $rateUsd->getOkResult()->rate); - - $rateSgd = app(CurrencyCloudService::class)->getRates('SGD', 'USD'); - $this->assertTrue($rateSgd->isOk()); - $this->assertLessThanOrEqual(1, $rateSgd->getOkResult()->rate); - } -} \ No newline at end of file diff --git a/tests/E2E/Services/CurrencyLayerServiceTest.php b/tests/E2E/Services/CurrencyLayerServiceTest.php deleted file mode 100644 index c2a0150..0000000 --- a/tests/E2E/Services/CurrencyLayerServiceTest.php +++ /dev/null @@ -1,17 +0,0 @@ -getRates('USD', 'GBP'); - - $this->assertTrue($rate->isOk()); - $this->assertLessThanOrEqual(1, $rate->getOkResult()->rate); - } -} \ No newline at end of file diff --git a/tests/E2E/Services/ExchangerRateHostServiceTest.php b/tests/E2E/Services/ExchangerRateHostServiceTest.php deleted file mode 100644 index f450180..0000000 --- a/tests/E2E/Services/ExchangerRateHostServiceTest.php +++ /dev/null @@ -1,17 +0,0 @@ -getRates('USD', 'GBP'); - - $this->assertTrue($rate->isOk()); - $this->assertLessThanOrEqual(1, $rate->getOkResult()->rate); - } -} \ No newline at end of file diff --git a/tests/E2E/Services/ExchangerRatesApiIoServiceTest.php b/tests/E2E/Services/ExchangerRatesApiIoServiceTest.php deleted file mode 100644 index cbd1edd..0000000 --- a/tests/E2E/Services/ExchangerRatesApiIoServiceTest.php +++ /dev/null @@ -1,18 +0,0 @@ -getRates('USD', 'VND'); - - $this->assertTrue($rate->isOk()); - $this->assertGreaterThan(22_000, $rate->getOkResult()->rate); - } -} \ No newline at end of file diff --git a/tests/E2E/Services/FixerIoServiceTest.php b/tests/E2E/Services/FixerIoServiceTest.php deleted file mode 100644 index 34cdac2..0000000 --- a/tests/E2E/Services/FixerIoServiceTest.php +++ /dev/null @@ -1,17 +0,0 @@ -getRates('USD', 'JPY'); - - $this->assertTrue($rate->isOk()); - $this->assertGreaterThan(50, $rate->getOkResult()->rate); - } -} \ No newline at end of file diff --git a/tests/Integration/IntegrationTestCase.php b/tests/Integration/IntegrationTestCase.php deleted file mode 100644 index ce91c4f..0000000 --- a/tests/Integration/IntegrationTestCase.php +++ /dev/null @@ -1,16 +0,0 @@ -artisan('about') - ->expectsOutputToContain('ShipSaaS/Currency-FX') - ->expectsOutputToContain(CurrencyFx::VERSION); - } - - public function testContainerReturnsTheBoundCurrencyCloudService() - { - config([ - 'currency-fx.drivers.currencycloud.api-key' => 'test', - 'currency-fx.drivers.currencycloud.login-id' => 'me@sethphat.dev', - ]); - $service = app(CurrencyCloudService::class); - - $this->assertNotNull($service); - $this->assertInstanceOf(CurrencyCloudService::class, $service); - } - - public function testContainerReturnsTheBoundCurrencyLayerService() - { - config([ - 'currency-fx.drivers.currencylayer.api-key' => 'test', - ]); - $service = app(CurrencyLayerService::class); - - $this->assertNotNull($service); - $this->assertInstanceOf(CurrencyLayerService::class, $service); - } - - public function testContainerReturnsTheBoundFixerIoService() - { - config([ - 'currency-fx.drivers.fixer-io.api-key' => 'test', - ]); - $service = app(FixerIoService::class); - - $this->assertNotNull($service); - $this->assertInstanceOf(FixerIoService::class, $service); - } - - public function testContainerReturnsTheBoundExchangeRateHostService() - { - $service = app(ExchangerRateHostService::class); - - $this->assertNotNull($service); - $this->assertInstanceOf(ExchangerRateHostService::class, $service); - } - - public function testContainerReturnsTheBoundExchangeRatesApiIoService() - { - config([ - 'currency-fx.drivers.exchangeratesapi-io.api-key' => 'test', - ]); - $service = app(ExchangerRatesApiIoService::class); - - $this->assertNotNull($service); - $this->assertInstanceOf(ExchangerRatesApiIoService::class, $service); - } -} \ No newline at end of file diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index b108eed..0000000 --- a/tests/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# CurrencyFX Tests - -We provided 3 kind of tests: - -- Unit tests: test methods using mocked data. - - Will run against PHP 8.1 & 8.2 -- Integration tests: to ensure our package is compatible with Laravel project. - - Will run against PHP 8.1 + Laravel 10 -- E2E tests: run real test cases against the LIVE services - - This helps us to ensure our services are working correctly & 100% reliable. \ No newline at end of file diff --git a/tests/Unit/Services/CurrencyCloudServiceTest.php b/tests/Unit/Services/CurrencyCloudServiceTest.php deleted file mode 100644 index 4d5cd3d..0000000 --- a/tests/Unit/Services/CurrencyCloudServiceTest.php +++ /dev/null @@ -1,147 +0,0 @@ -service = new CurrencyCloudService( - 'https://devapi.currencycloud.com', - 'fake-login', - 'fake-api' - ); - $this->httpClient = $this->createMock(CurrencyFxClient::class); - - $reflectorHttpClient = new ReflectionProperty($this->service, 'httpClient'); - $reflectorHttpClient->setAccessible(true); - $reflectorHttpClient->setValue($this->service, $this->httpClient); - } - - public function testGetRatesReturnsErrorDueToAuthenticationFailed() - { - $response = new ClientResponse(); - $response->isOk = false; - $response->statusCode = 400; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-cloud-auth-error.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'GBP'); - - $this->assertFalse($rateResult->isOk()); - $this->assertSame(GetRateErrorOutcome::AUTHENTICATION_FAILED, $rateResult->getErrorResult()->outcome); - } - - public function testGetRatesReturnsErrorDueToFailedToRetrieveFromCurrencyCloud() - { - $authResponse = new ClientResponse(); - $authResponse->isOk = true; - $authResponse->statusCode = 200; - $authResponse->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-cloud-auth.json'), - true - ); - - $rateResponse = new ClientResponse(); - $rateResponse->isOk = false; - $rateResponse->statusCode = 400; - $rateResponse->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-cloud-rate-error.json'), - true - ); - - $this->httpClient->expects($this->exactly(2)) - ->method('request') - ->willReturnOnConsecutiveCalls( - $authResponse, - $rateResponse - ); - - $rateResult = $this->service->getRates('USD', 'GBP'); - - $this->assertFalse($rateResult->isOk()); - $this->assertSame(GetRateErrorOutcome::RETRIEVE_RATE_FAILED, $rateResult->getErrorResult()->outcome); - } - - public function testGetRateReturnsOkResponseWithRate() - { - $authResponse = new ClientResponse(); - $authResponse->isOk = true; - $authResponse->statusCode = 200; - $authResponse->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-cloud-auth.json'), - true - ); - - $rateResponse = new ClientResponse(); - $rateResponse->isOk = true; - $rateResponse->statusCode = 200; - $rateResponse->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-cloud-rate.json'), - true - ); - - $this->httpClient->expects($this->exactly(2)) - ->method('request') - ->willReturnOnConsecutiveCalls( - $authResponse, - $rateResponse - ); - - $rateResult = $this->service->getRates('USD', 'GBP'); - - $this->assertTrue($rateResult->isOk()); - $this->assertSame(0.710227, $rateResult->getOkResult()->rate); - } - - public function testGetRateMultipleTimesWontDoAuthMultipleTimes() - { - $authResponse = new ClientResponse(); - $authResponse->isOk = true; - $authResponse->statusCode = 200; - $authResponse->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-cloud-auth.json'), - true - ); - - $rateResponse = new ClientResponse(); - $rateResponse->isOk = true; - $rateResponse->statusCode = 200; - $rateResponse->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-cloud-rate.json'), - true - ); - - $this->httpClient->expects($this->exactly(3)) - ->method('request') - ->willReturnOnConsecutiveCalls( - $authResponse, - $rateResponse, - $rateResponse - ); - - $rateResult = $this->service->getRates('USD', 'GBP'); - $this->assertTrue($rateResult->isOk()); - $this->assertSame(0.710227, $rateResult->getOkResult()->rate); - - $rateResult = $this->service->getRates('USD', 'GBP'); - $this->assertTrue($rateResult->isOk()); - $this->assertSame(0.710227, $rateResult->getOkResult()->rate); - } -} \ No newline at end of file diff --git a/tests/Unit/Services/CurrencyLayerServiceTest.php b/tests/Unit/Services/CurrencyLayerServiceTest.php deleted file mode 100644 index 7e9dcbe..0000000 --- a/tests/Unit/Services/CurrencyLayerServiceTest.php +++ /dev/null @@ -1,69 +0,0 @@ -service = new CurrencyLayerService( - 'https://api.apilayer.com/currency_data', - 'fake' - ); - $this->httpClient = $this->createMock(CurrencyFxClient::class); - - $reflectorHttpClient = new ReflectionProperty($this->service, 'httpClient'); - $reflectorHttpClient->setAccessible(true); - $reflectorHttpClient->setValue($this->service, $this->httpClient); - } - - public function testGetRatesReturnsRate() - { - $response = new ClientResponse(); - $response->isOk = true; - $response->statusCode = 200; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-layer-rate.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'AUD'); - - $this->assertTrue($rateResult->isOk()); - $this->assertSame(1.278342, $rateResult->getOkResult()->rate); - } - - public function testGetRatesReturnsError() - { - $response = new ClientResponse(); - $response->isOk = false; - $response->statusCode = 400; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/currency-layer-rate-error.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'AUD'); - - $this->assertFalse($rateResult->isOk()); - $this->assertSame(GetRateErrorOutcome::RETRIEVE_RATE_FAILED, $rateResult->getErrorResult()->outcome); - } -} \ No newline at end of file diff --git a/tests/Unit/Services/ExchangerRateHostServiceTest.php b/tests/Unit/Services/ExchangerRateHostServiceTest.php deleted file mode 100644 index 1b49a73..0000000 --- a/tests/Unit/Services/ExchangerRateHostServiceTest.php +++ /dev/null @@ -1,69 +0,0 @@ -service = new ExchangerRateHostService( - 'https://api.exchangerate.host/latest', - 'fake' - ); - $this->httpClient = $this->createMock(CurrencyFxClient::class); - - $reflectorHttpClient = new ReflectionProperty($this->service, 'httpClient'); - $reflectorHttpClient->setAccessible(true); - $reflectorHttpClient->setValue($this->service, $this->httpClient); - } - - public function testGetRatesReturnsRate() - { - $response = new ClientResponse(); - $response->isOk = true; - $response->statusCode = 200; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/exchanger-rate-host-rate.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'GBP'); - - $this->assertTrue($rateResult->isOk()); - $this->assertSame(0.72007, $rateResult->getOkResult()->rate); - } - - public function testGetRatesReturnsError() - { - $response = new ClientResponse(); - $response->isOk = false; - $response->statusCode = 400; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/exchanger-rate-host-rate-error.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'GBP'); - - $this->assertFalse($rateResult->isOk()); - $this->assertSame(GetRateErrorOutcome::RETRIEVE_RATE_FAILED, $rateResult->getErrorResult()->outcome); - } -} \ No newline at end of file diff --git a/tests/Unit/Services/ExchangerRatesApiIoServiceTest.php b/tests/Unit/Services/ExchangerRatesApiIoServiceTest.php deleted file mode 100644 index 529ab2c..0000000 --- a/tests/Unit/Services/ExchangerRatesApiIoServiceTest.php +++ /dev/null @@ -1,69 +0,0 @@ -service = new ExchangerRatesApiIoService( - 'https://api.exchangerate.host/latest', - 'fake' - ); - $this->httpClient = $this->createMock(CurrencyFxClient::class); - - $reflectorHttpClient = new ReflectionProperty($this->service, 'httpClient'); - $reflectorHttpClient->setAccessible(true); - $reflectorHttpClient->setValue($this->service, $this->httpClient); - } - - public function testGetRatesReturnsRate() - { - $response = new ClientResponse(); - $response->isOk = true; - $response->statusCode = 200; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/exchanger-rates-api-io-rate.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'JPY'); - - $this->assertTrue($rateResult->isOk()); - $this->assertSame(107.346001, $rateResult->getOkResult()->rate); - } - - public function testGetRatesReturnsError() - { - $response = new ClientResponse(); - $response->isOk = false; - $response->statusCode = 400; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/exchanger-rates-api-io-rate-error.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'JPY'); - - $this->assertFalse($rateResult->isOk()); - $this->assertSame(GetRateErrorOutcome::RETRIEVE_RATE_FAILED, $rateResult->getErrorResult()->outcome); - } -} \ No newline at end of file diff --git a/tests/Unit/Services/FixerIoServiceTest.php b/tests/Unit/Services/FixerIoServiceTest.php deleted file mode 100644 index e5b3e48..0000000 --- a/tests/Unit/Services/FixerIoServiceTest.php +++ /dev/null @@ -1,69 +0,0 @@ -service = new FixerIoService( - 'https://api.exchangerate.host/latest', - 'fake' - ); - $this->httpClient = $this->createMock(CurrencyFxClient::class); - - $reflectorHttpClient = new ReflectionProperty($this->service, 'httpClient'); - $reflectorHttpClient->setAccessible(true); - $reflectorHttpClient->setValue($this->service, $this->httpClient); - } - - public function testGetRatesReturnsRate() - { - $response = new ClientResponse(); - $response->isOk = true; - $response->statusCode = 200; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/fixer-io-rate.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'EUR'); - - $this->assertTrue($rateResult->isOk()); - $this->assertSame(0.813399, $rateResult->getOkResult()->rate); - } - - public function testGetRatesReturnsError() - { - $response = new ClientResponse(); - $response->isOk = false; - $response->statusCode = 400; - $response->response = json_decode( - file_get_contents(__DIR__ . '/../__fixtures__/fixer-io-rate-error.json'), - true - ); - - $this->httpClient->expects($this->once()) - ->method('request') - ->willReturn($response); - - $rateResult = $this->service->getRates('USD', 'EUR'); - - $this->assertFalse($rateResult->isOk()); - $this->assertSame(GetRateErrorOutcome::RETRIEVE_RATE_FAILED, $rateResult->getErrorResult()->outcome); - } -} \ No newline at end of file diff --git a/tests/Unit/Services/HttpClient/CurrencyFxClientTest.php b/tests/Unit/Services/HttpClient/CurrencyFxClientTest.php deleted file mode 100644 index c2c7fed..0000000 --- a/tests/Unit/Services/HttpClient/CurrencyFxClientTest.php +++ /dev/null @@ -1,63 +0,0 @@ -assertNotNull($client); - $this->assertInstanceOf(CurrencyFxClient::class, $client); - } - - public function testRequestReturnsSuccessResponse() - { - $mock = new MockHandler([ - new Response(200, [], '{"ok": true}'), - ]); - - $client = CurrencyFxClient::getClient('https://github.com/shipsaas', [], [ - 'handler' => $mock, - ]); - - $response = $client->request('GET', 'health-check'); - - $this->assertTrue($response->isOk); - $this->assertSame(200, $response->statusCode); - $this->assertSame([ - 'ok' => true, - ], $response->response); - } - - public function testRequestReturnsErrorResponse() - { - $mock = new MockHandler([ - new ClientException( - 'Client Error', - new Request('GET', 'transfer'), - new Response(400, [], '{"ok": false}'), - ), - ]); - - $client = CurrencyFxClient::getClient('https://github.com/shipsaas', [], [ - 'handler' => $mock, - ]); - - $response = $client->request('GET', 'transfer'); - - $this->assertFalse($response->isOk); - $this->assertSame(400, $response->statusCode); - $this->assertSame([ - 'ok' => false, - ], $response->response); - } -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/currency-cloud-auth-error.json b/tests/Unit/__fixtures__/currency-cloud-auth-error.json deleted file mode 100644 index 12899b3..0000000 --- a/tests/Unit/__fixtures__/currency-cloud-auth-error.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "error_code": "auth_invalid_user_login_details", - "error_messages": { - "login_id": [ - { - "code": "login_id_is_required", - "message": "login_id is required", - "params": {} - }, - { - "code": "login_id_is_too_short", - "message": "login_id can not be shorter than 1 character(s)", - "params": { - "minlength": 1 - } - } - ], - "api_key": [ - { - "code": "api_key_is_required", - "message": "api_key is required", - "params": {} - }, - { - "code": "api_key_length_is_invalid", - "message": "api_key should be 64 character(s) long", - "params": { - "length": 64 - } - } - ] - } -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/currency-cloud-auth.json b/tests/Unit/__fixtures__/currency-cloud-auth.json deleted file mode 100644 index 4afa551..0000000 --- a/tests/Unit/__fixtures__/currency-cloud-auth.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "auth_token": "9307e7f58099731aa731ed3a6818807b" -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/currency-cloud-rate-error.json b/tests/Unit/__fixtures__/currency-cloud-rate-error.json deleted file mode 100644 index 7760f75..0000000 --- a/tests/Unit/__fixtures__/currency-cloud-rate-error.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "error_code": "rate_fetch_failed", - "error_messages": { - "base": [ - { - "code": "rate_could_not_be_retrieved", - "message": "Rate could not be retrieved", - "params": {} - } - ] - } -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/currency-cloud-rate.json b/tests/Unit/__fixtures__/currency-cloud-rate.json deleted file mode 100644 index 476bc2d..0000000 --- a/tests/Unit/__fixtures__/currency-cloud-rate.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "settlement_cut_off_time": "2022-02-02T15:00:00Z", - "currency_pair": "GBPUSD", - "client_buy_currency": "GBP", - "client_sell_currency": "USD", - "client_buy_amount": "100.0", - "client_sell_amount": "140.81", - "fixed_side": "buy", - "client_rate": "1.4081", - "partner_rate": null, - "core_rate": "1.4081", - "deposit_required": false, - "deposit_amount": "0.0", - "deposit_currency": "USD", - "mid_market_rate": "1.408" -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/currency-layer-rate-error.json b/tests/Unit/__fixtures__/currency-layer-rate-error.json deleted file mode 100644 index bb96865..0000000 --- a/tests/Unit/__fixtures__/currency-layer-rate-error.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "success": false, - "message": "Error", - "timestamp": 1519296206 -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/currency-layer-rate.json b/tests/Unit/__fixtures__/currency-layer-rate.json deleted file mode 100644 index f7ab1c2..0000000 --- a/tests/Unit/__fixtures__/currency-layer-rate.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "quotes": { - "USDAUD": 1.278342 - }, - "source": "USD", - "success": true, - "timestamp": 1432400348 -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/exchanger-rate-host-rate-error.json b/tests/Unit/__fixtures__/exchanger-rate-host-rate-error.json deleted file mode 100644 index bb96865..0000000 --- a/tests/Unit/__fixtures__/exchanger-rate-host-rate-error.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "success": false, - "message": "Error", - "timestamp": 1519296206 -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/exchanger-rate-host-rate.json b/tests/Unit/__fixtures__/exchanger-rate-host-rate.json deleted file mode 100644 index 025d89c..0000000 --- a/tests/Unit/__fixtures__/exchanger-rate-host-rate.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "base": "USD", - "date": "2022-04-14", - "rates": { - "GBP": 0.72007 - }, - "success": true, - "timestamp": 1519296206 -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/exchanger-rates-api-io-rate-error.json b/tests/Unit/__fixtures__/exchanger-rates-api-io-rate-error.json deleted file mode 100644 index bb96865..0000000 --- a/tests/Unit/__fixtures__/exchanger-rates-api-io-rate-error.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "success": false, - "message": "Error", - "timestamp": 1519296206 -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/exchanger-rates-api-io-rate.json b/tests/Unit/__fixtures__/exchanger-rates-api-io-rate.json deleted file mode 100644 index 22c8340..0000000 --- a/tests/Unit/__fixtures__/exchanger-rates-api-io-rate.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "base": "USD", - "date": "2022-04-14", - "rates": { - "JPY": 107.346001 - }, - "success": true, - "timestamp": 1519296206 -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/fixer-io-rate-error.json b/tests/Unit/__fixtures__/fixer-io-rate-error.json deleted file mode 100644 index bb96865..0000000 --- a/tests/Unit/__fixtures__/fixer-io-rate-error.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "success": false, - "message": "Error", - "timestamp": 1519296206 -} \ No newline at end of file diff --git a/tests/Unit/__fixtures__/fixer-io-rate.json b/tests/Unit/__fixtures__/fixer-io-rate.json deleted file mode 100644 index 773c1d3..0000000 --- a/tests/Unit/__fixtures__/fixer-io-rate.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "base": "USD", - "date": "2022-04-14", - "rates": { - "EUR": 0.813399 - }, - "success": true, - "timestamp": 1519296206 -} \ No newline at end of file