Skip to content
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
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0, 8.1, 8.2]
laravel: [9.*, 10.*]
php: [8.1, 8.2, 8.3]
laravel: [10.*, 11.*]
dependency-version: [prefer-lowest, prefer-stable]
exclude:
- laravel: 10.*
php: 8.0
- laravel: 11.*
php: 8.1

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

Expand Down Expand Up @@ -51,4 +51,4 @@ jobs:

- name: Run PHPUnit tests
run: |
vendor/bin/phpunit --testdox
vendor/bin/phpunit
1 change: 0 additions & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ enabled:
- no_blank_lines_after_phpdoc
- no_blank_lines_after_return
- no_blank_lines_after_throw
- no_blank_lines_between_imports
- no_blank_lines_between_traits
- no_empty_comment
- no_empty_phpdoc
Expand Down
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ Each step or stage in the process is called a state. You do also define transiti
A workflow consist of **state** and **actions** to get from one state to another.
These **actions** are called **transitions** which describes how to get from one state to another.
## Installation
```
$ composer require ringierimu/state-workflow
```bash
composer require ringierimu/state-workflow
```

Publish `config/workflow.php` file
```php
$ php artisan vendor:publish --provider="Ringierimu\StateWorkflow\StateWorkflowServiceProvider"
```bash
php artisan vendor:publish --tag="state-workflow-config"
```
Run migrations

Publish migration
```bash
php artisan vendor:publish --tag="state-workflow-migration"
```
$ php artisan migrate

Run migration
```bash
php artisan migrate
```
## Configuration
1. Open `config/workflow.php` and configure it
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
}
],
"require": {
"php": "^8.0",
"illuminate/events": "^9.52|^10.0",
"illuminate/support": "^9.52|^10.0",
"symfony/event-dispatcher": "^5.1",
"php": "^8.1",
"illuminate/events": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0",
"symfony/event-dispatcher": "^6.0|^7.0",
"symfony/workflow": "^5.1",
"symfony/property-access": "^5.1"
},
"require-dev": {
"funkjedi/composer-include-files": "^1.0",
"mockery/mockery": "^1.3|^1.4.2",
"orchestra/testbench": "^6.24|^7.0|^8.0",
"phpunit/phpunit": "^9.5|^10.0"
"orchestra/testbench": "^8.0|^9.15",
"phpunit/phpunit": "^10.0|^11.0"
},
"extra": {
"include_files": [
Expand Down
19 changes: 12 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<ini name="memory_limit" value="512M"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
13 changes: 1 addition & 12 deletions src/StateWorkflowServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function boot()
{
$this->publishConfig();
$this->publishDatabase();
$this->loadMigrations();
$this->registerCommands();
}

Expand Down Expand Up @@ -78,17 +77,7 @@ protected function publishDatabase()
$path = 'migrations/' . date('Y_m_d_His', time());
$this->publishes([
$this->migrationPath() . '/create_state_workflow_histories_table.php' => database_path($path . '_create_state_workflow_histories_table.php'),
], 'state-workflow-migrations');
}
}

/**
* Load migration files.
*/
protected function loadMigrations()
{
if ($this->app->runningInConsole()) {
$this->loadMigrationsFrom($this->migrationPath());
], 'state-workflow-migration');
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function getEnvironmentSetUp($app)
*/
protected function defineDatabaseMigrations()
{
$this->loadLaravelMigrations();
$this->loadMigrationsFrom(base_path('migrations'));
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
$this->loadMigrationsFrom(__DIR__ . '/Fixtures/database/migrations/');
}
Expand Down
43 changes: 5 additions & 38 deletions tests/Unit/UserUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,23 @@
*/
class UserUnitTest extends TestCase
{
/**
* @test
*
* @throws \ReflectionException
*/
public function it_return_workflow_instance()
public function test_it_return_workflow_instance()
{
$this->assertInstanceOf(StateWorkflow::class, $this->user->workflow());
}

/**
* Test current state to be new.
*
* @test
*
* @throws \ReflectionException
*/
public function is_current_state_new()
public function test_is_current_state_new()
{
$this->assertEquals('new', $this->user->state());
}

/**
* Test if transition can be applied or not.
*
* @test
*
* @throws \ReflectionException
*/
public function can_apply_transition()
public function test_can_apply_transition()
{
$this->assertTrue($this->user->canTransition('create'));
$this->assertFalse($this->user->canTransition('block'));
}

/**
* Test invalid transition.
*
* @test
*
* @throws \ReflectionException
*/
public function invalid_transition_throws_exception()
public function test_invalid_transition_throws_exception()
{
$expectedExceptionClass = class_exists(NotEnabledTransitionException::class)
? NotEnabledTransitionException::class
Expand All @@ -64,14 +38,7 @@ public function invalid_transition_throws_exception()
$this->user->applyTransition('block');
}

/**
* Change Model states by applying transitions.
*
* @test
*
* @throws \ReflectionException
*/
public function apply_transitions()
public function test_apply_transitions()
{
$this->user->applyTransition('create');
$this->user = $this->user->refresh();
Expand Down
7 changes: 1 addition & 6 deletions tests/WorkflowSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
*/
class WorkflowSubscriberTest extends TestCase
{
/**
* @test
*
* @throws \ReflectionException
*/
public function if_workflow_subscriber_emit_events()
public function test_if_workflow_subscriber_emit_events()
{
global $events;
$events = [];
Expand Down
Loading