Skip to content
Merged
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
4 changes: 4 additions & 0 deletions core/src/Providers/ArtisanServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Console\Scheduling\ScheduleFinishCommand;
use Illuminate\Console\Scheduling\ScheduleTestCommand;
use Illuminate\Console\Scheduling\ScheduleWorkCommand;
use Illuminate\Console\Signals;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Console\Seeds\SeedCommand;
Expand All @@ -22,6 +23,7 @@
use Illuminate\Database\Console\Migrations\RefreshCommand as MigrateRefreshCommand;
use Illuminate\Database\Console\Migrations\RollbackCommand as MigrateRollbackCommand;
use Illuminate\Database\Console\Migrations\MigrateMakeCommand;
use Symfony\Component\Console\SignalRegistry\SignalRegistry;

use EvolutionCMS\Console\ClearCompiledCommand;
use EvolutionCMS\Console\VendorPublishCommand;
Expand Down Expand Up @@ -104,6 +106,8 @@ class ArtisanServiceProvider extends ServiceProvider
*/
public function register()
{
Signals::resolveAvailabilityUsing(static fn () => SignalRegistry::isSupported());

$hereCommands = array_merge(
$this->commands, $this->devCommands
);
Expand Down
55 changes: 55 additions & 0 deletions core/tests/Unit/Console/ConsoleSignalsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use EvolutionCMS\Providers\ArtisanServiceProvider;
use Illuminate\Console\Command;
use Illuminate\Console\Signals;
use Illuminate\Container\Container;
use Symfony\Component\Console\Application;

beforeEach(function () {
$this->resolver = new ReflectionProperty(Signals::class, 'availabilityResolver');
$this->previousResolver = $this->resolver->getValue();
$this->resolver->setValue(null, null);

(new ArtisanServiceProvider(new Container()))->register();
});

afterEach(function () {
$this->resolver->setValue(null, $this->previousResolver);
});

test('console boot registers signal availability for the current runtime', function () {
$called = false;

Signals::whenAvailable(function () use (&$called) {
$called = true;
});

expect($called)->toBe(function_exists('pcntl_signal'));
});

test('commands can trap and release signals after console boot', function () {
$command = new Command();
$command->setApplication(new Application());
$resolved = false;
$signal = defined('SIGUSR1') ? SIGUSR1 : 10;
$previousHandler = function_exists('pcntl_signal_get_handler')
? pcntl_signal_get_handler($signal)
: null;

try {
$command->trap(function () use (&$resolved, $signal) {
$resolved = true;

return $signal;
}, static function () {});

expect($resolved)->toBe(function_exists('pcntl_signal'));
} finally {
$command->untrap();
}

if ($previousHandler !== null) {
expect(pcntl_signal_get_handler($signal))->toBe($previousHandler);
}
});
Loading