Skip to content

Commit

Permalink
Merge pull request #5 from wearedevtical/develop
Browse files Browse the repository at this point in the history
Setup test, phpcs, and actions
  • Loading branch information
Kristories authored Jan 11, 2022
2 parents 21ac9b0 + 4c034ec commit 79a8d34
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.php_cs.dist.php export-ignore
23 changes: 23 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check & fix styling

on: [push]

jobs:
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
48 changes: 48 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: "Tests"

on:
push:
branches: [develop]
pull_request:
branches: [main]
schedule:
- cron: '0 0 * * *'

jobs:
run-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [7.4, 8.0, 8.1]
laravel: [8.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: ^6.23

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Setup Problem Matches
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests
run: vendor/bin/phpunit
28 changes: 28 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Update Changelog"

on:
release:
types: [released]

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: master

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: master
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
34 changes: 34 additions & 0 deletions .php_cs.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
],
'phpdoc_single_line_var_spacing' => true,
'phpdoc_var_without_name' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'single_trait_insert_per_statement' => true,
])
->setFinder($finder);
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
],
"type": "library",
"require": {
"illuminate/support": "^6.0|^7.0|^8.0"
"php": "^7.4|^8.0",
"illuminate/support": "^6.20.13|7.30.4|^8.22.2"
},
"require-dev": {
"phpunit/phpunit": "~9.0",
"orchestra/testbench": "~5|~6",
"phpunit/phpunit": "^9.3",
"orchestra/testbench": "^5.20|^6.23",
"friendsofphp/php-cs-fixer": "^3.0"
},
"autoload": {
Expand All @@ -42,8 +43,8 @@
}
},
"scripts": {
"test": "phpunit",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
"format": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist.php --allow-risky=yes",
"test": "vendor/bin/phpunit"
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
7 changes: 4 additions & 3 deletions src/Console/Commands/HelperMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ class HelperMakeCommand extends GeneratorCommand
*/
protected function getStub()
{
return __DIR__ . '/stubs/helper.stub';
return __DIR__.'/stubs/helper.stub';
}

/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @param string $rootNamespace
*
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace . '\\' . config('helpers.directory', 'Helpers');
return $rootNamespace.'\\'.config('helpers.directory', 'Helpers');
}
}
4 changes: 2 additions & 2 deletions src/HelperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class HelperServiceProvider extends ServiceProvider
{
public const CONFIG_PATH = __DIR__ . '/../config/helpers.php';
public const CONFIG_PATH = __DIR__.'/../config/helpers.php';

/**
* Bootstrap the application events.
Expand Down Expand Up @@ -35,7 +35,7 @@ public function boot()
public function register()
{
$this->mergeConfigFrom(self::CONFIG_PATH, 'helper');
$files = glob(app_path(config('helpers.directory', 'Helpers') . '/*.php'));
$files = glob(app_path(config('helpers.directory', 'Helpers').'/*.php'));

foreach ($files as $file) {
require_once $file;
Expand Down
2 changes: 1 addition & 1 deletion tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class HelpersTest extends TestCase
/** @test */
public function test_console_command()
{
$this->assertEquals(1, 1);
$this->artisan('make:helper', ['name' => 'TestHelper'])->assertExitCode(0);
}
}
12 changes: 12 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

namespace Devtical\Helpers\Tests;

use Devtical\Helpers\HelperServiceProvider;
use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
/**
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageProviders($app): array
{
return [
HelperServiceProvider::class,
];
}
}

0 comments on commit 79a8d34

Please sign in to comment.