Skip to content

Commit

Permalink
Merge pull request #18 from antistatique/feature/ci-tests-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
WengerK committed Jul 12, 2023
2 parents 5aae731 + 60523dc commit 9fb54fd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
25 changes: 15 additions & 10 deletions .github/workflows/cs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@2.12.0
uses: shivammathur/setup-php@v2
with:
tools: composer:v2
- uses: actions/checkout@v2
Expand All @@ -22,48 +22,53 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@2.12.0
uses: shivammathur/setup-php@v2
with:
tools: composer:v2, phpcpd
- name: Checkout
uses: actions/checkout@v2.3.4
- run: composer install --prefer-dist
- run: phpcpd ./ --exclude=vendor --exclude=bin --exclude=tests
- run: ./vendor/bin/phpcpd ./ --exclude=vendor --exclude=bin --exclude=tests

php-cs-fixer:
name: php-cs-fixer
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@2.12.0
uses: shivammathur/setup-php@v2
with:
tools: composer:v2, php-cs-fixer, cs2pr
- name: Checkout
uses: actions/checkout@v2.3.4
- run: composer install --prefer-dist
- run: php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --using-cache=no --format=checkstyle | cs2pr
- run: ./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -v --dry-run --using-cache=no --format=checkstyle | cs2pr

psalm:
name: psalm
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@2.12.0
with:
tools: composer:v2, psalm
uses: shivammathur/setup-php@v2
- uses: actions/checkout@v2
- run: composer install --prefer-dist
- run: psalm --config=psalm.xml --no-cache --output-format=github
- run: ./vendor/bin/psalm --output-format=github

tests:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2']
steps:
- name: Setup PHP
uses: shivammathur/setup-php@2.12.0
uses: shivammathur/setup-php@v2
with:
tools: composer:v2
php-version: ${{ matrix.php-versions }}
- uses: actions/checkout@v2
- uses: php-actions/composer@v6
with:
php_version: ${{ matrix.php-versions }}
version: 2
- run: XDEBUG_MODE=coverage ./vendor/bin/phpunit
- name: Upload coverage results to Coveralls
env:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- run tests over multiple PHP version

### Security
- update friendsofphp/php-cs-fixer (v3.4.0 => v3.21.1)

### Removed
- drop support for PHP 7.4 and below

## [1.0.2] - 2022-09-06
### Added
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"description": "Super-simple, minimum abstraction Pricehubble API v1.x wrapper, in PHP",
"license": "MIT",
"require": {
"php": ">=7.4",
"php": ">=8.0",
"ext-curl": "*",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^9",
"symfony/dotenv": "^5.4",
"friendsofphp/php-cs-fixer": "^3.0",
"friendsofphp/php-cs-fixer": "^3.21",
"phpmd/phpmd": "^2.6",
"sebastian/phpcpd": "^6.0",
"php-coveralls/php-coveralls": "^2.1",
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/AbstractResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Antistatique\Pricehubble\Pricehubble;
use Antistatique\Pricehubble\Resource\AbstractResource;
use PHPUnit\Framework\TestCase;
use ReflectionClass;

/**
* @coversDefaultClass \Antistatique\Pricehubble\Resource\AbstractResource
Expand Down Expand Up @@ -44,7 +43,7 @@ public function testConstructor(): void
->with($pricehubble);

// Now call the constructor
$reflectedClass = new ReflectionClass(AbstractResource::class);
$reflectedClass = new \ReflectionClass(AbstractResource::class);
$constructor = $reflectedClass->getConstructor();
$constructor->invoke($mock, $pricehubble);
}
Expand Down
22 changes: 10 additions & 12 deletions tests/Unit/PricehubbleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Antistatique\Pricehubble\Pricehubble;
use Antistatique\Pricehubble\Resource\AbstractResource;
use Antistatique\Pricehubble\Tests\Traits\TestPrivateTrait;
use BadMethodCallException;
use Exception;
use phpmock\phpunit\PHPMock;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -103,7 +101,7 @@ public function testMagicCallReturnsExpected(): void
*/
public function testMagicCallReturnsException(): void
{
$this->expectException(BadMethodCallException::class);
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage('Undefined method foo');
$this->pricehubble->foo();
}
Expand Down Expand Up @@ -209,7 +207,7 @@ public function testSetResponseStateError()
$curl_error_mock->expects($this->once())
->willReturn('Something went wrong.');

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Something went wrong.');
$this->callPrivateMethod($this->pricehubble, 'setResponseState', [
[], false, null,
Expand Down Expand Up @@ -366,7 +364,7 @@ public function testDetermineSuccessErrorMessage()
->method('findHttpStatus')
->willReturn(400);

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('400 Unsupported country code.');
$this->callPrivateMethod($pricehubble_mock, 'determineSuccess', [
[], ['message' => 'Unsupported country code.'], 0,
Expand All @@ -388,7 +386,7 @@ public function testDetermineSuccessErrorMessageDescription()
->method('findHttpStatus')
->willReturn(401);

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('401 invalid_token: The access token is invalid or has expired');
$this->callPrivateMethod($pricehubble_mock, 'determineSuccess', [
[], ['error_description' => 'The access token is invalid or has expired', 'error' => 'invalid_token'], 0,
Expand All @@ -410,7 +408,7 @@ public function testDetermineSuccessTimeout()
->method('findHttpStatus')
->willReturn(100);

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Request timed out after 20.000000 seconds.');
$this->callPrivateMethod($pricehubble_mock, 'determineSuccess', [
['headers' => ['total_time' => 20]], null, 5,
Expand All @@ -430,7 +428,7 @@ public function testDetermineSuccessUnknown()
->method('findHttpStatus')
->willReturn(100);

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Unknown error, call getLastResponse() to find out what happened.');
$this->callPrivateMethod($pricehubble_mock, 'determineSuccess', [
['headers' => ['total_time' => 20]], null, 35,
Expand All @@ -448,7 +446,7 @@ public function testDetermineSuccess401MissingToken()

$pricehubble_mock = new Pricehubble();

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('401 invalid_request: The access token is missing');
$this->callPrivateMethod($pricehubble_mock, 'determineSuccess', [
$response, [
Expand All @@ -467,7 +465,7 @@ public function testDetermineSuccess403MissingProperty()

$pricehubble_mock = new Pricehubble();

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage("403 'dossierId', 'simulationId' or 'buildingId' is a required property");
$this->callPrivateMethod($pricehubble_mock, 'determineSuccess', [
$response, [
Expand All @@ -485,7 +483,7 @@ public function testDetermineSuccess403Forbidden()

$pricehubble_mock = new Pricehubble();

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('403 Forbidden');
$this->callPrivateMethod($pricehubble_mock, 'determineSuccess', [
$response, ['message' => 'Forbidden'], 0,
Expand All @@ -503,7 +501,7 @@ public function testDetermineSuccess403ForbiddenNested()

$pricehubble_mock = new Pricehubble();

$this->expectException(Exception::class);
$this->expectException(\Exception::class);
$this->expectExceptionMessage('403 Forbidden');
$this->callPrivateMethod($pricehubble_mock, 'determineSuccess', [
$response, ['message' => ['message' => 'Forbidden']], 0,
Expand Down

0 comments on commit 9fb54fd

Please sign in to comment.