diff --git a/.gitignore b/.gitignore index 435185857a..32c14d01b5 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,8 @@ writable/uploads/* writable/debugbar/* +application/Database/Migrations/2* + php_errors.log #------------------------- @@ -124,4 +126,4 @@ nb-configuration.xml .vscode/ /results/ -/phpunit.xml \ No newline at end of file +/phpunit.xml diff --git a/system/Commands/Server/Serve.php b/system/Commands/Server/Serve.php index e101c9e5fb..849abef0fd 100644 --- a/system/Commands/Server/Serve.php +++ b/system/Commands/Server/Serve.php @@ -1,25 +1,68 @@ 'The PHP Binary [default: "PHP_BINARY"]', - '-host' => 'The HTTP Host [default: "localhost"]', - '-port' => 'The HTTP Host Port [default: "8080"]', + protected $usage = 'serve'; + protected $arguments = []; + protected $options = [ + '-php' => 'The PHP Binary [default: "PHP_BINARY"]', + '-host' => 'The HTTP Host [default: "localhost"]', + '-port' => 'The HTTP Host Port [default: "8080"]', ]; public function run(array $params) { // Collect any user-supplied options and apply them - $php = CLI::getOption('php') ?? PHP_BINARY; + $php = CLI::getOption('php') ?? PHP_BINARY; $host = CLI::getOption('host') ?? 'localhost'; $port = CLI::getOption('port') ?? '8080'; @@ -38,4 +81,5 @@ class Serve extends BaseCommand // to ensure our environment is set and it simulates basic mod_rewrite. passthru("{$php} -S {$host}:{$port} -t {$docroot} {$rewrite}"); } + } diff --git a/system/Commands/Server/rewrite.php b/system/Commands/Server/rewrite.php index ca2a061f84..a7af4d4211 100644 --- a/system/Commands/Server/rewrite.php +++ b/system/Commands/Server/rewrite.php @@ -6,8 +6,9 @@ * development server based around PHP's built-in development * server. This file simply tries to mimic Apache's mod_rewrite * functionality so the site will operate as normal. + * */ - +// @codeCoverageIgnoreStart // Avoid this file run when listing commands if (php_sapi_name() === 'cli') { @@ -36,3 +37,4 @@ if ($uri !== '/' && (is_file($path) || is_dir($path))) // Otherwise, we'll load the index file and let // the framework handle the request from here. require_once $fcpath . 'index.php'; +// @codeCoverageIgnoreEnd diff --git a/system/Commands/Sessions/CreateMigration.php b/system/Commands/Sessions/CreateMigration.php index 18551acc5b..34cccc6238 100644 --- a/system/Commands/Sessions/CreateMigration.php +++ b/system/Commands/Sessions/CreateMigration.php @@ -39,6 +39,12 @@ use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; use Config\App; +/** + * Creates a migration file for database sessions. + * + * @package CodeIgniter\Commands + */ + class CreateMigration extends BaseCommand { diff --git a/tests/_support/Commands/CommandsTestStreamFilter.php b/tests/_support/Commands/CommandsTestStreamFilter.php new file mode 100644 index 0000000000..9618507305 --- /dev/null +++ b/tests/_support/Commands/CommandsTestStreamFilter.php @@ -0,0 +1,17 @@ +data; + $consumed += $bucket->datalen; + } + return PSFS_PASS_ON; + } +} + +stream_filter_register('CommandsTestStreamFilter', 'CodeIgniter\Commands\CommandsTestStreamFilter'); diff --git a/tests/_support/Database/seeds/CITestSeeder.php b/tests/_support/Database/Seeds/CITestSeeder.php similarity index 96% rename from tests/_support/Database/seeds/CITestSeeder.php rename to tests/_support/Database/Seeds/CITestSeeder.php index e7eaed444e..8088eeca21 100644 --- a/tests/_support/Database/seeds/CITestSeeder.php +++ b/tests/_support/Database/Seeds/CITestSeeder.php @@ -1,4 +1,4 @@ -stream_filter = stream_filter_append(STDOUT, 'CommandsTestStreamFilter'); + + $this->env = new \CodeIgniter\Config\DotEnv(ROOTPATH); + $this->env->load(); + + // Set environment values that would otherwise stop the framework from functioning during tests. + if ( ! isset($_SERVER['app.baseURL'])) + { + $_SERVER['app.baseURL'] = 'http://example.com'; + } + + $_SERVER['argv'] = ['spark', 'list']; + $_SERVER['argc'] = 2; + CLI::init(); + + $this->config = new MockAppConfig(); + $this->request = new \CodeIgniter\HTTP\IncomingRequest($this->config, new \CodeIgniter\HTTP\URI('https://somwhere.com'), null, new UserAgent()); + $this->response = new \CodeIgniter\HTTP\Response($this->config); + $this->runner = new CommandRunner($this->request, $this->response); + } + + public function tearDown() + { + stream_filter_remove($this->stream_filter); + } + + public function testHelpCommand() + { + $this->runner->index(['help']); + $result = CommandsTestStreamFilter::$buffer; + + // make sure the result looks like a command list + $this->assertContains('Displays basic usage information.', $result); + $this->assertContains('command_name', $result); + } + + public function testListCommands() + { + $this->runner->index(['list']); + $result = CommandsTestStreamFilter::$buffer; + + // make sure the result looks like a command list + $this->assertContains('Lists the available commands.', $result); + $this->assertContains('Displays basic usage information.', $result); + } + +} diff --git a/tests/system/Commands/SessionsCommandsTest.php b/tests/system/Commands/SessionsCommandsTest.php new file mode 100644 index 0000000000..39e792889f --- /dev/null +++ b/tests/system/Commands/SessionsCommandsTest.php @@ -0,0 +1,70 @@ +stream_filter = stream_filter_append(STDOUT, 'CommandsTestStreamFilter'); + + $this->env = new \CodeIgniter\Config\DotEnv(ROOTPATH); + $this->env->load(); + + // Set environment values that would otherwise stop the framework from functioning during tests. + if ( ! isset($_SERVER['app.baseURL'])) + { + $_SERVER['app.baseURL'] = 'http://example.com'; + } + + $_SERVER['argv'] = ['spark', 'list']; + $_SERVER['argc'] = 2; + CLI::init(); + + $this->config = new MockAppConfig(); + $this->request = new \CodeIgniter\HTTP\IncomingRequest($this->config, new \CodeIgniter\HTTP\URI('https://somwhere.com'), null, new UserAgent()); + $this->response = new \CodeIgniter\HTTP\Response($this->config); + $this->runner = new CommandRunner($this->request, $this->response); + } + + public function tearDown() + { + stream_filter_remove($this->stream_filter); + } + + public function testCreateMigrationCommand() + { + $this->runner->index(['session:migration']); + $result = CommandsTestStreamFilter::$buffer; + + // make sure we end up with a migration class in the right place + // or at least that we claim to have done so + // separate assertions avoid console color codes + $this->assertContains('Created file:', $result); + $this->assertContains('APPPATH/Database/Migrations/', $result); + $this->assertContains('_create_ci_sessions_table.php', $result); + } + + public function testOverriddenCreateMigrationCommand() + { + $_SERVER['argv'] = ['spark','session:migration', '-t', 'mygoodies']; + $_SERVER['argc'] = 4; + CLI::init(); + + $this->runner->index(['session:migration']); + $result = CommandsTestStreamFilter::$buffer; + + // make sure we end up with a migration class in the right place + $this->assertContains('Created file:', $result); + $this->assertContains('APPPATH/Database/Migrations/', $result); + $this->assertContains('_create_mygoodies_table.php', $result); + } + + +}