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

Feat/lucid 2.x #44

Open
wants to merge 12 commits into
base: main
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
51 changes: 29 additions & 22 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,15 @@ on:
pull_request:
branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [7.0.21, 7.1, 7.2, 7.3, 7.4, 8.0]
php: [8.0, 8.1]
stability: [prefer-lowest, prefer-stable]
laravel: [5.5, 6.x, 7.x, 8.x]
exclude:
- laravel: 5.5
php: 8.0
- laravel: 6.x
php: 7.0.21
- laravel: 6.x
php: 7.1
- laravel: 7.x
php: 7.0.21
- laravel: 7.x
php: 7.1
- laravel: 8.x
php: 7.0.21
- laravel: 8.x
php: 7.1
- laravel: 8.x
php: 7.2
laravel: [9.x]

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

Expand All @@ -48,7 +29,6 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
tools: composer:v2
coverage: none

Expand All @@ -71,3 +51,30 @@ jobs:
cp $GITHUB_WORKSPACE/bin/test-commands.sh laravel-${{ matrix.laravel }}
cd laravel-${{ matrix.laravel }}
./test-commands.sh

code_quality:
runs-on: ubuntu-latest

name: Code Quality

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2
coverage: none

- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist

- name: Run Pint
run: ./vendor/bin/pint --test -v --ansi

- name: Run PHPStan
run: ./vendor/bin/phpstan analyse --memory-limit=2G

- name: Run Pest
run: ./vendor/bin/pest
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Lucid Architecture's GitHub issue trackers are not intended to provide help or s

## Core Development Discussion

You may propose new features or improvements of existing Lucid Architecture behaviour in the [Lucid Discussins](https://github.com/lucidarch/lucid/discussions).
You may propose new features or improvements of existing Lucid Architecture behaviour in the [Lucid Discussions](https://github.com/lucidarch/lucid/discussions).
If you propose a new feature, please be willing to implement at least some of the code that would be needed to complete the feature, or collaborate on active ideation in the meantime.

Informal discussion regarding bugs, new features, and implementation of existing features takes place in the `#internals` channel of the [Lucid Slack workspace](https://lucid-slack.herokuapp.com/).
Expand Down
3 changes: 2 additions & 1 deletion bin/test-commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ fi
examine "app/Providers"
examine "app/Providers/RouteServiceProvider.php"
examine "resources"
examine "resources/lang"
examine "resources/views"
examine "resources/views/welcome.blade.php"
lint "resources/views/welcome.blade.php"
Expand Down Expand Up @@ -147,6 +146,7 @@ lint "tests/Unit/Services/Harbour/Operations/TwistOperationTest.php"
## --- TEARDOWN ---

./vendor/bin/lucid delete:feature trade
./vendor/bin/lucid delete:feature finance/wallet/pay
./vendor/bin/lucid delete:job submitTradeRequest shipping
./vendor/bin/lucid delete:job sail boat
./vendor/bin/lucid delete:model bridge
Expand All @@ -156,6 +156,7 @@ lint "tests/Unit/Services/Harbour/Operations/TwistOperationTest.php"
rm app/Http/Controllers/TradeController.php

./vendor/bin/lucid delete:feature trade harbour
./vendor/bin/lucid delete:feature port/yacht/park harbour
./vendor/bin/lucid delete:operation spin harbour
./vendor/bin/lucid delete:operation twist harbour
rm app/Services/Harbour/Http/Controllers/TradeController.php
Expand Down
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,30 @@
}
],
"require": {
"php": ">=8.0",
"ext-dom": "*",
"mockery/mockery": "*",
"symfony/console": "*",
"symfony/filesystem": "*",
"symfony/finder": "*",
"symfony/process": "*"
},
"require-dev": {
"laravel/pint": "^1.4",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^8.0",
"pestphp/pest": "^1.22"
},
"autoload": {
"psr-4": {
"Lucid\\": "src/"
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
4 changes: 3 additions & 1 deletion lucid
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

use Illuminate\Events\Dispatcher;

if (file_exists('./vendor/autoload.php')) {
require './vendor/autoload.php';
} else if(file_exists(__DIR__.'/vendor/autoload.php')) {
Expand Down Expand Up @@ -41,7 +43,7 @@ $commands = [
new Lucid\Console\Commands\OperationDeleteCommand(),
];

$app = new Symfony\Component\Console\Application('Lucid', '1.0.0');
$app = new Illuminate\Console\Application($laravel, new Dispatcher(), '1.0.0');
array_walk($commands, [$app, 'add']);

$app->run();
24 changes: 24 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon

parameters:

paths:
- src

# Level 0 is the lowest, 8 is the highest
level: 5

checkMissingIterableValueType: false
reportUnmatchedIgnoredErrors: true
treatPhpDocTypesAsCertain: false
polluteScopeWithLoopInitialAssignments: false
polluteScopeWithAlwaysIterableForeach: false
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkUninitializedProperties: true

parallel:
processTimeout: 300.00

ignoreErrors:
- '/Call to an undefined method Mockery\\ExpectationInterface|Mockery\\HigherOrderMessage\:\:once\(\)/'
17 changes: 17 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
</phpunit>
33 changes: 14 additions & 19 deletions src/Bus/Marshal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@

namespace Lucid\Bus;

use Exception;
use ArrayAccess;
use Exception;
use Illuminate\Http\Request;
use ReflectionParameter;

trait Marshal
{
/**
* Marshal a command from the given array accessible object.
*
* @param string $command
* @param \ArrayAccess $source
* @param array $extras
*
* @return mixed
*/
protected function marshal($command, ArrayAccess $source, array $extras = [])
{
protected function marshal(
string $command,
iterable|Request $source,
array $extras = []
): mixed {
$parameters = [];

foreach ($source as $name => $parameter) {
$parameters[$name] = $parameter;
}
Expand All @@ -33,17 +31,14 @@ protected function marshal($command, ArrayAccess $source, array $extras = [])
/**
* Get a parameter value for a marshaled command.
*
* @param string $command
* @param \ArrayAccess $source
* @param \ReflectionParameter $parameter
* @param array $extras
*
* @return mixed
* @throws Exception
*/
protected function getParameterValueForCommand($command, ArrayAccess $source,
ReflectionParameter $parameter, array $extras = [])
{
protected function getParameterValueForCommand(
string $command,
ArrayAccess $source,
ReflectionParameter $parameter,
array $extras = []
): mixed {
if (array_key_exists($parameter->name, $extras)) {
return $extras[$parameter->name];
}
Expand Down
11 changes: 3 additions & 8 deletions src/Bus/ServesFeatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Lucid\Bus;

use Illuminate\Support\Collection;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Collection;
use Lucid\Events\FeatureStarted;

trait ServesFeatures
Expand All @@ -13,16 +13,11 @@ trait ServesFeatures

/**
* Serve the given feature with the given arguments.
*
* @param string $feature
* @param array $arguments
*
* @return mixed
*/
public function serve($feature, $arguments = [])
public function serve(string $feature, array $arguments = []): mixed
{
event(new FeatureStarted($feature, $arguments));

return $this->dispatch($this->marshal($feature, new Collection(), $arguments));
return $this->dispatchSync($this->marshal($feature, new Collection(), $arguments));
}
}
51 changes: 23 additions & 28 deletions src/Bus/UnitDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
namespace Lucid\Bus;

use App;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Lucid\Events\JobStarted;
use Lucid\Events\OperationStarted;
use Lucid\Testing\UnitMock;
use Lucid\Testing\UnitMockRegistry;
use ReflectionClass;
use Lucid\Units\Job;
use ReflectionException;
use Lucid\Units\Operation;
use Illuminate\Http\Request;
use Lucid\Events\JobStarted;
use Illuminate\Support\Collection;
use Lucid\Events\OperationStarted;
use Illuminate\Foundation\Bus\DispatchesJobs;
use ReflectionClass;
use ReflectionException;

trait UnitDispatcher
{
Expand All @@ -25,24 +25,21 @@ trait UnitDispatcher
* laravel function dispatchFromArray.
* When the $arguments is an instance of Request
* it will call dispatchFrom instead.
*
* @param mixed $unit
* @param array|\Illuminate\Http\Request $arguments
* @param array $extra
*
* @return mixed
*/
public function run($unit, $arguments = [], $extra = [])
{
if (is_object($unit) && !App::runningUnitTests()) {
$result = $this->dispatch($unit);
public function run(
mixed $unit,
array|Request $arguments = [],
array $extra = []
): mixed {
if (is_object($unit) && ! App::runningUnitTests()) {
$result = $this->dispatchSync($unit);
} elseif ($arguments instanceof Request) {
$result = $this->dispatch($this->marshal($unit, $arguments, $extra));
$result = $this->dispatchSync($this->marshal($unit, $arguments, $extra));
} else {
if (!is_object($unit)) {
if (! is_object($unit)) {
$unit = $this->marshal($unit, new Collection(), $arguments);

// don't dispatch unit when in tests and have a mock for it.
// don't dispatch unit when in tests and have a mock for it.
} elseif (App::runningUnitTests() && app(UnitMockRegistry::class)->has(get_class($unit))) {
/** @var UnitMock $mock */
$mock = app(UnitMockRegistry::class)->get(get_class($unit));
Expand All @@ -58,7 +55,7 @@ public function run($unit, $arguments = [], $extra = [])
);
}

$result = $this->dispatch($unit);
$result = $this->dispatchSync($unit);
}

if ($unit instanceof Operation) {
Expand All @@ -75,15 +72,13 @@ public function run($unit, $arguments = [], $extra = [])
/**
* Run the given unit in the given queue.
*
* @param string $unit
* @param array $arguments
* @param string|null $queue
*
* @return mixed
* @throws ReflectionException
*/
public function runInQueue($unit, array $arguments = [], $queue = 'default')
{
public function runInQueue(
string $unit,
array $arguments = [],
?string $queue = 'default'
): mixed {
// instantiate and queue the unit
$reflection = new ReflectionClass($unit);
$instance = $reflection->newInstanceArgs($arguments);
Expand Down
Loading