From fe4e85ad4f7cb90be92975c677039fec252c765f Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Tue, 30 Apr 2024 18:23:53 +0300 Subject: [PATCH] test: Updated `RunSQLCommand` Tests --- .../framework/test/cli/RunSQLCommandTest.php | 97 +++++++------------ 1 file changed, 36 insertions(+), 61 deletions(-) diff --git a/tests/webfiori/framework/test/cli/RunSQLCommandTest.php b/tests/webfiori/framework/test/cli/RunSQLCommandTest.php index f7b4396a..ba1c796a 100644 --- a/tests/webfiori/framework/test/cli/RunSQLCommandTest.php +++ b/tests/webfiori/framework/test/cli/RunSQLCommandTest.php @@ -1,15 +1,15 @@ setName('testing-connection'); App::getConfig()->addOrUpdateDBConnection($conn); - - $runner = App::getRunner(); - $runner->setArgsVector([ - 'webfiori', - 'run-query', - ]); - $runner->setInputs([ - '0', - '0', - 'select * from hello;', - 'y' - ]); - - - $this->assertEquals(1146, $runner->start()); - + $this->setRunner(App::getRunner()); + $this->assertEquals([ "Select database connection:\n", "0: testing-connection <--\n", @@ -47,7 +33,13 @@ public function testCLIQuery00() { "Continue?(Y/n)\n", "Info: Executing query on database testing_db...\n", "Error: 1146 - Table 'testing_db.hello' doesn't exist\n" - ], $runner->getOutput()); + ], $this->executeMultiCommand(['run-query'], [ + '0', + '0', + 'select * from hello;', + 'y' + ])); + $this->assertEquals(1146, $this->getExitCode()); } /** * @test @@ -56,20 +48,7 @@ public function testCLIQuery01() { $conn = new ConnectionInfo('mysql', 'root', '123456', 'testing_db', '127.0.0.1'); $conn->setName('testing-connection'); App::getConfig()->addOrUpdateDBConnection($conn); - - $runner = App::getRunner(); - $runner->setArgsVector([ - 'webfiori', - 'run-query', - '--connection' => 'testing-connection', - ]); - $runner->setInputs([ - '0', - 'drop table test2_x;', - 'y' - ]); - - $this->assertEquals(1051, $runner->start()); + $this->setRunner(App::getRunner()); $this->assertEquals([ "What type of query you would like to run?\n", @@ -82,7 +61,15 @@ public function testCLIQuery01() { "Continue?(Y/n)\n", "Info: Executing query on database testing_db...\n", "Error: 1051 - Unknown table 'testing_db.test2_x'\n" - ], $runner->getOutput()); + ], $this->executeMultiCommand([ + 'run-query', + '--connection' => 'testing-connection', + ], [ + '0', + 'drop table test2_x;', + 'y' + ])); + $this->assertEquals(1051, $this->getExitCode()); } /** * @test @@ -188,23 +175,17 @@ public function testQueryFromFile02() { $conn->setName('testing-connection'); App::getConfig()->addOrUpdateDBConnection($conn); - $runner = App::getRunner(); - $runner->setArgsVector([ - 'webfiori', + $this->setRunner(App::getRunner()); + + $this->assertEquals([ + "Error: Provided file is not SQL file!\n" + ], $this->executeMultiCommand([ 'run-query', '--connection' => 'testing-connection', '--no-confirm', '--file' => 'app\\database\\Test2Table.php' - ]); - $runner->setInputs([ - - ]); - - - $this->assertEquals(-1, $runner->start()); - $this->assertEquals([ - "Error: Provided file is not SQL file!\n" - ], $runner->getOutput()); + ])); + $this->assertEquals(-1, $this->getExitCode()); } /** * @test @@ -213,25 +194,19 @@ public function testQueryFromFile03() { $conn = new ConnectionInfo('mysql', 'root', '123456', 'testing_db', '127.0.0.1'); $conn->setName('testing-connection'); App::getConfig()->addOrUpdateDBConnection($conn); + $this->setRunner(App::getRunner()); - $runner = App::getRunner(); - $runner->setArgsVector([ - 'webfiori', + $this->assertEquals([ + "Info: Executing query on database testing_db...\n", + "Success: Query executed without errors.\n" + ], $this->executeMultiCommand([ 'run-query', '--connection' => 'testing-connection', '--no-confirm', '--file' => 'app\\database\\sql-file.sql' - ]); - $runner->setInputs([ - - ]); - - - $this->assertEquals(0, $runner->start()); - $this->assertEquals([ - "Info: Executing query on database testing_db...\n", - "Success: Query executed without errors.\n" - ], $runner->getOutput()); + ])); + + $this->assertEquals(0, $this->getExitCode()); } /** * @test