Skip to content

Commit 5c48204

Browse files
authored
Merge pull request #139 from omise/test/PLUGINS-270-unit-test
[PLUGINS-270] : PHP Unit Test
2 parents a45d190 + eea4509 commit 5c48204

156 files changed

Lines changed: 1456 additions & 10244 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.env.example‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
PUBLIC_KEY=pkey_***
2+
SECRET_KEY=skey_***

‎.github/workflows/php.yml‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
php-versions: ['5.6', '7.1', '7.2', '7.3', '7.4']
15+
php-versions: ['7.4', '8.0', '8.1']
1616
steps:
1717
- uses: actions/checkout@v2
1818

@@ -34,8 +34,10 @@ jobs:
3434
${{ runner.os }}-php-
3535
3636
- name: Install dependencies
37-
if: steps.composer-cache.outputs.cache-hit != 'true'
3837
run: composer install --prefer-dist --no-progress --no-suggest
38+
39+
- name: Run GrumPHP
40+
run: composer check
3941

40-
- name: Run test suite
41-
run: composer run-script test
42+
# - name: Run test suite
43+
# run: PUBLIC_KEY=::add-mask::${{ secrets.OMISE_PUBLIC_KEY }} SECRET_KEY=::add-mask::${{ secrets.OMISE_SECRET_KEY }} ./vendor/bin/phpunit --testdox

‎.gitignore‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
vendor/
1+
.phpunit.result.cache
2+
.php-cs-fixer.cache
3+
.vscode
4+
.DS_Store
5+
.env
6+
test.php
27
composer.lock
38
composer.phar
9+
vendor
10+
fixtures
11+
reports

‎.php-cs-fixer.php‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->exclude(['vendor'])
5+
->name('*.php')
6+
->in(__DIR__);
7+
8+
$config = new PhpCsFixer\Config();
9+
return $config->setRules([
10+
'@PSR12' => true,
11+
'strict_param' => false,
12+
'no_unused_imports' => true,
13+
'indentation_type' => true,
14+
'array_indentation' => false,
15+
'single_quote' => true,
16+
'method_chaining_indentation' => true,
17+
'trim_array_spaces' => true,
18+
'array_syntax' => ['syntax' => 'short'],
19+
'binary_operator_spaces' => [
20+
'operators' => [
21+
'=>' => 'single_space',
22+
'=' => 'single_space',
23+
'+=' => 'single_space',
24+
'-=' => 'single_space',
25+
'>' => 'single_space',
26+
'<' => 'single_space',
27+
'<=' => 'single_space',
28+
'>=' => 'single_space',
29+
'||' => 'single_space',
30+
'&&' => 'single_space',
31+
],
32+
],
33+
'no_extra_blank_lines' => ['tokens' => ['attribute', 'break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use']],
34+
])
35+
->setIndent(str_pad('', 4))
36+
->setLineEnding("\n")
37+
->setFinder($finder);

‎Makefile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SHELL := /bin/bash
2+
include .env
3+
4+
coverage:
5+
PUBLIC_KEY=${PUBLIC_KEY} SECRET_KEY=${SECRET_KEY} XDEBUG_MODE=coverage \
6+
./vendor/bin/phpunit --coverage-html reports --testdox
7+
8+
test:
9+
PUBLIC_KEY=${PUBLIC_KEY} SECRET_KEY=${SECRET_KEY} \
10+
./vendor/bin/phpunit --testdox
11+

‎README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
## Requirements
77

8-
* PHP v5.4 and above.
8+
* PHP v7.4 and above.
99
* Built-in [libcurl](http://php.net/manual/en/book.curl.php) support.
1010

11-
> Note that, due to the PHP [END OF LIFE](http://php.net/supported-versions.php) cycle, we encourage you to run Omise-PHP library on a PHP version 5.6 or higher as there is no longer security support for any below 5.6 and that could cause you any security vulnerable issues in the future.
11+
> Note that, due to the PHP [END OF LIFE](http://php.net/supported-versions.php) cycle, we encourage you to run Omise-PHP library on a PHP version 7.4 or higher as there is no longer security support for any below 7.4 and that could cause you any security vulnerable issues in the future.
1212
1313
## Installation
1414

@@ -127,8 +127,10 @@ To run an automated test suite, make sure you already have a [PHPUnit](https://p
127127
Then run the PHPUnit:
128128

129129
```ssh
130-
phpunit omise-php/tests
130+
cp .env.example .env
131+
make test
131132
```
133+
- To generate code coverage test report run `make coverage`
132134

133135
## Contributing
134136

‎composer.json‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@
2929
"php": ">=5.4.0"
3030
},
3131
"require-dev": {
32-
"phpunit/phpunit": "4.4.*",
33-
"squizlabs/php_codesniffer": "3.*"
32+
"phpunit/phpunit": "^9.5",
33+
"squizlabs/php_codesniffer": "3.*",
34+
"friendsofphp/php-cs-fixer": "^3.9",
35+
"phpro/grumphp": "^1.13",
36+
"phpstan/phpstan": "^1.8"
3437
},
3538
"autoload": {
3639
"classmap": ["lib/omise/"]
3740
},
3841
"scripts": {
39-
"test": "vendor/bin/phpunit"
42+
"test": "./vendor/bin/phpunit --testdox",
43+
"check": "./vendor/bin/grumphp run",
44+
"fix": "vendor/bin/php-cs-fixer fix"
45+
},
46+
"config": {
47+
"allow-plugins": {
48+
"phpro/grumphp": true
49+
}
4050
}
4151
}

‎grumphp.yml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
grumphp:
2+
hooks_dir: ./git-hooks
3+
process_timeout: 180
4+
fixer:
5+
enabled: true
6+
fix_by_default: false
7+
tasks:
8+
phpstan:
9+
force_patterns: []
10+
ignore_patterns: []
11+
triggered_by: ["php"]
12+
memory_limit: "-1"
13+
use_grumphp_paths: true
14+
phpcsfixer2:
15+
config: .php-cs-fixer.php
16+
config_contains_finder: true
17+
verbose: true
18+
diff: false
19+
triggered_by: ["php"]

‎lib/Omise.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
// Cores and utilities.
34
require_once dirname(__FILE__).'/omise/res/obj/OmiseObject.php';
45
require_once dirname(__FILE__).'/omise/res/OmiseApiResource.php';

‎lib/omise/OmiseAccount.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class OmiseAccount extends OmiseApiResource
44
{
5-
const ENDPOINT = 'account';
5+
public const ENDPOINT = 'account';
66

77
/**
88
* Retrieves an account.

0 commit comments

Comments
 (0)