Skip to content

Commit f9ec3d0

Browse files
authored
migrate to github actions (#2)
Migrate to github actions
1 parent e7e9fa0 commit f9ec3d0

16 files changed

+618
-471
lines changed

.github/workflows/CI.yaml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Tests
2+
3+
# Run this workflow every time a new commit pushed to your repository
4+
on:
5+
push:
6+
paths-ignore:
7+
- '**/*.md'
8+
pull_request:
9+
paths-ignore:
10+
- '**/*.md'
11+
12+
jobs:
13+
tests:
14+
runs-on: ${{ matrix.operating-system }}
15+
if: (github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository)
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
operating-system: [ubuntu-20.04]
21+
php-versions: ['7.4', '8.0', '8.1']
22+
dependencies: ['no', 'low', 'beta']
23+
include:
24+
- operating-system: ubuntu-20.04
25+
php-versions: '8.0'
26+
continue-on-error: true
27+
28+
name: PHP ${{ matrix.php-versions }} - ${{ matrix.dependencies }}
29+
30+
env:
31+
extensions: curl json libxml dom
32+
key: cache-v1 # can be any string, change to clear the extension cache.
33+
34+
steps:
35+
36+
# Checks out a copy of your repository on the ubuntu machine
37+
- name: Checkout code
38+
uses: actions/checkout@v2
39+
40+
- name: Setup cache environment
41+
id: extcache
42+
uses: shivammathur/cache-extensions@v1
43+
with:
44+
php-version: ${{ matrix.php-versions }}
45+
extensions: ${{ env.extensions }}
46+
key: ${{ env.key }}
47+
48+
- name: Cache PHP Extensions
49+
uses: actions/cache@v2
50+
with:
51+
path: ${{ steps.extcache.outputs.dir }}
52+
key: ${{ steps.extcache.outputs.key }}
53+
restore-keys: ${{ steps.extcache.outputs.key }}
54+
55+
- name: Cache Composer Dependencies
56+
uses: actions/cache@v1
57+
with:
58+
path: ~/.composer/cache/files
59+
key: dependencies-composer-${{ hashFiles('composer.json') }}
60+
61+
- name: Setup PHP Action
62+
uses: shivammathur/setup-php@2.8.0
63+
with:
64+
php-version: ${{ matrix.php-versions }}
65+
extensions: ${{ env.extensions }}
66+
coverage: xdebug
67+
tools: pecl, composer
68+
69+
- name: PHP Show modules
70+
run: php -m
71+
72+
- name: Get composer cache directory
73+
id: composer-cache
74+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
75+
76+
- name: Cache dependencies
77+
uses: actions/cache@v2
78+
with:
79+
path: ${{ steps.composer-cache.outputs.dir }}
80+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
81+
restore-keys: ${{ runner.os }}-composer-
82+
83+
- name: Install Composer dependencies
84+
if: ${{ matrix.dependencies != 'low' }}
85+
run: composer update --no-interaction
86+
87+
- name: Install Composer dependencies
88+
if: ${{ matrix.dependencies == 'low' }}
89+
run: composer update -vvv --prefer-lowest --prefer-stable --no-interaction
90+
91+
- name: Validate files
92+
run: composer validate-files
93+
94+
- name: Check Style
95+
run: composer check-code-style
96+
97+
# - name: Run tests
98+
# run: composer run-tests

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
composer.phar
44
composer.lock
55
.DS_Store
6+
.php-cs-fixer.cache
7+
.phpunit.result.cache

.travis.yml

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

composer.json

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,26 @@
2525
},
2626

2727
"require-dev": {
28-
"phpunit/phpunit": "7.*"
29-
},
28+
"php-parallel-lint/php-parallel-lint": "^1.2",
29+
"phpmd/phpmd": "^2.9",
30+
"phpunit/phpunit": "^9.3",
31+
"sebastian/phpcpd": ">=4.1",
32+
"friendsofphp/php-cs-fixer": ">=2.17",
33+
"squizlabs/php_codesniffer": "^3.5"
34+
},
3035

36+
"scripts": {
37+
"check-code-style": [
38+
"vendor/bin/phpcs --standard=PSR2 ./src/"
39+
],
40+
"run-tests": [
41+
"vendor/bin/phpunit -c phpunit.xml",
42+
"vendor/bin/phpunit --coverage-clover=coverage.xml"
43+
],
44+
"validate-files": [
45+
"vendor/bin/parallel-lint --exclude vendor ."
46+
]
47+
},
3148
"minimum-stability": "dev",
3249
"prefer-stable": true,
3350

phpunit.xml

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="phpunit.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
>
11-
<testsuites>
12-
<testsuite name="Package Test Suite">
13-
<directory suffix=".php">./tests/</directory>
14-
</testsuite>
15-
</testsuites>
16-
17-
<filter>
18-
<whitelist>
19-
<directory>./src</directory>
20-
</whitelist>
21-
</filter>
22-
</phpunit>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="phpunit.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory>./src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Package Test Suite">
10+
<directory suffix=".php">./tests/</directory>
11+
</testsuite>
12+
</testsuites>
13+
</phpunit>

src/AncestorsRelation.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ class AncestorsRelation extends BaseRelation
1313
*/
1414
public function addConstraints()
1515
{
16-
if ( ! static::$constraints) return;
16+
if (! static::$constraints) {
17+
return;
18+
}
1719

1820
$this->query->whereAncestorOf($this->parent)
1921
->applyNestedSetScope();

src/BaseRelation.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ abstract class BaseRelation extends Relation
3636
*/
3737
public function __construct(QueryBuilder $builder, Model $model)
3838
{
39-
if ( ! NestedSet::isNode($model)) {
39+
if (! NestedSet::isNode($model)) {
4040
throw new InvalidArgumentException('Model must be node.');
4141
}
4242

@@ -76,8 +76,10 @@ abstract protected function relationExistenceCondition($hash, $table, $lft, $rgt
7676
*
7777
* @return mixed
7878
*/
79-
public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilder $parent,
80-
$columns = [ '*' ]
79+
public function getRelationExistenceQuery(
80+
EloquentBuilder $query,
81+
EloquentBuilder $parent,
82+
$columns = [ '*' ]
8183
) {
8284
$query = $this->getParent()->replicate()->newScopedQuery()->select($columns);
8385

@@ -93,7 +95,8 @@ public function getRelationExistenceQuery(EloquentBuilder $query, EloquentBuilde
9395
$grammar->wrapTable($hash),
9496
$grammar->wrapTable($table),
9597
$grammar->wrap($this->parent->getLftName()),
96-
$grammar->wrap($this->parent->getRgtName()));
98+
$grammar->wrap($this->parent->getRgtName())
99+
);
97100

98101
return $query->whereRaw($condition);
99102
}
@@ -119,7 +122,8 @@ public function initRelation(array $models, $relation)
119122
* @return mixed
120123
*/
121124
public function getRelationQuery(
122-
EloquentBuilder $query, EloquentBuilder $parent,
125+
EloquentBuilder $query,
126+
EloquentBuilder $parent,
123127
$columns = [ '*' ]
124128
) {
125129
return $this->getRelationExistenceQuery($query, $parent, $columns);

src/Collection.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ class Collection extends BaseCollection
1616
*/
1717
public function linkNodes()
1818
{
19-
if ($this->isEmpty()) return $this;
19+
if ($this->isEmpty()) {
20+
return $this;
21+
}
2022

2123
$groupedNodes = $this->groupBy($this->first()->getParentIdName());
2224

2325
/** @var NodeTrait|Model $node */
2426
foreach ($this->items as $node) {
25-
if ( ! $node->getParentId()) {
27+
if (! $node->getParentId()) {
2628
$node->setRelation('parent', null);
2729
}
2830

@@ -53,7 +55,7 @@ public function linkNodes()
5355
public function toTree($root = false)
5456
{
5557
if ($this->isEmpty()) {
56-
return new static;
58+
return new static();
5759
}
5860

5961
$this->linkNodes();
@@ -112,9 +114,11 @@ protected function getRootNodeId($root = false)
112114
*/
113115
public function toFlatTree($root = false)
114116
{
115-
$result = new static;
117+
$result = new static();
116118

117-
if ($this->isEmpty()) return $result;
119+
if ($this->isEmpty()) {
120+
return $result;
121+
}
118122

119123
$groupedNodes = $this->groupBy($this->first()->getParentIdName());
120124

@@ -139,5 +143,4 @@ protected function flattenTree(self $groupedNodes, $parentId)
139143

140144
return $this;
141145
}
142-
143-
}
146+
}

src/DescendantsRelation.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
class DescendantsRelation extends BaseRelation
99
{
10-
1110
/**
1211
* Set the base constraints on the relation query.
1312
*
1413
* @return void
1514
*/
1615
public function addConstraints()
1716
{
18-
if ( ! static::$constraints) return;
17+
if (! static::$constraints) {
18+
return;
19+
}
1920

2021
$this->query->whereDescendantOf($this->parent)
2122
->applyNestedSetScope();
@@ -53,4 +54,4 @@ protected function relationExistenceCondition($hash, $table, $lft, $rgt)
5354
{
5455
return "{$hash}.{$lft} between {$table}.{$lft} + 1 and {$table}.{$rgt}";
5556
}
56-
}
57+
}

src/NestedSet.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ class NestedSet
99
/**
1010
* The name of default lft column.
1111
*/
12-
const LFT = '_lft';
12+
public const LFT = '_lft';
1313

1414
/**
1515
* The name of default rgt column.
1616
*/
17-
const RGT = '_rgt';
17+
public const RGT = '_rgt';
1818

1919
/**
2020
* The name of default parent id column.
2121
*/
22-
const PARENT_ID = 'parent_id';
22+
public const PARENT_ID = 'parent_id';
2323

2424
/**
2525
* Insert direction.
2626
*/
27-
const BEFORE = 1;
27+
public const BEFORE = 1;
2828

2929
/**
3030
* Insert direction.
3131
*/
32-
const AFTER = 2;
32+
public const AFTER = 2;
3333

3434
/**
3535
* Add default nested set columns to the table. Also create an index.
@@ -79,5 +79,4 @@ public static function isNode($node)
7979
{
8080
return $node instanceof Node;
8181
}
82-
83-
}
82+
}

0 commit comments

Comments
 (0)