diff --git a/composer.json b/composer.json index 7b239f0e6c..bbcb4956fc 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "license": "MIT", "require": { "php": ">=8.1", - "cakephp/cakephp": "^5.0.0", + "cakephp/cakephp": "^5.0.1", "cakephp/migrations": "^4.0.0", "cakephp/plugin-installer": "^2.0", "mobiledetect/mobiledetectlib": "^3.74" diff --git a/config/plugins.php b/config/plugins.php new file mode 100644 index 0000000000..72984dcdd4 --- /dev/null +++ b/config/plugins.php @@ -0,0 +1,33 @@ + ['onlyDebug' => true], + + // Optional plugins which are only needed in CLI commands + 'Bake' => ['onlyCli' => true, 'optional' => true], + + // Required plugins only in CLI commands + 'Migrations' => ['onlyCli' => true], + + // Add your custom plugins here +]; diff --git a/src/Application.php b/src/Application.php index 7d2481b52d..c85a1ecdb2 100644 --- a/src/Application.php +++ b/src/Application.php @@ -48,24 +48,12 @@ public function bootstrap(): void // Call parent to load bootstrap from files. parent::bootstrap(); - if (PHP_SAPI === 'cli') { - $this->bootstrapCli(); - } else { + if (PHP_SAPI !== 'cli') { FactoryLocator::add( 'Table', (new TableLocator())->allowFallbackClass(false) ); } - - /* - * Only try to load DebugKit in development mode - * Debug Kit should not be installed on a production system - */ - if (Configure::read('debug')) { - $this->addPlugin('DebugKit'); - } - - // Load more plugins here } /** @@ -116,20 +104,4 @@ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue public function services(ContainerInterface $container): void { } - - /** - * Bootstrapping for CLI application. - * - * That is when running commands. - * - * @return void - */ - protected function bootstrapCli(): void - { - $this->addOptionalPlugin('Bake'); - - $this->addPlugin('Migrations'); - - // Load more plugins here - } } diff --git a/src/Console/Installer.php b/src/Console/Installer.php index e446aee09f..6f5579829b 100644 --- a/src/Console/Installer.php +++ b/src/Console/Installer.php @@ -57,7 +57,7 @@ public static function postInstall(Event $event): void { $io = $event->getIO(); - $rootDir = dirname(dirname(__DIR__)); + $rootDir = dirname(__DIR__, 2); static::createAppLocalConfig($rootDir, $io); static::createWritableDirectories($rootDir, $io); diff --git a/tests/TestCase/ApplicationTest.php b/tests/TestCase/ApplicationTest.php index 7c42d856dc..6a65c52bde 100644 --- a/tests/TestCase/ApplicationTest.php +++ b/tests/TestCase/ApplicationTest.php @@ -24,7 +24,6 @@ use Cake\Routing\Middleware\RoutingMiddleware; use Cake\TestSuite\IntegrationTestTrait; use Cake\TestSuite\TestCase; -use InvalidArgumentException; /** * ApplicationTest class @@ -41,7 +40,7 @@ class ApplicationTest extends TestCase public function testBootstrap() { Configure::write('debug', false); - $app = new Application(dirname(dirname(__DIR__)) . '/config'); + $app = new Application(dirname(__DIR__, 2) . '/config'); $app->bootstrap(); $plugins = $app->getPlugins(); @@ -58,33 +57,13 @@ public function testBootstrap() public function testBootstrapInDebug() { Configure::write('debug', true); - $app = new Application(dirname(dirname(__DIR__)) . '/config'); + $app = new Application(dirname(__DIR__, 2) . '/config'); $app->bootstrap(); $plugins = $app->getPlugins(); $this->assertTrue($plugins->has('DebugKit'), 'plugins has DebugKit?'); } - /** - * testBootstrapPluginWitoutHalt - * - * @return void - */ - public function testBootstrapPluginWithoutHalt() - { - $this->expectException(InvalidArgumentException::class); - - $app = $this->getMockBuilder(Application::class) - ->setConstructorArgs([dirname(dirname(__DIR__)) . '/config']) - ->onlyMethods(['addPlugin']) - ->getMock(); - - $app->method('addPlugin') - ->will($this->throwException(new InvalidArgumentException('test exception.'))); - - $app->bootstrap(); - } - /** * testMiddleware * @@ -92,7 +71,7 @@ public function testBootstrapPluginWithoutHalt() */ public function testMiddleware() { - $app = new Application(dirname(dirname(__DIR__)) . '/config'); + $app = new Application(dirname(__DIR__, 2) . '/config'); $middleware = new MiddlewareQueue(); $middleware = $app->middleware($middleware);