2026-10-05 18:10:18 -04:00
<? php
declare ( strict_types = 1 );
namespace Pterodactyl\Tests\Pest\Unit\Extensions\ExtensionProviderRuntimeTest ;
use Closure ;
use Illuminate\Console\Scheduling\Schedule ;
2026-10-06 13:57:18 -04:00
use Illuminate\Database\Console\Migrations\MigrateCommand ;
2026-10-05 18:10:18 -04:00
use Illuminate\Filesystem\FilesystemManager ;
use Illuminate\Http\Request ;
2026-10-06 13:57:18 -04:00
use Illuminate\Queue\Console\WorkCommand ;
2026-10-05 18:10:18 -04:00
use Illuminate\Support\Facades\Artisan ;
use Illuminate\Support\Facades\Cache ;
use Illuminate\Support\Facades\File ;
use Illuminate\Support\Facades\Route ;
use InvalidArgumentException ;
use Mockery ;
use Mockery\MockInterface ;
2026-10-06 13:44:08 -04:00
use Pterodactyl\Actions\Extensions\InstallExtension ;
use Pterodactyl\Actions\Extensions\RemoveExtension ;
use Pterodactyl\Actions\Extensions\ReplaceExtensionSettingFile ;
use Pterodactyl\Actions\Extensions\SetExtensionEnabled ;
use Pterodactyl\Actions\Extensions\UpdateExtensionSettings ;
use Pterodactyl\Actions\Themes\ApplyTheme ;
use Pterodactyl\Actions\Themes\ResetTheme ;
use Pterodactyl\Contracts\Extensions\InstallsExtensions ;
use Pterodactyl\Contracts\Extensions\RemovesExtensions ;
use Pterodactyl\Contracts\Extensions\ReplacesExtensionSettingFiles ;
use Pterodactyl\Contracts\Extensions\SetsExtensionEnabled ;
use Pterodactyl\Contracts\Extensions\UpdatesExtensionSettings ;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Contracts\Servers\DeletesServers ;
2026-10-06 13:44:08 -04:00
use Pterodactyl\Contracts\Themes\AppliesThemes ;
use Pterodactyl\Contracts\Themes\ResetsThemes ;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Exceptions\Extensions\InvalidExtensionException ;
use Pterodactyl\Extensions\ExtensionProvider ;
use Pterodactyl\Http\Middleware\EnsureExtensionIsAvailable ;
use Pterodactyl\Models\Server ;
2026-10-06 13:44:08 -04:00
use Pterodactyl\Services\Extensions\ExtensionActionDecorators ;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Services\Extensions\ExtensionConsoleRegistry ;
use Pterodactyl\Services\Extensions\ExtensionHeadTags ;
use Pterodactyl\Services\Extensions\ExtensionManifest ;
use Pterodactyl\Services\Extensions\ExtensionManifestValidator ;
use Pterodactyl\Services\Extensions\ExtensionRepository ;
use Pterodactyl\Services\Helpers\AssetHashService ;
use Pterodactyl\Tests\TestCase ;
use RuntimeException ;
use Symfony\Component\Console\Attribute\AsCommand ;
use Symfony\Component\Console\Command\Command ;
use Symfony\Component\Console\Input\InputInterface ;
use Symfony\Component\Console\Output\OutputInterface ;
use Throwable ;
use function pterodactylTestCase ;
uses ( TestCase :: class );
beforeEach ( function () : void {
$this -> directory = sys_get_temp_dir () . DIRECTORY_SEPARATOR . 'ptero-extension-runtime-' . uniqid ();
File :: ensureDirectoryExists ( $this -> directory );
config ([ 'extensions.enabled' => true ]);
$this -> available = [];
$this -> failures = [];
$this -> app -> bind ( DeletesServers :: class , CoreDeleter :: class );
// The layout reads the built Vite manifest; use the committed fixture instead.
$this -> app -> bind ( AssetHashService :: class , fn () : AssetHashService => new AssetHashService ( $this -> app -> make ( FilesystemManager :: class ), base_path ( 'tests/Fixtures' )));
CoreDeleter :: $deleted = [];
});
afterEach ( function () : void {
File :: deleteDirectory ( $this -> directory );
});
test ( 'a wrapped action runs extension code around the core action and honours fluent options' , function () : void {
extensions ( 'dns' );
provider ( 'dns' ) -> wrap ( DeletesServers :: class , fn ( DeletesServers $inner ) : DeletesServers => new RecordingDeleter ( $inner ));
$action = $this -> app -> make ( DeletesServers :: class );
expect ( $action ) -> toBeInstanceOf ( RecordingDeleter :: class );
expect ( $action -> withForce ()) -> toBe ( $action );
$action -> delete ( new Server );
expect ( CoreDeleter :: $deleted ) -> toBe ([ 'before' , 'forced' , 'after' ]);
expect ( $this -> failures ) -> toBe ([]);
});
test ( 'extensions wrap in load order and each resolution is decorated afresh' , function () : void {
extensions ( 'first' , 'second' );
provider ( 'first' ) -> wrap ( DeletesServers :: class , fn ( DeletesServers $inner ) : DeletesServers => new RecordingDeleter ( $inner , 'first' ));
provider ( 'second' ) -> wrap ( DeletesServers :: class , fn ( DeletesServers $inner ) : DeletesServers => new RecordingDeleter ( $inner , 'second' ));
$this -> app -> make ( DeletesServers :: class ) -> delete ( new Server );
$this -> app -> make ( DeletesServers :: class ) -> delete ( new Server );
expect ( CoreDeleter :: $deleted ) -> toBe ([
'second:before' , 'first:before' , 'deleted' , 'first:after' , 'second:after' ,
'second:before' , 'first:before' , 'deleted' , 'first:after' , 'second:after' ,
]);
});
test ( 'a wrapper is inert while its extension is not available' , function () : void {
extensions ();
provider ( 'dns' ) -> wrap ( DeletesServers :: class , fn ( DeletesServers $inner ) : DeletesServers => new RecordingDeleter ( $inner ));
expect ( $this -> app -> make ( DeletesServers :: class )) -> toBeInstanceOf ( CoreDeleter :: class );
extensions ( 'dns' );
expect ( $this -> app -> make ( DeletesServers :: class )) -> toBeInstanceOf ( RecordingDeleter :: class );
});
test ( 'a wrapper staged by a provider that never commits or fails to commit is inert' , function () : void {
extensions ( 'dns' );
$discarded = provider ( 'dns' );
$discarded -> beginRegistration ();
$discarded -> wrap ( DeletesServers :: class , fn ( DeletesServers $inner ) : DeletesServers => new RecordingDeleter ( $inner ));
$discarded -> discardRegistration ();
expect ( $this -> app -> make ( DeletesServers :: class )) -> toBeInstanceOf ( CoreDeleter :: class );
$failed = provider ( 'dns' );
$failed -> beginRegistration ();
$failed -> wrap ( DeletesServers :: class , fn ( DeletesServers $inner ) : DeletesServers => new RecordingDeleter ( $inner ));
$failed -> consoleCommands ([ ProbeCommand :: class ]);
$failed -> schedule ( function ( Schedule $schedule ) : void {
$schedule -> call ( fn () : null => null );
});
$failed -> headTags ([[ 'tag' => 'meta' , 'name' => 'theme-color' , 'content' => '#000000' ]]);
$failed -> permissions ( 'Broken.' , []);
expect ( fn () => $failed -> commitRegistration ()) -> toThrow ( InvalidArgumentException :: class );
expect ( $this -> app -> make ( DeletesServers :: class )) -> toBeInstanceOf ( CoreDeleter :: class );
expect ( $this -> app -> make ( ExtensionConsoleRegistry :: class ) -> snapshot ()) -> toBe ([ 'commands' => [], 'schedules' => []]);
expect ( $this -> app -> make ( ExtensionHeadTags :: class ) -> toHtml ()) -> toBe ( '' );
});
test ( 'a broken decorator is recorded and the core action stays resolvable' , function ( Closure $decorator , string $message ) : void {
extensions ( 'dns' );
provider ( 'dns' ) -> wrap ( DeletesServers :: class , $decorator );
expect ( $this -> app -> make ( DeletesServers :: class )) -> toBeInstanceOf ( CoreDeleter :: class );
expect ( $this -> failures ) -> toBe ([[ 'dns' , $message , 'action' ]]);
}) -> with ([
'throws' => [ fn () : never => throw new RuntimeException ( 'decorator failed' ), 'decorator failed' ],
'returns another type' => [ fn () : Server => new Server , 'The decorator for ' . DeletesServers :: class . ' must return an implementation of that contract.' ],
]);
test ( 'exceptions of a wrapper and of the core action reach the caller unchanged' , function () : void {
extensions ( 'dns' );
provider ( 'dns' ) -> wrap ( DeletesServers :: class , fn ( DeletesServers $inner ) : DeletesServers => new RecordingDeleter ( $inner , failure : new RuntimeException ( 'dns cleanup failed' )));
expect ( fn () => $this -> app -> make ( DeletesServers :: class ) -> delete ( new Server )) -> toThrow ( RuntimeException :: class , 'dns cleanup failed' );
CoreDeleter :: $failure = $core = new RuntimeException ( 'wings is unreachable' );
try {
$this -> app -> make ( DeletesServers :: class ) -> delete ( new Server );
$this -> fail ( 'The core exception must propagate.' );
} catch ( Throwable $throwable ) {
expect ( $throwable ) -> toBe ( $core );
} finally {
CoreDeleter :: $failure = null ;
}
});
test ( 'only bound panel contracts can be wrapped' , function ( string $contract ) : void {
extensions ( 'dns' );
expect ( fn () => provider ( 'dns' ) -> wrap ( $contract , fn ( $inner ) => $inner )) -> toThrow ( InvalidArgumentException :: class , 'can only wrap action contracts' );
}) -> with ([
'a concrete action' => [ CoreDeleter :: class ],
'a framework contract' => [ \Illuminate\Contracts\Cache\Repository :: class ],
'a missing interface' => [ DeletesServers :: class . 'Missing' ],
'an unbound panel interface' => [ \Pterodactyl\Contracts\Models\Identifiable :: class ],
'a shared panel service' => [ \Pterodactyl\Contracts\Extensions\HashidsInterface :: class ],
'an interface outside the contracts namespace' => [ \Pterodactyl\Services\Extensions\Contracts\ManagesExtensionSettings :: class ],
]);
2026-10-06 13:44:08 -04:00
test ( 'the actions that manage extensions and themes cannot be wrapped and keep resolving to core' , function ( string $contract , string $implementation ) : void {
extensions ( 'dns' );
expect ( fn () => provider ( 'dns' ) -> wrap ( $contract , fn ( object $inner ) : object => $inner )) -> toThrow ( InvalidArgumentException :: class , 'cannot wrap "' . $contract . '"' );
// A differently cased name is the same interface to PHP and is refused as well.
expect ( fn () => provider ( 'dns' ) -> wrap ( mb_strtolower ( $contract ), fn ( object $inner ) : object => $inner )) -> toThrow ( InvalidArgumentException :: class );
expect ( $this -> app -> make ( ExtensionActionDecorators :: class ) -> snapshot ()) -> toBe ([]);
expect ( $this -> app -> make ( $contract )) -> toBeInstanceOf ( $implementation );
}) -> with ([
'install' => [ InstallsExtensions :: class , InstallExtension :: class ],
'remove' => [ RemovesExtensions :: class , RemoveExtension :: class ],
'enable and disable' => [ SetsExtensionEnabled :: class , SetExtensionEnabled :: class ],
'settings' => [ UpdatesExtensionSettings :: class , UpdateExtensionSettings :: class ],
'setting files' => [ ReplacesExtensionSettingFiles :: class , ReplaceExtensionSettingFile :: class ],
'apply a theme' => [ AppliesThemes :: class , ApplyTheme :: class ],
'reset the theme' => [ ResetsThemes :: class , ResetTheme :: class ],
]);
test ( 'a provider asking to wrap an extension lifecycle action fails to boot and stages nothing' , function () : void {
extensions ( 'dns' );
$provider = provider ( 'dns' );
$provider -> beginRegistration ();
$provider -> wrap ( DeletesServers :: class , fn ( DeletesServers $inner ) : DeletesServers => new RecordingDeleter ( $inner ));
$provider -> wrap ( SetsExtensionEnabled :: class , fn ( SetsExtensionEnabled $inner ) : SetsExtensionEnabled => $inner );
expect ( fn () => $provider -> commitRegistration ()) -> toThrow ( InvalidArgumentException :: class , 'cannot wrap' );
expect ( $this -> app -> make ( DeletesServers :: class )) -> toBeInstanceOf ( CoreDeleter :: class );
expect ( $this -> app -> make ( SetsExtensionEnabled :: class )) -> toBeInstanceOf ( SetExtensionEnabled :: class );
});
2026-10-05 18:10:18 -04:00
test ( 'registered commands reach artisan only for available extensions' , function () : void {
extensions ( 'probe' );
provider ( 'probe' ) -> consoleCommands ([ ProbeCommand :: class ]);
provider ( 'disabled' ) -> consoleCommands ([ DisabledProbeCommand :: class ]);
expect ( Artisan :: all ()) -> toHaveKey ( 'probe:run' ) -> not -> toHaveKey ( 'disabled:run' );
expect ( Artisan :: call ( 'probe:run' )) -> toBe ( 7 );
});
2026-10-07 16:32:56 -04:00
test ( 'a command that names itself with AsCommand is constructed only when it runs' , function () : void {
extensions ( 'probe' );
CountingCommand :: $constructed = 0 ;
provider ( 'probe' ) -> consoleCommands ([ ProbeCommand :: class , CountingCommand :: class ]);
expect ( Artisan :: call ( 'probe:run' )) -> toBe ( 7 );
expect ( CountingCommand :: $constructed ) -> toBe ( 0 );
expect ( Artisan :: call ( 'probe:count' )) -> toBe ( 0 );
expect ( CountingCommand :: $constructed ) -> toBe ( 1 );
});
2026-10-06 13:57:18 -04:00
test ( 'extension commands carry the extension id and never replace an existing command' , function () : void {
extensions ( 'probe' , 'queue' );
provider ( 'probe' ) -> consoleCommands ([ UnprefixedCommand :: class , AliasedCommand :: class , ProbeCommand :: class ]);
provider ( 'queue' ) -> consoleCommands ([ ShadowingCommand :: class , QueueNamespaceCommand :: class ]);
$commands = Artisan :: all ();
expect ( $commands ) -> toHaveKeys ([ 'probe:run' , 'queue:drain' ]) -> not -> toHaveKeys ([ 'cleanup' , 'probe:alias' ]);
expect ( $commands [ 'migrate' ]) -> toBeInstanceOf ( MigrateCommand :: class );
expect ( $commands [ 'queue:work' ]) -> toBeInstanceOf ( WorkCommand :: class );
expect ( $this -> failures ) -> toBe ([
[ 'probe' , 'Extension "probe" cannot register the command "cleanup": its names must start with "probe:".' , 'command' ],
[ 'probe' , 'Extension "probe" cannot register the command "migrate": its names must start with "probe:".' , 'command' ],
[ 'queue' , 'Extension "queue" cannot register the command "queue:work": a command with that name already exists.' , 'command' ],
]);
});
2026-10-05 18:10:18 -04:00
test ( 'only console commands can be registered' , function () : void {
expect ( fn () => provider ( 'probe' ) -> consoleCommands ([ Server :: class ])) -> toThrow ( InvalidArgumentException :: class , 'is not a console command' );
});
test ( 'scheduled tasks run only while the extension is available and failures are attributed' , function () : void {
extensions ( 'probe' );
provider ( 'probe' ) -> schedule ( function ( Schedule $schedule ) : void {
$schedule -> call ( fn () : never => throw new RuntimeException ( 'task failed' )) -> everyMinute () -> description ( 'probe task' );
});
provider ( 'disabled' ) -> schedule ( function ( Schedule $schedule ) : void {
$schedule -> call ( fn () : null => null ) -> everyMinute () -> description ( 'disabled task' );
});
$schedule = new Schedule ;
$this -> app -> make ( ExtensionConsoleRegistry :: class ) -> schedule ( $schedule );
expect ( $schedule -> events ()) -> toHaveCount ( 1 );
$event = $schedule -> events ()[ 0 ];
expect ( $event -> description ) -> toBe ( 'probe task' );
expect ( $event -> filtersPass ( $this -> app )) -> toBeTrue ();
expect ( fn () => $event -> run ( $this -> app )) -> toThrow ( RuntimeException :: class , 'task failed' );
expect ( $this -> failures ) -> toBe ([[ 'probe' , 'Scheduled task "probe task" failed.' , 'schedule' ]]);
extensions ();
expect ( $event -> filtersPass ( $this -> app )) -> toBeFalse ();
});
test ( 'a schedule callback that throws is recorded and schedules nothing runnable' , function () : void {
extensions ( 'probe' );
provider ( 'probe' ) -> schedule ( function ( Schedule $schedule ) : void {
$schedule -> call ( fn () : null => null ) -> everyMinute ();
throw new RuntimeException ( 'schedule failed' );
});
$schedule = new Schedule ;
$this -> app -> make ( ExtensionConsoleRegistry :: class ) -> schedule ( $schedule );
expect ( $this -> failures ) -> toBe ([[ 'probe' , 'schedule failed' , 'schedule' ]]);
expect ( $schedule -> events ()[ 0 ] -> filtersPass ( $this -> app )) -> toBeFalse ();
});
test ( 'head tags are rendered into the layout for guests and replace the panel defaults' , function () : void {
extensions ( 'pwa' );
provider ( 'pwa' ) -> headTags ([
[ 'tag' => 'link' , 'rel' => 'manifest' , 'href' => '/extensions/pwa/manifest.webmanifest' ],
[ 'tag' => 'meta' , 'name' => 'theme-color' , 'content' => '#0f172a"><script>' ],
]);
provider ( 'disabled' ) -> headTags ([[ 'tag' => 'meta' , 'name' => 'application-name' , 'content' => 'Disabled' ]]);
$html = view ( 'templates/base.core' ) -> render ();
expect ( $html )
-> toContain ( '<link rel="manifest" href="/extensions/pwa/manifest.webmanifest">' )
-> toContain ( '<meta name="theme-color" content="#0f172a"><script>">' )
-> not -> toContain ( '/favicons/manifest.json' )
-> not -> toContain ( '#0e4688' )
-> not -> toContain ( 'Disabled' )
-> toContain ( '/favicons/favicon.ico' );
});
test ( 'head tag callbacks are resolved when rendered, cached, and never break the page' , function () : void {
extensions ( 'pwa' , 'broken' );
$calls = 0 ;
provider ( 'pwa' ) -> headTags ( function () use ( & $calls ) : array {
$calls ++ ;
return [[ 'tag' => 'meta' , 'name' => 'apple-mobile-web-app-title' , 'content' => 'Panel ' . $calls ]];
});
provider ( 'broken' ) -> headTags ( fn () : array => [[ 'tag' => 'script' , 'src' => 'https://example.com/x.js' ]]);
$tags = $this -> app -> make ( ExtensionHeadTags :: class );
expect ( $calls ) -> toBe ( 0 );
expect ( $tags -> toHtml ()) -> toBe ( '<meta name="apple-mobile-web-app-title" content="Panel 1">' );
$tags -> restore ( $tags -> snapshot ());
expect ( $tags -> toHtml ()) -> toBe ( '<meta name="apple-mobile-web-app-title" content="Panel 1">' );
expect ( $calls ) -> toBe ( 1 );
expect ( $this -> failures ) -> toBe ([[ 'broken' , 'Head tags must set "tag" to "meta" or "link".' , 'head' ]]);
$tags -> forget ( 'pwa' );
expect ( $tags -> toHtml ()) -> toBe ( '<meta name="apple-mobile-web-app-title" content="Panel 2">' );
config ([ 'extensions.head_tags_cache_seconds' => 0 ]);
Cache :: flush ();
$tags -> forget ( 'pwa' );
$tags -> toHtml ();
$tags -> forget ( 'pwa' );
$tags -> toHtml ();
expect ( $calls ) -> toBe ( 4 );
});
test ( 'invalid static head tags fail the registration' , function () : void {
expect ( fn () => provider ( 'pwa' ) -> headTags ([[ 'tag' => 'link' , 'rel' => 'stylesheet' , 'href' => '/x.css' ]])) -> toThrow ( InvalidArgumentException :: class );
});
test ( 'root routes mount under each claimed prefix ahead of the SPA catch-all' , function () : void {
extensions ( 'redirect' );
$path = writeRouteFile ( 'root.php' , '/{slug}' , 'go' );
provider ( 'redirect' , [ 'routes' => [ 'root' => [ 'go' , 'r' ]]]) -> rootRoutes ( $path );
Route :: getRoutes () -> refreshNameLookups ();
foreach ([ 'go' , 'r' ] as $prefix ) {
$route = Route :: getRoutes () -> getByName ( 'extensions.redirect.root.' . $prefix . '.go' );
expect ( $route ) -> not -> toBeNull ();
expect ( $route -> uri ()) -> toBe ( $prefix . '/{slug}' );
expect ( $route -> middleware ()) -> toBe ([ 'web' , 'throttle:extensions.root' , EnsureExtensionIsAvailable :: class . ':redirect' ]);
expect ( Route :: getRoutes () -> match ( Request :: create ( '/' . $prefix . '/docs' )) -> getName ()) -> toBe ( 'extensions.redirect.root.' . $prefix . '.go' );
}
expect ( Route :: getRoutes () -> match ( Request :: create ( '/server/abc' )) -> uri ()) -> toBe ( '{react}' );
$this -> get ( '/go/docs' ) -> assertOk () -> assertContent ( 'ok' );
extensions ();
$this -> get ( '/go/docs' ) -> assertNotFound ();
});
test ( 'authenticated web routes turn guests away' , function () : void {
extensions ( 'account' );
$path = writeRouteFile ( 'account.php' , '/link' , 'link' );
provider ( 'account' ) -> authenticatedWebRoutes ( $path );
Route :: getRoutes () -> refreshNameLookups ();
expect ( Route :: getRoutes () -> getByName ( 'extensions.account.web.link' ) -> middleware ()) -> toContain ( 'auth' );
$this -> get ( '/extensions/account/link' ) -> assertRedirect ( '/auth/login' );
$this -> getJson ( '/extensions/account/link' ) -> assertUnauthorized ();
});
test ( 'a single claimed prefix can be mounted and undeclared prefixes are refused' , function () : void {
$path = writeRouteFile ( 'root.php' , '/{slug}' , 'go' );
$provider = provider ( 'redirect' , [ 'routes' => [ 'root' => [ 'go' , 'r' ]]]);
$provider -> rootRoutes ( $path , 'r' );
Route :: getRoutes () -> refreshNameLookups ();
expect ( Route :: has ( 'extensions.redirect.root.r.go' )) -> toBeTrue ();
expect ( Route :: has ( 'extensions.redirect.root.go.go' )) -> toBeFalse ();
expect ( fn () => $provider -> rootRoutes ( $path , 'links' )) -> toThrow ( InvalidExtensionException :: class , 'does not declare the root path prefix "links"' );
expect ( fn () => provider ( 'plain' ) -> rootRoutes ( $path )) -> toThrow ( InvalidExtensionException :: class , 'declares no "routes.root" prefixes' );
});
2026-10-06 13:44:37 -04:00
test ( 'route binders and patterns declared in a staged route file reach the panel router' , function () : void {
extensions ( 'lookup' );
$provider = provider ( 'lookup' , [ 'routes' => [ 'root' => [ 'lookup' ]]]);
$provider -> beginRegistration ();
$provider -> rootRoutes ( writeBindingRouteFile ());
$provider -> commitRegistration ();
$this -> get ( '/lookup/abc' ) -> assertOk () -> assertContent ( 'ABC' );
expect ( Route :: getBindingCallback ( 'code' )) -> not -> toBeNull ();
expect ( Route :: getPatterns ()) -> toHaveKey ( 'code' , '[a-z]+' );
});
test ( 'route binders and patterns of a provider that fails to commit are discarded' , function () : void {
extensions ( 'lookup' );
$provider = provider ( 'lookup' , [ 'routes' => [ 'root' => [ 'lookup' ]]]);
$provider -> beginRegistration ();
$provider -> rootRoutes ( writeBindingRouteFile ());
$provider -> permissions ( 'Broken.' , []);
expect ( fn () => $provider -> commitRegistration ()) -> toThrow ( InvalidArgumentException :: class );
expect ( Route :: getPatterns ()) -> not -> toHaveKey ( 'code' );
expect ( Route :: getBindingCallback ( 'code' )) -> toBeNull ();
expect ( Route :: getRoutes () -> match ( Request :: create ( '/lookup/abc' )) -> uri ()) -> toBe ( '{react}' );
});
2026-10-05 18:10:18 -04:00
/** Marks the given extensions as enabled and collects every failure recorded against one. */
function extensions ( string ... $identifiers ) : void
{
( function () use ( $identifiers ) : void {
$this -> available = $identifiers ;
if ( $this -> app -> bound ( 'extension-test.repository' )) {
return ;
}
/** @var ExtensionRepository&MockInterface $repository */
$repository = Mockery :: mock ( ExtensionRepository :: class );
$repository -> shouldReceive ( 'isAvailable' ) -> andReturnUsing ( fn ( string $identifier ) : bool => in_array ( $identifier , $this -> available , true ));
$repository -> shouldReceive ( 'enabled' ) -> andReturnUsing ( fn () => collect ( array_fill_keys ( $this -> available , true )));
$repository -> shouldReceive ( 'recordFailure' ) -> andReturnUsing ( function ( string $identifier , string $reason , ? Throwable $exception = null , string $phase = 'runtime' ) : void {
$this -> failures [] = [ $identifier , $reason , $phase ];
});
$this -> app -> instance ( ExtensionRepository :: class , $repository );
$this -> app -> instance ( 'extension-test.repository' , true );
}) -> call ( pterodactylTestCase ());
}
/** @param array<string, mixed> $manifest */
function provider ( string $identifier , array $manifest = []) : ExtensionProvider
{
return ( function () use ( $identifier , $manifest ) {
if ( ! $this -> app -> bound ( 'extension-test.repository' )) {
extensions ();
}
$path = $this -> directory . DIRECTORY_SEPARATOR . $identifier ;
File :: ensureDirectoryExists ( $path );
File :: put ( $path . DIRECTORY_SEPARATOR . ExtensionManifest :: FILENAME , json_encode ([ 'id' => $identifier , 'name' => 'Runtime Fixture' , 'version' => '1.0.0' , ... $manifest ], JSON_THROW_ON_ERROR ));
return new class ( $this -> app , ( new ExtensionManifestValidator ) -> fromDirectory ( $path )) extends ExtensionProvider
{
public function wrap ( string $contract , Closure $decorator ) : void
{
$this -> wrapAction ( $contract , $decorator );
}
public function consoleCommands ( array $classes ) : void
{
$this -> registerCommands ( $classes );
}
public function schedule ( Closure $callback ) : void
{
$this -> registerSchedule ( $callback );
}
public function headTags ( array | Closure $tags ) : void
{
$this -> registerHeadTags ( $tags );
}
public function rootRoutes ( string $path , ? string $prefix = null ) : void
{
$this -> registerRootRoutes ( $path , $prefix );
}
public function authenticatedWebRoutes ( string $path ) : void
{
$this -> registerAuthenticatedWebRoutes ( $path );
}
public function permissions ( string $description , array $keys ) : void
{
$this -> registerPermissions ( $description , $keys );
}
};
}) -> call ( pterodactylTestCase ());
}
function writeRouteFile ( string $filename , string $uri , string $name ) : string
{
return ( function () use ( $filename , $uri , $name ) : string {
$path = $this -> directory . DIRECTORY_SEPARATOR . $filename ;
File :: put ( $path , <<< PHP
<? php
use Illuminate\\Support\\Facades\\Route ;
Route :: get ( '{$uri}' , fn () => 'ok' ) -> name ( '{$name}' );
PHP );
return $path ;
}) -> call ( pterodactylTestCase ());
}
2026-10-06 13:44:37 -04:00
/** A route file that scopes its parameter through Route::pattern() and Route::bind(). */
function writeBindingRouteFile () : string
{
return ( function () : string {
$path = $this -> directory . DIRECTORY_SEPARATOR . 'binding.php' ;
File :: put ( $path , <<< 'PHP'
<? php
use Illuminate\Support\Facades\Route ;
Route :: pattern ( 'code' , '[a-z]+' );
Route :: bind ( 'code' , fn ( string $value ) : string => strtoupper ( $value ));
Route :: get ( '/{code}' , fn ( string $code ) : string => $code ) -> name ( 'code' );
PHP );
return $path ;
}) -> call ( pterodactylTestCase ());
}
2026-10-05 18:10:18 -04:00
final class CoreDeleter implements DeletesServers
{
/** @var list<string> */
public static array $deleted = [];
public static ? Throwable $failure = null ;
private bool $force = false ;
public function withForce ( bool $bool = true ) : self
{
$this -> force = $bool ;
return $this ;
}
public function delete ( Server $server ) : void
{
throw_if ( self :: $failure instanceof Throwable , self :: $failure );
self :: $deleted [] = $this -> force ? 'forced' : 'deleted' ;
}
}
/** What an extension ships: it holds the inner action, forwards fluent options and calls it. */
final class RecordingDeleter implements DeletesServers
{
public function __construct (
private readonly DeletesServers $inner ,
private readonly ? string $label = null ,
private readonly ? Throwable $failure = null ,
) {}
public function withForce ( bool $bool = true ) : self
{
$this -> inner -> withForce ( $bool );
return $this ;
}
public function delete ( Server $server ) : void
{
CoreDeleter :: $deleted [] = $this -> label === null ? 'before' : $this -> label . ':before' ;
$this -> inner -> delete ( $server );
throw_if ( $this -> failure instanceof Throwable , $this -> failure );
CoreDeleter :: $deleted [] = $this -> label === null ? 'after' : $this -> label . ':after' ;
}
}
#[ AsCommand ( name : 'probe:run' )]
final class ProbeCommand extends Command
{
protected function execute ( InputInterface $input , OutputInterface $output ) : int
{
return 7 ;
}
2026-10-07 16:32:56 -04:00
}
#[ AsCommand ( name : 'probe:count' )]
final class CountingCommand extends Command
{
public static int $constructed = 0 ;
public function __construct ()
{
self :: $constructed ++ ;
parent :: __construct ();
}
protected function execute ( InputInterface $input , OutputInterface $output ) : int
{
return 0 ;
}
2026-10-05 18:10:18 -04:00
}
#[ AsCommand ( name : 'disabled:run' )]
final class DisabledProbeCommand extends Command
{
protected function execute ( InputInterface $input , OutputInterface $output ) : int
{
return 0 ;
}
}
2026-10-06 13:57:18 -04:00
#[ AsCommand ( name : 'cleanup' )]
final class UnprefixedCommand extends Command
{
protected function execute ( InputInterface $input , OutputInterface $output ) : int
{
return 0 ;
}
}
#[ AsCommand ( name : 'probe:alias' , aliases : [ 'migrate' ])]
final class AliasedCommand extends Command
{
protected function execute ( InputInterface $input , OutputInterface $output ) : int
{
return 0 ;
}
}
#[ AsCommand ( name : 'queue:work' )]
final class ShadowingCommand extends Command
{
protected function execute ( InputInterface $input , OutputInterface $output ) : int
{
return 0 ;
}
}
#[ AsCommand ( name : 'queue:drain' )]
final class QueueNamespaceCommand extends Command
{
protected function execute ( InputInterface $input , OutputInterface $output ) : int
{
return 0 ;
}
}