setAppNamespace(); $this->pluginsListPath = ROOT . DS . 'cakephp-plugins.php'; if (file_exists($this->pluginsListPath)) { unlink($this->pluginsListPath); } $this->pluginsConfigPath = CONFIG . DS . 'plugins.php'; if (file_exists($this->pluginsConfigPath)) { $this->originalPluginsConfigContent = file_get_contents($this->pluginsConfigPath); } } protected function tearDown(): void { parent::tearDown(); if (file_exists($this->pluginsListPath)) { unlink($this->pluginsListPath); } if (file_exists($this->pluginsConfigPath)) { file_put_contents($this->pluginsConfigPath, $this->originalPluginsConfigContent); } } /** * Test generating help succeeds */ public function testHelp(): void { $this->exec('plugin list --help'); $this->assertExitCode(CommandInterface::CODE_SUCCESS); $this->assertOutputContains('plugin list'); } /** * Test plugin names are being displayed correctly */ public function testList(): void { $file = << [ 'TestPlugin' => '/config/path', 'OtherPlugin' => '/config/path' ] ]; PHP; file_put_contents($this->pluginsListPath, $file); $this->exec('plugin list'); $this->assertExitCode(CommandInterface::CODE_SUCCESS); $this->assertOutputContains('TestPlugin'); $this->assertOutputContains('OtherPlugin'); } /** * Test empty plugins array */ public function testListEmpty(): void { $file = <<pluginsListPath, $file); $this->exec('plugin list'); $this->assertExitCode(CommandInterface::CODE_ERROR); $this->assertErrorContains('No plugins have been found.'); } /** * Test enabled plugins are being flagged as enabled */ public function testListEnabled(): void { $file = << [ 'TestPlugin' => '/config/path', 'OtherPlugin' => '/config/path' ] ]; PHP; file_put_contents($this->pluginsListPath, $file); $config = << ['onlyDebug' => true, 'onlyCli' => true, 'optional' => true] ]; PHP; file_put_contents($this->pluginsConfigPath, $config); $this->exec('plugin list'); $this->assertExitCode(CommandInterface::CODE_SUCCESS); $this->assertOutputContains('TestPlugin'); $this->assertOutputContains('OtherPlugin'); } /** * Test listing unknown plugins throws an exception */ public function testListUnknown(): void { $file = << [ 'TestPlugin' => '/config/path', 'OtherPlugin' => '/config/path' ] ]; PHP; file_put_contents($this->pluginsListPath, $file); $config = <<pluginsConfigPath, $config); $this->expectException(MissingPluginException::class); $this->expectExceptionMessage('Plugin `Unknown` could not be found.'); $this->exec('plugin list'); } }