Skip to content

Commit

Permalink
Merge pull request #9 from ttskch/ci/gh-actions
Browse files Browse the repository at this point in the history
Execute some tests on GitHub Actions
  • Loading branch information
torukitagawa committed Sep 22, 2023
2 parents 5845003 + 8406ec9 commit 1c92704
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 85 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: CI

on: push

jobs:
coding-standards:
runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2

- uses: actions/checkout@v3

- name: Install Dependencies
run: |
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
composer bin all install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Execute checks
run: composer cs

static-analysis:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php-version:
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2

steps:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- uses: actions/checkout@v3

- name: Install Dependencies
run: |
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
composer bin all install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Execute checks
run: composer sa

test:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php-version:
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
dependencies:
- lowest
- highest

steps:
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}

- uses: actions/checkout@v3

- name: Install lowest dependencies
if: ${{ matrix.dependencies == 'lowest' }}
run: |
composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --prefer-lowest
# phpunit too old cannot be run on PHP 8.1+
composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist phpunit/phpunit
- name: Install highest dependencies
if: ${{ matrix.dependencies == 'highest' }}
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: Execute tests
run: composer test
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
/composer.lock
/vendor
/vendor-bin/*/composer.lock
/vendor-bin/*/vendor

# friendsofphp/php-cs-fixer
/.php-cs-fixer.php
/.php-cs-fixer.cache

# phpunit/phpunit
/phpunit.xml
/.phpunit.result.cache
16 changes: 16 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$finder = new PhpCsFixer\Finder();

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'yoda_style' => [
'equal' => false,
'identical' => false,
'less_and_greater' => false,
],
'no_null_property_initialization' => false,
])
->setFinder($finder)
;
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TreasureData REST API Wrapper
=============================

[![Build Status](https://travis-ci.org/otobank/treasure-php.svg?branch=master)](https://travis-ci.org/otobank/treasure-php)
[![](https://github.com/otobank/treasure-php/actions/workflows/ci.yaml/badge.svg?branch=master)](https://github.com/otobank/treasure-php/actions/workflows/ci.yaml?query=branch:master)
[![Latest Stable Version](https://poser.pugx.org/otobank/treasure/v/stable)](https://packagist.org/packages/otobank/treasure)
[![Total Downloads](https://poser.pugx.org/otobank/treasure/downloads)](https://packagist.org/packages/otobank/treasure)
[![Latest Unstable Version](https://poser.pugx.org/otobank/treasure/v/unstable)](https://packagist.org/packages/otobank/treasure)
Expand Down
25 changes: 23 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,30 @@
}
],
"require-dev": {
"phpunit/phpunit": "^8.5"
"phpunit/phpunit": "^8.5",
"bamarni/composer-bin-plugin": "^1.8"
},
"scripts": {
"test": "vendor/bin/phpunit"
"cs": [
"@putenv PHP_CS_FIXER_IGNORE_ENV=1",
"vendor-bin/tools/vendor/bin/php-cs-fixer fix --config .php-cs-fixer.dist.php --dry-run --diff -v src tests"
],
"cs:fix": [
"@putenv PHP_CS_FIXER_IGNORE_ENV=1",
"vendor-bin/tools/vendor/bin/php-cs-fixer fix --config .php-cs-fixer.dist.php src tests"
],
"sa": "@php -d memory_limit=-1 vendor-bin/tools/vendor/bin/phpstan analyse --configuration=phpstan.neon",
"test": "vendor/bin/phpunit",
"tests": ["@cs", "@sa", "@test"]
},
"config": {
"allow-plugins": {
"bamarni/composer-bin-plugin": true
}
},
"extra": {
"bamarni-bin": {
"bin-links": false
}
}
}
17 changes: 17 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
includes:
- vendor-bin/tools/vendor/phpstan/phpstan-strict-rules/rules.neon

parameters:
level: max
paths:
- src
- tests

ignoreErrors:
# Allow some "Dynamic call to static method" in tests
# @see https://github.com/phpstan/phpstan-strict-rules/issues/36
- messages:
- '#Dynamic call to static method PHPUnit\\Framework\\TestCase::once\(\)\.#'
- '#Dynamic call to static method PHPUnit\\Framework\\Assert::equalTo\(\)\.#'
paths:
- tests
68 changes: 15 additions & 53 deletions src/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Otobank\Treasure;

class Configuration
Expand All @@ -20,7 +22,7 @@ class Configuration
private $pathname = '/postback/v3/event/';

/**
* @param array $options
* @param array<string, mixed> $options
*/
public function __construct(array $options = [])
{
Expand All @@ -29,106 +31,66 @@ public function __construct(array $options = [])
if (!method_exists($this, $method)) {
throw new \InvalidArgumentException(sprintf('Unsupported options "%s"', $key));
}
$this->$method($value);
$this->$method($value); // @phpstan-ignore-line
}
}

/**
* @param bool $development
*
* @return Configuration
*/
public function setDevelopment($development)
public function setDevelopment(bool $development): self
{
$this->development = $development ? true : false;
$this->development = $development;

return $this;
}

/**
* @return bool
*/
public function getDevelopment()
public function getDevelopment(): bool
{
return $this->development;
}

/**
* @param string $host
*
* @return Configuration
*/
public function setHost($host)
public function setHost(string $host): self
{
$this->host = $host;

return $this;
}

/**
* @return string
*/
public function getHost()
public function getHost(): string
{
return $this->host;
}

/**
* @var string
*
* @return Configuration
*/
public function setWriteKey($writeKey)
public function setWriteKey(string $writeKey): self
{
$this->writeKey = $writeKey;

return $this;
}

/**
* @return string
*/
public function getWriteKey()
public function getWriteKey(): string
{
return $this->writeKey;
}

/**
* @var string
*
* @return Configuration
*/
public function setDatabase($database)
public function setDatabase(string $database): self
{
$this->database = $database;

return $this;
}

/**
* @return string
*/
public function getDatabase()
public function getDatabase(): string
{
return $this->database;
}

/**
* @var string
*
* @return Configuration
*/
public function setPathname($pathname)
public function setPathname(string $pathname): self
{
$this->pathname = $pathname;

return $this;
}

/**
* @return string
*/
public function getPathname()
public function getPathname(): string
{
return $this->pathname;
}
Expand Down
29 changes: 10 additions & 19 deletions src/Treasure.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Otobank\Treasure;

use GuzzleHttp\Client;
Expand All @@ -10,11 +12,11 @@ class Treasure
/** @var Configuration */
private $config;

/** @var ClientInterface */
private $client;
/** @var ClientInterface|null */
private $client = null;

/**
* @param Configuration|array $config
* @param Configuration|array<string, mixed>|mixed $config
*/
public function __construct($config = [])
{
Expand All @@ -27,27 +29,19 @@ public function __construct($config = [])
}
}

/**
* @param ClientInterface $client
*
* @return Treasure
*/
public function setClient(ClientInterface $client)
public function setClient(ClientInterface $client): self
{
$this->client = $client;

return $this;
}

/**
* @param string $table
* @param array $record
*
* @return bool
* @param array<mixed> $record
*/
public function addRecord($table, array $record = [])
public function addRecord(string $table, array $record = []): bool
{
if (!$this->client) {
if ($this->client === null) {
$this->client = $this->createClient();
}

Expand All @@ -68,10 +62,7 @@ public function addRecord($table, array $record = [])
return $response->getStatusCode() === 200;
}

/**
* @return ClientInterface
*/
private function createClient()
private function createClient(): ClientInterface
{
return new Client();
}
Expand Down
Loading

0 comments on commit 1c92704

Please sign in to comment.