Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Updated Core Libraries #221

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
$schema = new DB($connName);

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

Check warning on line 124 in webfiori/framework/cli/commands/RunSQLQueryCommand.php

View check run for this annotation

Codecov / codecov/patch

webfiori/framework/cli/commands/RunSQLQueryCommand.php#L124

Added line #L124 was not covered by tests

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

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

Check warning on line 128 in webfiori/framework/cli/commands/RunSQLQueryCommand.php

View check run for this annotation

Codecov / codecov/patch

webfiori/framework/cli/commands/RunSQLQueryCommand.php#L128

Added line #L128 was not covered by tests

if ($mime == 'application/sql' || $mime == 'application/x-sql') {

Check warning on line 130 in webfiori/framework/cli/commands/RunSQLQueryCommand.php

View check run for this annotation

Codecov / codecov/patch

webfiori/framework/cli/commands/RunSQLQueryCommand.php#L130

Added line #L130 was not covered by tests
return $this->runFileQuery($schema, $fileObj);
} else {
$this->error('Provided file is not SQL file!');
Expand Down
Loading