Skip to content

Commit 0b84968

Browse files
authored
Adds Unit Tests. Support for PHP 8.
* Added info about Laravel package * Adds unit tests * Adds workflow to run tests * Adds FIXERIO_API_KEY to env in github action
1 parent 34589c9 commit 0b84968

5 files changed

Lines changed: 115 additions & 0 deletions

File tree

.github/workflows/tests.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
tests:
9+
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: true
13+
matrix:
14+
php: [7.3, 7.4, 8.0]
15+
16+
name: Run Test (PHP ${{ matrix.php }})
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v2
21+
22+
- name: Setup PHP, with composer and extensions
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php }}
26+
extensions: dom, curl, libxml, mbstring, zip, fileinfo
27+
tools: composer:v2
28+
coverage: none
29+
30+
- name: Install dependencies
31+
run: |
32+
composer install --prefer-dist --no-interaction --no-progress
33+
- name: Execute tests
34+
run: vendor/bin/phpunit tests --verbose --testdox
35+
env:
36+
FIXERIO_API_KEY: ${{ secrets.FIXERIO_API_KEY }}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store
5+
Thumbs.db
6+
/phpunit.xml
7+
/.idea
8+
/.vscode
9+
.phpunit.result.cache

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
<p align="center">
2+
<a href="https://github.com/ranium/fixerio-php-client/actions">
3+
<img src="https://github.com/ranium/fixerio-php-client/workflows/tests/badge.svg" alt="Build Status">
4+
</a>
5+
<a href="https://packagist.org/packages/ranium/fixerio-php-client">
6+
<img src="https://img.shields.io/packagist/dt/ranium/fixerio-php-client" alt="Total Downloads">
7+
</a>
8+
<a href="https://packagist.org/packages/ranium/fixerio-php-client">
9+
<img src="https://img.shields.io/packagist/v/ranium/fixerio-php-client" alt="Latest Stable Version">
10+
</a>
11+
<a href="https://packagist.org/packages/ranium/fixerio-php-client">
12+
<img src="https://img.shields.io/packagist/l/ranium/fixerio-php-client" alt="License">
13+
</a>
14+
</p>
15+
116
# Fixer.io PHP Client
217

318
Provides an easy to use client for [fixer.io](https://fixer.io) exchange rates and currency conversion JSON API.
419

20+
*Looking for a Laravel package? Please use [ranium/laravel-fixerio](https://github.com/ranium/laravel-fixerio) instead of this library.*
21+
522
## Installation
623

724
This project can be installed using Composer:

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"psr-4": {
1919
"Ranium\\Fixerio\\": "src"
2020
}
21+
},
22+
"require-dev": {
23+
"phpunit/phpunit": "^9.5"
2124
}
2225
}

tests/FixerioTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php declare(strict_types=1);
2+
use PHPUnit\Framework\TestCase;
3+
use Ranium\Fixerio\Client;
4+
5+
final class FixerioTest extends TestCase
6+
{
7+
protected $fixerioApiKey;
8+
9+
protected function setUp(): void
10+
{
11+
$this->fixerioApiKey = getenv('FIXERIO_API_KEY');
12+
}
13+
14+
public function testCanBeCreatedFromAccessKey()
15+
{
16+
17+
$this->assertInstanceOf(
18+
Client::class,
19+
Client::create($this->fixerioApiKey)
20+
);
21+
}
22+
23+
public function testCanGetLatestRates()
24+
{
25+
$fixerio = Client::create($this->fixerioApiKey, false);
26+
27+
$latestRates = $fixerio->latest();
28+
29+
$this->assertFixerioResponse($latestRates);
30+
}
31+
32+
public function testCanGetHistoricalRates()
33+
{
34+
$fixerio = Client::create($this->fixerioApiKey, false);
35+
36+
$historicalRates = $fixerio->historical(
37+
[
38+
'date' => '2019-01-01',
39+
]
40+
);
41+
42+
$this->assertFixerioResponse($historicalRates);
43+
}
44+
45+
private function assertFixerioResponse($response)
46+
{
47+
$this->assertTrue($response['success']);
48+
$this->assertIsArray($response['rates']);
49+
}
50+
}

0 commit comments

Comments
 (0)