Skip to content

Commit

Permalink
Bump max Laravel version (#131)
Browse files Browse the repository at this point in the history
* Bump max Laravel version
* Move phpstan to dev requirements
* Change versioning
  • Loading branch information
eugene-nuwber authored Apr 29, 2024
1 parent 3344661 commit a2b387a
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 56 deletions.
29 changes: 24 additions & 5 deletions .github/workflows/static-code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,29 @@ name: Static code analysis
on: [push]

jobs:
static-code-analysis:
container: ghcr.io/nuwber/phpqa-docker:php8.1
types:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.2', '8.3']
name: Static code analysis (PHP ${{ matrix.php-versions }})
steps:
- uses: actions/checkout@v2
- name: phpqa
run: phpqa
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer:v2
coverage: none

- name: Install dependencies
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute type checking
run: vendor/bin/phpstan --configuration="phpstan.neon.dist"
4 changes: 2 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.2']
php-versions: ['8.1', '8.2', '8.3']
name: Testing on PHP ${{ matrix.php-versions }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: setup
uses: shivammathur/setup-php@v2
with:
Expand Down
13 changes: 0 additions & 13 deletions .phpqa.yml

This file was deleted.

17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
"require": {
"php": "^8.1",
"ext-json": "*",
"enqueue/amqp-lib": "^0.10",
"illuminate/support": "^9.0|^10.0",
"illuminate/events": "^9.0|^10.0",
"illuminate/console": "^9.0|^10.0",
"illuminate/container": "^9.0|^10.0"
"enqueue/amqp-lib": "^0.10.19",
"illuminate/support": "9 - 11",
"illuminate/events": "9 - 11",
"illuminate/console": "9 - 11",
"illuminate/container": "9 - 11"
},
"replace": {
"rabbitevents/foundation": "self.version",
"rabbitevents/publisher": "self.version",
"rabbitevents/listener": "self.version"
},
"require-dev": {
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^10.0",
"vlucas/phpdotenv": "^v5.4.1"
"mockery/mockery": "^1.6.0",
"phpunit/phpunit": "^10.5|^11.0",
"vlucas/phpdotenv": "^v5.4.1",
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
parameters:
paths:
- src
level: 0
ignoreErrors:
- "#Unsafe usage of new static#"
-
message: "#^Call to an undefined static method Illuminate\\\\Support\\\\ServiceProvider\\:\\:addProviderToBootstrapFile\\(\\)\\.$#"
reportUnmatched: false
38 changes: 22 additions & 16 deletions src/RabbitEvents/Foundation/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use RabbitEvents\Foundation\RabbitEventsServiceProvider;

/**
* @codeCoverageIgnore
Expand Down Expand Up @@ -32,8 +33,6 @@ public function handle(): void
$this->callSilent('vendor:publish', ['--tag' => 'rabbitevents-config']);

if (in_array('rabbitevents-listener-provider', $registeredTags)) {
$this->comment('Publishing RabbitEvents Service Provider...');
$this->callSilent('vendor:publish', ['--tag' => 'rabbitevents-listener-provider']);
$this->registerServiceProvider();
}

Expand All @@ -42,24 +41,31 @@ public function handle(): void

private function registerServiceProvider(): void
{
$this->comment('Publishing RabbitEvents Service Provider...');
$this->callSilent('vendor:publish', ['--tag' => 'rabbitevents-listener-provider']);

$namespace = Str::replaceLast('\\', '', $this->laravel->getNamespace());
$prefix = "{$namespace}\\Providers";
$appConfig = file_get_contents($this->laravel->configPath('app.php'));
if (Str::contains($appConfig, $prefix . 'RabbitEventsServiceProvider::class')) {
return;

if (file_exists($this->getLaravel()->bootstrapPath('providers.php'))) {
ServiceProvider::addProviderToBootstrapFile("{$namespace}\\Providers\\RabbitEventsServiceProvider");
} else {
$appConfig = file_get_contents($this->laravel->configPath('app.php'));
if (Str::contains($appConfig, "{$namespace}\\Providers\\RabbitEventsServiceProvider::class")) {
return;
}
file_put_contents(
$this->laravel->configPath('app.php'),
str_replace(
"{$namespace}\\Providers}\\EventServiceProvider::class," . PHP_EOL,
"{$namespace}\\Providers\\EventServiceProvider::class," . PHP_EOL
. " {$namespace}\\Providers\\RabbitEventsServiceProvider::class," . PHP_EOL,
$appConfig
)
);
}
file_put_contents(
$this->laravel->configPath('app.php'),
str_replace(
"{$prefix}\\EventServiceProvider::class," . PHP_EOL,
"{$prefix}\\EventServiceProvider::class," . PHP_EOL
. " {$prefix}\\RabbitEventsServiceProvider::class," . PHP_EOL,
$appConfig
)
);

file_put_contents($this->laravel->path('Providers/RabbitEventsServiceProvider.php'), str_replace(
"namespace App\Providers;",
'namespace App\Providers;',
"namespace {$namespace}\Providers;",
file_get_contents($this->laravel->path('Providers/RabbitEventsServiceProvider.php'))
));
Expand Down
3 changes: 0 additions & 3 deletions src/RabbitEvents/Foundation/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

namespace RabbitEvents\Foundation;

use Illuminate\Container\Container;
use Illuminate\Contracts\Container\BindingResolutionException;
use Interop\Amqp\AmqpMessage;
use JsonSerializable;
use RabbitEvents\Foundation\Amqp\MessageFactory;
use RabbitEvents\Foundation\Contracts\Transport;
use RabbitEvents\Foundation\Support\Payload;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function registerPublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/config/rabbitevents.php' => config_path('rabbitevents.php'),
__DIR__ . '/config/rabbitevents.php' => $this->app->configPath('rabbitevents.php'),
], 'rabbitevents-config');
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/RabbitEvents/Listener/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ protected function createMiddlewareCallable($mixed): callable
if (is_string($mixed)) {
return $this->createClassCallable($mixed);
}

throw new \RuntimeException('Invalid middleware definition');
}

protected function handlerShouldBeQueued($class): bool
Expand Down
3 changes: 1 addition & 2 deletions src/RabbitEvents/Listener/Message/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public function process(Message $message, ListenerOptions $options): void
*
* @param Handler $handler
* @param ListenerOptions $options
* @return mixed
* @throws Throwable
*/
public function runHandler(Handler $handler, ListenerOptions $options): mixed
public function runHandler(Handler $handler, ListenerOptions $options)
{
try {
$this->raiseBeforeEvent($handler);
Expand Down
5 changes: 2 additions & 3 deletions tests/Listener/Message/ProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Events\Dispatcher;
use Mockery as m;
use PHPUnit\Framework\Attributes\After;
use RabbitEvents\Foundation\Contracts\Transport;
use RabbitEvents\Foundation\Message;
use RabbitEvents\Listener\Events\ListenerHandled;
Expand Down Expand Up @@ -184,9 +185,7 @@ protected function mockListeners(array $listeners)
->andReturn($listeners);
}

/**
* @after
*/
#[After]
protected function clearListenersMock()
{
RabbitEvents::clearResolvedInstances();
Expand Down
7 changes: 4 additions & 3 deletions tests/Listener/WorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Container\Container;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Mockery as m;
use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\Before;
use RabbitEvents\Foundation\Consumer;
use RabbitEvents\Foundation\Exceptions\ConnectionLostException;
use RabbitEvents\Foundation\Message;
Expand All @@ -22,6 +24,7 @@ class WorkerTest extends TestCase

private $options;

#[Before]
protected function setUp(): void
{
$this->events = m::spy(Dispatcher::class);
Expand All @@ -33,9 +36,7 @@ protected function setUp(): void
$container->instance(ExceptionHandler::class, $this->exceptionHandler);
}

/**
* @after
*/
#[After]
protected function tearDown(): void
{
Container::setInstance(null);
Expand Down

0 comments on commit a2b387a

Please sign in to comment.