Skip to content

Commit

Permalink
Merge pull request #8 from RingierIMU/feature/support-laravel-6
Browse files Browse the repository at this point in the history
Add support for laravel 6
  • Loading branch information
datashaman authored Feb 5, 2020
2 parents f21d81e + a88cf8b commit a49c006
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 57 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[{*.js,*.json}]
indent_size = 2

[*.yml]
indent_size = 2

[Makefile]
indent_style = tabs
21 changes: 21 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
* text=auto eol=lf whitespace=tab-in-indent,blank-at-eol,tabwidth=4
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/.styleci.yml export-ignore
/tests export-ignore
/.travis.yml export-ignore
*.eot binary
*.gif binary
*.jpeg binary
*.jpg binary
*.pdf binary
*.png binary
*.svg binary
*.ttf binary
*.woff binary
*.woff2 binary
*.zip binary
*.tgz binary
53 changes: 53 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php: [7.2, 7.3, 7.4]
setup: [basic, stable, lowest]
exclude:
- php: 7.4
setup: lowest

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

- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: ${{matrix.php}}

- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache Composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: |
if [[ ${{matrix.setup}} = 'basic' ]]; then composer install --prefer-dist --no-interaction --no-suggest; fi
if [[ ${{matrix.setup}} = 'stable' ]]; then composer update --prefer-dist --no-interaction --no-suggest --prefer-stable; fi
if [[ ${{matrix.setup}} = 'lowest' ]]; then composer update --prefer-dist --no-interaction --no-suggest --prefer-lowest --prefer-stable; fi
- name: Run PHPUnit tests
run: |
vendor/bin/phpunit --testdox
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Created by .ignore support plugin (hsz.mobi)
vendor/
composer.lock
.idea/
/composer.lock
/.idea/
/.phpunit.result.cache
/vendor/
58 changes: 32 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
{
"name": "ringierimu/state-workflow",
"type": "library",
"description": "State Management workflow for Laravel",
"keywords": [
"workflow",
"state management",
"laravel"
],
"homepage": "https://github.com/RingierIMU/state-workflow",
"keywords": ["workflow","state management","laravel"],
"type": "library",
"license": "MIT",
"require": {
"php": ">=5.6.4",
"symfony/workflow": "^3.3 || ^4.0 || ^4.1",
"illuminate/support": "^5.3 || ^5.4 || ^5.5 || ^5.6 || ^5.7",
"symfony/event-dispatcher": "^3.3 || ^4.0 || ^4.2",
"illuminate/events": "^5.3 || ^5.4 || ^5.5 || ^5.6 || ^5.7"
},
"authors": [
{
"name": "Norby Baruani",
"email": "[email protected]",
"role": "Developer"
}
],
"autoload": {
"classmap": [
"tests/Fixtures/database/factories"
],
"psr-4": {
"Ringierimu\\StateWorkflow\\": "src/"
}
"require": {
"php": ">=7.1.3",
"illuminate/events": "^5.6 || ^6.0",
"illuminate/support": "^5.6 || ^6.0",
"symfony/event-dispatcher": "^3.4 || ^4.0",
"symfony/workflow": "^3.4 || ^4.0"
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
"require-dev": {
"funkjedi/composer-include-files": "^1.0",
"mockery/mockery": "^1.3",
"orchestra/database": "^3.5 || ^4.0",
"orchestra/testbench": "^3.6 || ^4.0",
"phpunit/phpunit": "^6.0 || ^7.0 || ^8.0"
},
"extra": {
"include_files": [
"tests/Fixtures/Helpers.php"
],
"laravel": {
"providers": [
"Ringierimu\\StateWorkflow\\StateWorkflowServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Ringierimu\\StateWorkflow\\": "src/"
},
"include_files": [
"tests/Fixtures/Helpers.php"
"classmap": [
"tests/Fixtures/database/factories"
]
},
"require-dev": {
"phpunit/phpunit": "^6.0 || ^7.0",
"orchestra/testbench": "^3.7",
"funkjedi/composer-include-files": "^1.0"
"autoload-dev": {
"psr-4": {
"Ringierimu\\StateWorkflow\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
8 changes: 6 additions & 2 deletions src/Console/Commands/StateWorkflowDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public function handle()
$config = Config::get('workflow');

if (!isset($config[$workflowName])) {
throw new Exception("Workflow $workflowName is not configured. Make sure it is configured correctly on the config file.");
throw new Exception(
"Workflow $workflowName is not configured. Make sure it is configured correctly on the config file."
);
}

if (!$config[$workflowName]['class']) {
Expand All @@ -59,7 +61,9 @@ public function handle()
$model = $ref->newInstance();

if (!method_exists($model, 'workflow')) {
throw new Exception("Class $class does not support State Workflow. Make sure Class is configured correctly");
throw new Exception(
"Class $class does not support State Workflow. Make sure Class is configured correctly"
);
}

/** @var StateWorkflow $workflow */
Expand Down
9 changes: 8 additions & 1 deletion src/WorkflowRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\StateMachine;
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\Workflow;
Expand Down Expand Up @@ -81,7 +82,13 @@ public function get($subject, $workflowName = null)
*/
public function add(StateWorkflow $workflow, $supportStrategy)
{
$this->registry->addWorkflow($workflow, new InstanceOfSupportStrategy($supportStrategy));
// Add method became addWorkflow method in Symfony Workflow Component v4.1
// InstanceOfSupportStrategy class became ClassInstanceSupportStrategy in v4.1
$method = method_exists($this->registry, 'addWorkflow') ? 'addWorkflow' : 'add';
$strategyClass = class_exists(InstanceOfSupportStrategy::class)
? InstanceOfSupportStrategy::class
: ClassInstanceSupportStrategy::class;
$this->registry->$method($workflow, new $strategyClass($supportStrategy));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Models/User.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Fixtures\Models;
namespace Ringierimu\StateWorkflow\Tests\Fixtures\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Ringierimu\StateWorkflow\Traits\HasWorkflowTrait;
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Subscriber/UserEventSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Fixtures\Subscriber;
namespace Ringierimu\StateWorkflow\Tests\Fixtures\Subscriber;

use Illuminate\Support\Facades\Log;
use Ringierimu\StateWorkflow\Events\CompletedEvent;
Expand Down
9 changes: 6 additions & 3 deletions tests/Fixtures/Traits/ConfigTrait.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace Tests\Fixtures\Traits;
namespace Ringierimu\StateWorkflow\Tests\Fixtures\Traits;

use Ringierimu\StateWorkflow\Tests\Fixtures\Models\User;
use Ringierimu\StateWorkflow\Tests\Fixtures\Subscriber\UserEventSubscriber;

/**
* Trait ConfigTrait.
Expand All @@ -16,10 +19,10 @@ public function getWorflowConfig()
// this should be your model name in camelcase. eg. PropertyListing::Class => propertyListing
'user' => [
// class of your domain object
'class' => \Tests\Fixtures\Models\User::class,
'class' => User::class,

// Subscriber for this workflow which contains business rules
'subscriber' => \Tests\Fixtures\Subscriber\UserEventSubscriber::class,
'subscriber' => UserEventSubscriber::class,

// property of your object holding the actual state (default is "current_state")
'property_path' => 'user_state',
Expand Down
5 changes: 3 additions & 2 deletions tests/Fixtures/database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Faker\Generator as Faker;
use Illuminate\Support\Str;

/*
|--------------------------------------------------------------------------
Expand All @@ -13,12 +14,12 @@
|
*/

$factory->define(\Tests\Fixtures\Models\User::class, function (Faker $faker) {
$factory->define(Ringierimu\StateWorkflow\Tests\Fixtures\Models\User::class, function (Faker $faker) {
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => str_random(10),
'remember_token' => Str::random(10),
];
});
27 changes: 16 additions & 11 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Tests;
namespace Ringierimu\StateWorkflow\Tests;

use Ringierimu\StateWorkflow\StateWorkflowServiceProvider;
use Tests\Fixtures\Models\User;
use Tests\Fixtures\Traits\ConfigTrait;
use Ringierimu\StateWorkflow\Tests\Fixtures\Models\User;
use Ringierimu\StateWorkflow\Tests\Fixtures\Traits\ConfigTrait;

/**
* Class TestCase.
Expand All @@ -16,19 +16,24 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
/** @var User */
protected $user;

public function setUp()
public function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub

$this->loadMigrationsFrom(__DIR__.'/Fixtures/database/migrations/');
$this->withFactories(__DIR__.'/Fixtures/database/factories/');

$this->user = factory(User::class)->create([
'user_state' => 'new',
]);

auth()->login(factory(User::class)->create([
'user_state' => 'new',
]));
$this->user = factory(User::class)->create(
[
'user_state' => 'new',
]
);

auth()->login(factory(User::class)->create(
[
'user_state' => 'new',
]
));
}

/**
Expand Down
14 changes: 9 additions & 5 deletions tests/Unit/UserUnitTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

namespace Tests\Unit;
namespace Ringierimu\StateWorkflow\Tests\Unit;

use Ringierimu\StateWorkflow\Tests\Fixtures\Models\User;
use Ringierimu\StateWorkflow\Tests\TestCase;
use Ringierimu\StateWorkflow\Workflow\StateWorkflow;
use Symfony\Component\Workflow\Exception\LogicException;
use Symfony\Component\Workflow\Exception\NotEnabledTransitionException;
use Tests\Fixtures\Models\User;
use Tests\TestCase;

/**
* Class UserTest.
Expand All @@ -15,7 +16,7 @@ class UserUnitTest extends TestCase
/** @var User */
protected $user;

public function setUp()
public function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub

Expand Down Expand Up @@ -72,7 +73,10 @@ public function can_apply_transition()
*/
public function invalid_transition_throws_exception()
{
$this->expectException(NotEnabledTransitionException::class);
$expectedExceptionClass = class_exists(NotEnabledTransitionException::class)
? NotEnabledTransitionException::class
: LogicException::class;
$this->expectException($expectedExceptionClass);

$this->user->applyTransition('block');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/WorkflowSubscriberTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests {
namespace Ringierimu\StateWorkflow\Tests {

use Ringierimu\StateWorkflow\WorkflowRegistry;

Expand Down

0 comments on commit a49c006

Please sign in to comment.