Skip to content

Commit

Permalink
Merge pull request #221 from WebFiori/dev
Browse files Browse the repository at this point in the history
chore: Updated Core Libraries
  • Loading branch information
usernane authored Apr 30, 2024
2 parents e54cd0e + 87dc2e3 commit 1af0361
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 67 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"ext-fileinfo": "*",
"ext-openssl": "*",
"webfiori/http":"v3.3.11",
"webfiori/file":"v1.3.5",
"webfiori/file":"v1.3.6",
"webfiori/jsonx":"v3.3.0",
"webfiori/ui":"v2.6.1",
"webfiori/collections":"v1.1.4",
"webfiori/database":"v0.8.9",
"webfiori/cli":"v1.2.0",
"webfiori/database":"v0.8.10",
"webfiori/cli":"v1.2.2",
"webfiori/mailer":"v1.2.0",
"webfiori/err":"v1.0.9"
},
Expand Down
97 changes: 36 additions & 61 deletions tests/webfiori/framework/test/cli/RunSQLCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
namespace webfiori\framework\test\cli;

use PHPUnit\Framework\TestCase;
use tables\Schema;
use tables\Schema2;
use webfiori\cli\CommandTestCase;
use webfiori\database\ConnectionInfo;
use webfiori\framework\App;
use webfiori\framework\config\Controller;
use webfiori\framework\config\JsonDriver;

class RunSQLCommandTest extends TestCase {
class RunSQLCommandTest extends CommandTestCase {
/**
* @test
*/
Expand All @@ -18,22 +18,8 @@ public function testCLIQuery00() {
$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',
]);
$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",
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions webfiori/framework/cli/commands/RunSQLQueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ private function connectionBased($dbConnections) : int {
$schema = new DB($connName);

if ($file !== null) {
$fileObj = new File($file);
$fileObj = new File(ROOT_PATH.DS.$file);

if ($fileObj->isExist()) {
$fileObj->read();

if ($fileObj->getMIME() == 'application/sql') {
$mime = $fileObj->getMIME();

if ($mime == 'application/sql' || $mime == 'application/x-sql') {
return $this->runFileQuery($schema, $fileObj);
} else {
$this->error('Provided file is not SQL file!');
Expand Down

0 comments on commit 1af0361

Please sign in to comment.