diff --git a/src/System/Integrate/Console/ConfigCommand.php b/src/System/Integrate/Console/ConfigCommand.php new file mode 100644 index 00000000..5fa0e97d --- /dev/null +++ b/src/System/Integrate/Console/ConfigCommand.php @@ -0,0 +1,76 @@ +> + */ + public static array $command = [ + [ + 'pattern' => 'config:cache', + 'fn' => [self::class, 'main'], + ], [ + 'pattern' => 'config:clear', + 'fn' => [self::class, 'clear'], + ], + ]; + + /** + * @return array> + */ + public function printHelp() + { + return [ + 'commands' => [ + 'config:cache' => 'Build cache application config', + 'config:clear' => 'Remove cached application config', + ], + 'options' => [], + 'relation' => [], + ]; + } + + public function main(): int + { + $app = Application::getIntance(); + (new ConfigProviders())->bootstrap($app); + + $this->clear(); + $config = $app->get(ConfigRepository::class)->toArray(); + $cached_config = 'getApplicationCachePath() . 'config.php', $cached_config)) { + ok('Config file has successfully created.')->out(); + + return 0; + } + fail('Cant build config cache.')->out(); + + return 1; + } + + public function clear(): int + { + if (file_exists($file = Application::getIntance()->getApplicationCachePath() . 'config.php')) { + @unlink($file); + ok('Clear config file has successfully.')->out(); + + return 0; + } + + return 1; + } +} diff --git a/tests/Integrate/Commands/ConfigCommandTest.php b/tests/Integrate/Commands/ConfigCommandTest.php new file mode 100644 index 00000000..84b4a884 --- /dev/null +++ b/tests/Integrate/Commands/ConfigCommandTest.php @@ -0,0 +1,63 @@ +setConfigPath(DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR); + + $command = new ConfigCommand([]); + + ob_start(); + $status = $command->main(); + $out = ob_get_clean(); + + $this->assertEquals(0, $status); + $this->assertStringContainsString('Config file has successfully created.', $out); + + $app->flush(); + } + + /** + * @test + */ + public function itCanRemoveConfigFile() + { + $app = new Application(dirname(__DIR__) . DIRECTORY_SEPARATOR); + + $app->setConfigPath(DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR); + + $command = new ConfigCommand([]); + + ob_start(); + $command->main(); + $status = $command->clear(); + $out = ob_get_clean(); + + $this->assertEquals(0, $status); + $this->assertStringContainsString('Config file has successfully created.', $out); + + $app->flush(); + } +} diff --git a/tests/Integrate/bootsrap/cache/.gitignore b/tests/Integrate/bootsrap/cache/.gitignore new file mode 100644 index 00000000..4f4773fb --- /dev/null +++ b/tests/Integrate/bootsrap/cache/.gitignore @@ -0,0 +1 @@ +config.php