Skip to content

Commit b519370

Browse files
authored
Merge pull request #22 from peter279k/test_enhancement
Test enhancement and integrate GitHub Actions
2 parents c8a1bf5 + 612a578 commit b519370

15 files changed

+142
-33
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: spatie

.github/workflows/php-cs-fixer.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Code style
2+
3+
on: [push]
4+
5+
jobs:
6+
style:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v2
12+
13+
- name: Fix style
14+
uses: docker://oskarstark/php-cs-fixer-ga
15+
with:
16+
args: --config=.php_cs --allow-risky=yes
17+
18+
- name: Extract branch name
19+
shell: bash
20+
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
21+
id: extract_branch
22+
23+
- name: Commit changes
24+
uses: stefanzweifel/git-auto-commit-action@v2.3.0
25+
with:
26+
commit_message: Fix styling
27+
branch: ${{ steps.extract_branch.outputs.branch }}
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/run-tests.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ${{ matrix.os }}
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
os: [ubuntu-latest]
12+
php: [8.0, 7.4]
13+
dependency-version: [prefer-lowest, prefer-stable]
14+
15+
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
- name: Cache dependencies
22+
uses: actions/cache@v2
23+
with:
24+
path: ~/.composer/cache/files
25+
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
26+
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: ${{ matrix.php }}
31+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
32+
coverage: none
33+
34+
- name: Install dependencies
35+
run: composer update --no-interaction --prefer-source
36+
37+
- name: Execute tests
38+
run: vendor/bin/phpunit

.php_cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
$finder = Symfony\Component\Finder\Finder::create()
4+
->notPath('bootstrap/*')
5+
->notPath('storage/*')
6+
->notPath('vendor')
7+
->in([
8+
__DIR__ . '/src',
9+
__DIR__ . '/tests',
10+
])
11+
->name('*.php')
12+
->notName('*.blade.php')
13+
->ignoreDotFiles(true)
14+
->ignoreVCS(true);
15+
16+
return PhpCsFixer\Config::create()
17+
->setRules([
18+
'@PSR2' => true,
19+
'array_syntax' => ['syntax' => 'short'],
20+
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
21+
'no_unused_imports' => true,
22+
'not_operator_with_successor_space' => true,
23+
'trailing_comma_in_multiline_array' => true,
24+
'phpdoc_scalar' => true,
25+
'unary_operator_spaces' => true,
26+
'binary_operator_spaces' => true,
27+
'blank_line_before_statement' => [
28+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
29+
],
30+
'phpdoc_single_line_var_spacing' => true,
31+
'phpdoc_var_without_name' => true,
32+
'class_attributes_separation' => [
33+
'elements' => [
34+
'method', 'property',
35+
],
36+
],
37+
'method_argument_space' => [
38+
'on_multiline' => 'ensure_fully_multiline',
39+
'keep_multiple_spaces_after_comma' => true,
40+
]
41+
])
42+
->setFinder($finder);

.travis.yml

Lines changed: 0 additions & 12 deletions
This file was deleted.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
}
1919
],
2020
"require": {
21-
"php" : "^7.2"
21+
"php" : "^7.4|^8.0"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit" : "^7.0"
24+
"phpunit/phpunit" : "^9.4"
2525
},
2626
"autoload": {
2727
"files": ["src/array_functions.php"]

src/array_functions.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
function array_rand_value(array $array, $numReq = 1)
1414
{
15-
if (!count($array)) {
15+
if (! count($array)) {
1616
return;
1717
}
1818

@@ -39,7 +39,7 @@ function array_rand_weighted(array $array)
3939
return $item >= 1;
4040
});
4141

42-
if (!count($array)) {
42+
if (! count($array)) {
4343
return;
4444
}
4545
$totalWeight = array_sum($array);
@@ -62,7 +62,7 @@ function array_rand_weighted(array $array)
6262
*/
6363
function values_in_array($needles, array $haystack)
6464
{
65-
if (!is_array($needles)) {
65+
if (! is_array($needles)) {
6666
$needles = [$needles];
6767
}
6868

@@ -79,7 +79,7 @@ function values_in_array($needles, array $haystack)
7979
*/
8080
function array_keys_exist($needles, array $haystack)
8181
{
82-
if (!is_array($needles)) {
82+
if (! is_array($needles)) {
8383
return array_key_exists($needles, $haystack);
8484
}
8585

@@ -104,7 +104,9 @@ function array_split_filter(array $array, callable $callback)
104104
{
105105
$passesFilter = array_filter($array, $callback);
106106

107-
$negatedCallback = static function ($item) use ($callback) { return !$callback($item); };
107+
$negatedCallback = static function ($item) use ($callback) {
108+
return ! $callback($item);
109+
};
108110

109111
$doesNotPassFilter = array_filter($array, $negatedCallback);
110112

@@ -146,7 +148,7 @@ function array_split(array $array, $numberOfPieces = 2, $preserveKeys = false)
146148
function array_merge_values(array ...$arrays)
147149
{
148150
$allValues = array_reduce($arrays, static function ($carry, $array) {
149-
return array_merge($carry, $array);
151+
return array_merge($carry, $array);
150152
}, []);
151153

152154
return array_values(array_unique($allValues));

tests/ArrayFlattenTest.php

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

33
namespace Spatie\Test;
44

5-
use function spatie\array_flatten;
65
use PHPUnit\Framework\TestCase;
6+
use function spatie\array_flatten;
77

88
class ArrayFlattenTest extends TestCase
99
{

tests/ArrayKeysExistTest.php

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

33
namespace Spatie\Test;
44

5-
use function spatie\array_keys_exist;
65
use PHPUnit\Framework\TestCase;
6+
use function spatie\array_keys_exist;
77

88
class ArrayKeysExistTest extends TestCase
99
{
@@ -14,6 +14,7 @@ public function it_returns_true_when_all_array_keys_exist()
1414
{
1515
$this->assertTrue(array_keys_exist(['a', 'b'], ['a' => 'foo', 'b' => 'bar', 'c' => 'baz']));
1616
}
17+
1718
/**
1819
* @test
1920
*/

tests/ArrayMergeValuesTest.php

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

33
namespace Spatie\Test;
44

5-
use function spatie\array_merge_values;
65
use PHPUnit\Framework\TestCase;
6+
use function spatie\array_merge_values;
77

88
class ArrayMergeValuesTest extends TestCase
99
{

0 commit comments

Comments
 (0)