Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roelofr feature/GitHub actions #33

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/check-style.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 --allow-risky=yes

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

on: [push, pull_request]

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [7.4]
laravel: [7.*, 8.*]
dependency-version: [prefer-stable]
include:
- laravel: 7.*
testbench: 5.*
- laravel: 8.*
testbench: 6.*

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

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, fileinfo
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call doesn't actually install anything anymore, so the tests probably go boom

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the command works fine, but the test's assertion fail


- name: Execute tests
run: vendor/bin/phpunit
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
composer.lock
/vendor
/vendor
.php_cs.cache
37 changes: 37 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('vendor')
->notPath('tests/fixtures/*')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If memory serves me right, this is deprecated. Use new PhpCsFixer\Config instead

->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => 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,
],
])
->ex
->setFinder($finder);
4 changes: 0 additions & 4 deletions .styleci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require-dev": {
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0",
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "8.0 || ^9.0"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions src/BlueprintNovaAddonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Naoray\BlueprintNovaAddon;

use Blueprint\Blueprint;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField;
use Illuminate\Contracts\Support\DeferrableProvider;
use Naoray\BlueprintNovaAddon\Tasks\AddRegularFields;
use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields;
use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField;
use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields;
use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields;

class BlueprintNovaAddonServiceProvider extends ServiceProvider implements DeferrableProvider
{
Expand All @@ -19,7 +19,7 @@ public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
dirname(__DIR__).'/config/nova_blueprint.php' => config_path('nova_blueprint.php'),
dirname(__DIR__) . '/config/nova_blueprint.php' => config_path('nova_blueprint.php'),
], 'nova_blueprint');
}
}
Expand All @@ -30,8 +30,8 @@ public function boot()
public function register()
{
$this->mergeConfigFrom(
dirname(__DIR__).'/config/nova_blueprint.php',
'blueprint-nova-config'
dirname(__DIR__) . '/config/nova_blueprint.php',
'blueprint-nova'
);

$this->app->singleton(NovaGenerator::class, function ($app) {
Expand Down
24 changes: 12 additions & 12 deletions src/NovaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Naoray\BlueprintNovaAddon;

use Blueprint\Tree;
use Blueprint\Blueprint;
use Blueprint\Contracts\Generator;
use Blueprint\Models\Model;
use Blueprint\Tree;
use Illuminate\Pipeline\Pipeline;
use Illuminate\Support\Str;
use Illuminate\Pipeline\Pipeline;
use Blueprint\Contracts\Generator;
use Naoray\BlueprintNovaAddon\Contracts\Task;
use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields;
use Naoray\BlueprintNovaAddon\Tasks\RemapImports;
use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields;

class NovaGenerator implements Generator
{
Expand All @@ -34,13 +34,13 @@ public function output(Tree $tree): array
{
$output = [];

$stub = $this->files->get($this->stubPath().DIRECTORY_SEPARATOR.'class.stub');
$stub = $this->files->get($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub');

/** @var \Blueprint\Models\Model $model */
foreach ($tree->models() as $model) {
$path = $this->getPath($model);

if (! $this->files->exists(dirname($path))) {
if (!$this->files->exists(dirname($path))) {
$this->files->makeDirectory(dirname($path), 0755, true);
}

Expand All @@ -54,9 +54,9 @@ public function output(Tree $tree): array

protected function getPath(Model $model): string
{
$path = str_replace('\\', '/', Blueprint::relativeNamespace($this->getNovaNamespace($model).'/'.$model->name()));
$path = str_replace('\\', '/', Blueprint::relativeNamespace($this->getNovaNamespace($model) . '/' . $model->name()));

return config('blueprint.app_path').'/'.$path.'.php';
return config('blueprint.app_path') . '/' . $path . '.php';
}

protected function populateStub(string $stub, Model $model): string
Expand All @@ -72,7 +72,7 @@ protected function populateStub(string $stub, Model $model): string

$stub = str_replace('DummyNamespace', $this->getNovaNamespace($model), $stub);
$stub = str_replace('DummyClass', $model->name(), $stub);
$stub = str_replace('DummyModel', '\\'.$model->fullyQualifiedClassName(), $stub);
$stub = str_replace('DummyModel', '\\' . $model->fullyQualifiedClassName(), $stub);
$stub = str_replace('// fields...', $data['fields'], $stub);
$stub = str_replace('use Illuminate\Http\Request;', implode(PHP_EOL, $data['imports']), $stub);

Expand All @@ -82,10 +82,10 @@ protected function populateStub(string $stub, Model $model): string
protected function getNovaNamespace(Model $model): string
{
$namespace = Str::after($model->fullyQualifiedNamespace(), config('blueprint.namespace'));
$namespace = config('blueprint.namespace').'\Nova'.$namespace;
$namespace = config('blueprint.namespace') . '\Nova' . $namespace;

if (config('blueprint.models_namespace')) {
$namespace = str_replace('\\'.config('blueprint.models_namespace'), '', $namespace);
$namespace = str_replace('\\' . config('blueprint.models_namespace'), '', $namespace);
}

return $namespace;
Expand All @@ -110,7 +110,7 @@ protected function filteredTasks(): array
{
$tasks = $this->tasks;

if (! config('nova_blueprint.timestamps')) {
if (!config('nova_blueprint.timestamps')) {
$tasks = array_filter($tasks, function ($key) {
return $key !== AddTimestampFields::class;
}, ARRAY_FILTER_USE_KEY);
Expand Down
16 changes: 8 additions & 8 deletions tests/NovaGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Naoray\BlueprintNovaAddon\Tests;

use Blueprint\Blueprint;
use Blueprint\Tree;
use Blueprint\Blueprint;
use Naoray\BlueprintNovaAddon\HasStubPath;
use Naoray\BlueprintNovaAddon\NovaGenerator;
use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField;
use Naoray\BlueprintNovaAddon\Tasks\AddRegularFields;
use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields;
use Naoray\BlueprintNovaAddon\Tasks\AddIdentifierField;
use Naoray\BlueprintNovaAddon\Tasks\AddTimestampFields;
use Naoray\BlueprintNovaAddon\Tasks\AddRelationshipFields;

class NovaGeneratorTest extends TestCase
{
Expand Down Expand Up @@ -44,7 +44,7 @@ protected function setUp(): void
public function output_generates_nothing_for_empty_tree()
{
$this->files->expects('get')
->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub')
->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub')
->andReturn(file_get_contents('stubs/class.stub'));

$this->files->shouldNotHaveReceived('put');
Expand All @@ -59,7 +59,7 @@ public function output_generates_nothing_for_empty_tree()
public function output_generates_nova_resources($definition, $path, $novaResource)
{
$this->files->expects('get')
->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub')
->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub')
->andReturn(file_get_contents('stubs/class.stub'));

$this->files->expects('exists')
Expand All @@ -81,7 +81,7 @@ public function output_generates_nova_resources($definition, $path, $novaResourc
public function output_generates_relationships()
{
$this->files->expects('get')
->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub')
->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub')
->andReturn(file_get_contents('stubs/class.stub'));

$this->files->expects('exists')
Expand All @@ -106,7 +106,7 @@ public function output_respects_blueprint_configurations()
$this->app['config']->set('blueprint.models_namespace', 'Models');

$this->files->expects('get')
->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub')
->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub')
->andReturn(file_get_contents('stubs/class.stub'));

$this->files->expects('exists')
Expand All @@ -131,7 +131,7 @@ public function output_respects_packages_configuration()
$this->app['config']->set('nova_blueprint.timestamps', false);

$this->files->expects('get')
->with($this->stubPath().DIRECTORY_SEPARATOR.'class.stub')
->with($this->stubPath() . DIRECTORY_SEPARATOR . 'class.stub')
->andReturn(file_get_contents('stubs/class.stub'));

$this->files->expects('exists')
Expand Down