Skip to content

Commit 79a8d34

Browse files
authored
Merge pull request #5 from wearedevtical/develop
Setup test, phpcs, and actions
2 parents 21ac9b0 + 4c034ec commit 79a8d34

File tree

10 files changed

+161
-13
lines changed

10 files changed

+161
-13
lines changed

.gitattributes

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
33

44
# Ignore all test and documentation with "export-ignore".
5+
/.github export-ignore
56
/.gitattributes export-ignore
67
/.gitignore export-ignore
7-
/.travis.yml export-ignore
88
/phpunit.xml.dist export-ignore
9-
/.scrutinizer.yml export-ignore
109
/tests export-ignore
10+
/.editorconfig export-ignore
11+
/.php_cs.dist.php export-ignore

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Check & fix styling
2+
3+
on: [push]
4+
5+
jobs:
6+
php-cs-fixer:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout code
11+
uses: actions/checkout@v2
12+
with:
13+
ref: ${{ github.head_ref }}
14+
15+
- name: Run PHP CS Fixer
16+
uses: docker://oskarstark/php-cs-fixer-ga
17+
with:
18+
args: --config=.php_cs.dist.php --allow-risky=yes
19+
20+
- name: Commit changes
21+
uses: stefanzweifel/git-auto-commit-action@v4
22+
with:
23+
commit_message: Fix styling

.github/workflows/tests.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "Tests"
2+
3+
on:
4+
push:
5+
branches: [develop]
6+
pull_request:
7+
branches: [main]
8+
schedule:
9+
- cron: '0 0 * * *'
10+
11+
jobs:
12+
run-tests:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php: [7.4, 8.0, 8.1]
18+
laravel: [8.*]
19+
dependency-version: [prefer-lowest, prefer-stable]
20+
include:
21+
- laravel: 8.*
22+
testbench: ^6.23
23+
24+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
25+
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v2
29+
30+
- name: Setup PHP
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php }}
34+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
35+
coverage: none
36+
37+
- name: Setup Problem Matches
38+
run: |
39+
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
40+
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
41+
42+
- name: Install dependencies
43+
run: |
44+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
45+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
46+
47+
- name: Execute tests
48+
run: vendor/bin/phpunit
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: "Update Changelog"
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
jobs:
8+
update:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
with:
15+
ref: master
16+
17+
- name: Update Changelog
18+
uses: stefanzweifel/changelog-updater-action@v1
19+
with:
20+
latest-version: ${{ github.event.release.name }}
21+
release-notes: ${{ github.event.release.body }}
22+
23+
- name: Commit updated CHANGELOG
24+
uses: stefanzweifel/git-auto-commit-action@v4
25+
with:
26+
branch: master
27+
commit_message: Update CHANGELOG
28+
file_pattern: CHANGELOG.md

.php_cs.dist.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in([
5+
__DIR__ . '/src',
6+
__DIR__ . '/tests',
7+
])
8+
->name('*.php')
9+
->ignoreDotFiles(true)
10+
->ignoreVCS(true);
11+
12+
return (new PhpCsFixer\Config())
13+
->setRules([
14+
'@PSR12' => true,
15+
'array_syntax' => ['syntax' => 'short'],
16+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
17+
'no_unused_imports' => true,
18+
'not_operator_with_successor_space' => true,
19+
'trailing_comma_in_multiline' => true,
20+
'phpdoc_scalar' => true,
21+
'unary_operator_spaces' => true,
22+
'binary_operator_spaces' => true,
23+
'blank_line_before_statement' => [
24+
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
25+
],
26+
'phpdoc_single_line_var_spacing' => true,
27+
'phpdoc_var_without_name' => true,
28+
'method_argument_space' => [
29+
'on_multiline' => 'ensure_fully_multiline',
30+
'keep_multiple_spaces_after_comma' => true,
31+
],
32+
'single_trait_insert_per_statement' => true,
33+
])
34+
->setFinder($finder);

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
],
1818
"type": "library",
1919
"require": {
20-
"illuminate/support": "^6.0|^7.0|^8.0"
20+
"php": "^7.4|^8.0",
21+
"illuminate/support": "^6.20.13|7.30.4|^8.22.2"
2122
},
2223
"require-dev": {
23-
"phpunit/phpunit": "~9.0",
24-
"orchestra/testbench": "~5|~6",
24+
"phpunit/phpunit": "^9.3",
25+
"orchestra/testbench": "^5.20|^6.23",
2526
"friendsofphp/php-cs-fixer": "^3.0"
2627
},
2728
"autoload": {
@@ -42,8 +43,8 @@
4243
}
4344
},
4445
"scripts": {
45-
"test": "phpunit",
46-
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
46+
"format": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist.php --allow-risky=yes",
47+
"test": "vendor/bin/phpunit"
4748
},
4849
"minimum-stability": "dev",
4950
"prefer-stable": true

src/Console/Commands/HelperMakeCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,18 @@ class HelperMakeCommand extends GeneratorCommand
3434
*/
3535
protected function getStub()
3636
{
37-
return __DIR__ . '/stubs/helper.stub';
37+
return __DIR__.'/stubs/helper.stub';
3838
}
3939

4040
/**
4141
* Get the default namespace for the class.
4242
*
43-
* @param string $rootNamespace
43+
* @param string $rootNamespace
44+
*
4445
* @return string
4546
*/
4647
protected function getDefaultNamespace($rootNamespace)
4748
{
48-
return $rootNamespace . '\\' . config('helpers.directory', 'Helpers');
49+
return $rootNamespace.'\\'.config('helpers.directory', 'Helpers');
4950
}
5051
}

src/HelperServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class HelperServiceProvider extends ServiceProvider
99
{
10-
public const CONFIG_PATH = __DIR__ . '/../config/helpers.php';
10+
public const CONFIG_PATH = __DIR__.'/../config/helpers.php';
1111

1212
/**
1313
* Bootstrap the application events.
@@ -35,7 +35,7 @@ public function boot()
3535
public function register()
3636
{
3737
$this->mergeConfigFrom(self::CONFIG_PATH, 'helper');
38-
$files = glob(app_path(config('helpers.directory', 'Helpers') . '/*.php'));
38+
$files = glob(app_path(config('helpers.directory', 'Helpers').'/*.php'));
3939

4040
foreach ($files as $file) {
4141
require_once $file;

tests/HelpersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class HelpersTest extends TestCase
77
/** @test */
88
public function test_console_command()
99
{
10-
$this->assertEquals(1, 1);
10+
$this->artisan('make:helper', ['name' => 'TestHelper'])->assertExitCode(0);
1111
}
1212
}

tests/TestCase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
namespace Devtical\Helpers\Tests;
44

5+
use Devtical\Helpers\HelperServiceProvider;
56
use Orchestra\Testbench\TestCase as Orchestra;
67

78
abstract class TestCase extends Orchestra
89
{
10+
/**
11+
* @param \Illuminate\Foundation\Application $app
12+
*
13+
* @return array
14+
*/
15+
protected function getPackageProviders($app): array
16+
{
17+
return [
18+
HelperServiceProvider::class,
19+
];
20+
}
921
}

0 commit comments

Comments
 (0)