From f29a9e21b620479674b14bbac2fe2640a66d5fc6 Mon Sep 17 00:00:00 2001 From: Ondra Date: Thu, 9 Nov 2023 23:51:20 +0100 Subject: [PATCH] wip - functional tests --- Dockerfile | 4 + composer.json | 11 +- phpunit.xml.dist | 11 +- src/Application.php | 4 +- src/Writer/Common.php | 1 + {src => tests/Fixtures}/run.php | 6 +- tests/functional/DatadirTest.php | 52 +++++++++ tests/functional/PdoTestConnection.php | 44 ++++++++ .../functional/get-tables-info/expected-code | 1 + .../get-tables-info/expected-stderr | 0 .../get-tables-info/expected-stdout | 1 + tests/functional/get-tables-info/setUp.php | 18 ++++ .../get-tables-info/source/data/config.json | 15 +++ tests/functional/run-action/expected-code | 1 + tests/functional/run-action/expected-stderr | 0 tests/functional/run-action/expected-stdout | 7 ++ .../run-action/source/data/config.json | 102 ++++++++++++++++++ .../source/data}/in/tables/encoding.csv | 0 .../data}/in/tables/encoding.csv.manifest | 0 .../source/data}/in/tables/simple.csv | 0 .../data}/in/tables/simple.csv.manifest | 0 .../data}/in/tables/simple_increment.csv | 0 .../in/tables/simple_increment.csv.manifest | 0 .../source/data}/in/tables/simple_merged.csv | 0 .../in/tables/simple_merged.csv.manifest | 0 .../source/data}/in/tables/types.csv | 0 .../source/data}/in/tables/types.csv.manifest | 0 tests/phpunit/Base.php | 24 +++++ .../{ => phpunit}/data/deprecated/config.json | 0 .../data/deprecated}/in/tables/encoding.csv | 0 .../in/tables/encoding.csv.manifest | 0 .../data/deprecated}/in/tables/simple.csv | 0 .../deprecated}/in/tables/simple.csv.manifest | 0 .../deprecated/in/tables/simple_increment.csv | 5 + .../in/tables/simple_increment.csv.manifest | 7 ++ .../deprecated/in/tables/simple_merged.csv | 12 +++ .../in/tables/simple_merged.csv.manifest | 7 ++ .../data/deprecated/in/tables/types.csv | 4 + .../deprecated/in/tables/types.csv.manifest | 8 ++ tests/{ => phpunit}/data/encoding/config.json | 0 .../data/encoding/in/tables/encoding.csv | 11 ++ .../encoding/in/tables/encoding.csv.manifest | 6 ++ tests/{ => phpunit}/data/simple/config.json | 0 .../phpunit/data/simple/in/tables/simple.csv | 10 ++ .../data/simple/in/tables/simple.csv.manifest | 7 ++ .../{phpunit => testsOld}/ApplicationTest.php | 27 +---- {src/Test => tests/testsOld}/BaseTest.php | 2 +- .../Writer => testsOld}/CommonTest.php | 2 +- .../ConfigRowApplicationTest.php | 10 +- .../WriterFactoryTest.php | 2 +- tests/traits/CloseSshTunnelsTrait.php | 17 +++ tests/traits/DropAllTablesTrait.php | 44 ++++++++ 52 files changed, 443 insertions(+), 40 deletions(-) rename {src => tests/Fixtures}/run.php (87%) create mode 100644 tests/functional/DatadirTest.php create mode 100644 tests/functional/PdoTestConnection.php create mode 100644 tests/functional/get-tables-info/expected-code create mode 100644 tests/functional/get-tables-info/expected-stderr create mode 100644 tests/functional/get-tables-info/expected-stdout create mode 100644 tests/functional/get-tables-info/setUp.php create mode 100644 tests/functional/get-tables-info/source/data/config.json create mode 100644 tests/functional/run-action/expected-code create mode 100644 tests/functional/run-action/expected-stderr create mode 100644 tests/functional/run-action/expected-stdout create mode 100644 tests/functional/run-action/source/data/config.json rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/encoding.csv (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/encoding.csv.manifest (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/simple.csv (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/simple.csv.manifest (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/simple_increment.csv (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/simple_increment.csv.manifest (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/simple_merged.csv (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/simple_merged.csv.manifest (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/types.csv (100%) rename tests/{data/deprecated => functional/run-action/source/data}/in/tables/types.csv.manifest (100%) create mode 100644 tests/phpunit/Base.php rename tests/{ => phpunit}/data/deprecated/config.json (100%) rename tests/{data/encoding => phpunit/data/deprecated}/in/tables/encoding.csv (100%) rename tests/{data/encoding => phpunit/data/deprecated}/in/tables/encoding.csv.manifest (100%) rename tests/{data/simple => phpunit/data/deprecated}/in/tables/simple.csv (100%) rename tests/{data/simple => phpunit/data/deprecated}/in/tables/simple.csv.manifest (100%) create mode 100644 tests/phpunit/data/deprecated/in/tables/simple_increment.csv create mode 100644 tests/phpunit/data/deprecated/in/tables/simple_increment.csv.manifest create mode 100644 tests/phpunit/data/deprecated/in/tables/simple_merged.csv create mode 100644 tests/phpunit/data/deprecated/in/tables/simple_merged.csv.manifest create mode 100644 tests/phpunit/data/deprecated/in/tables/types.csv create mode 100644 tests/phpunit/data/deprecated/in/tables/types.csv.manifest rename tests/{ => phpunit}/data/encoding/config.json (100%) create mode 100644 tests/phpunit/data/encoding/in/tables/encoding.csv create mode 100644 tests/phpunit/data/encoding/in/tables/encoding.csv.manifest rename tests/{ => phpunit}/data/simple/config.json (100%) create mode 100644 tests/phpunit/data/simple/in/tables/simple.csv create mode 100644 tests/phpunit/data/simple/in/tables/simple.csv.manifest rename tests/{phpunit => testsOld}/ApplicationTest.php (87%) rename {src/Test => tests/testsOld}/BaseTest.php (98%) rename tests/{phpunit/Writer => testsOld}/CommonTest.php (99%) rename tests/{phpunit => testsOld}/ConfigRowApplicationTest.php (95%) rename tests/{phpunit => testsOld}/WriterFactoryTest.php (95%) create mode 100644 tests/traits/CloseSshTunnelsTrait.php create mode 100644 tests/traits/DropAllTablesTrait.php diff --git a/Dockerfile b/Dockerfile index 8fb61c1..c852c6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,10 @@ RUN docker-php-ext-install pdo_mysql RUN docker-php-ext-configure intl \ && docker-php-ext-install intl +# Xdebug +RUN pecl install xdebug \ + && docker-php-ext-enable xdebug + ## Composer - deps always cached unless changed # First copy only composer files COPY composer.* /code/ diff --git a/composer.json b/composer.json index 4b17591..878ce65 100644 --- a/composer.json +++ b/composer.json @@ -27,13 +27,17 @@ }, "autoload-dev": { "psr-4": { + "Keboola\\DbWriter\\Traits\\": "tests/Traits/", + "Keboola\\DbWriter\\TestsFunctional\\": "tests/functional/", "Keboola\\DbWriter\\Tests\\": "tests/phpunit/" } }, "scripts": { - "tests-phpunit": "phpunit", + "tests-phpunit": "phpunit --testsuite unit", + "tests-datadir": "phpunit --testsuite functional", "tests": [ - "@tests-phpunit" + "@tests-phpunit", + "@tests-datadir" ], "phpcs": "phpcs -n --ignore=vendor,tests --extensions=php .", "phpcbf": "phpcbf -n --ignore=vendor --extensions=php .", @@ -57,7 +61,8 @@ }, "require-dev": { "keboola/coding-standard": "^15.0", + "keboola/datadir-tests": "dev-ondra-update-packages", "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^10.4" + "phpunit/phpunit": "^9.6" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3dd5c82..7eb3d0b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,12 @@ stopOnFailure="false" bootstrap="vendor/autoload.php"> - - tests/phpunit - + + + tests/phpunit + + + tests/functional + + diff --git a/src/Application.php b/src/Application.php index 218541a..3ec98c8 100644 --- a/src/Application.php +++ b/src/Application.php @@ -38,8 +38,10 @@ protected function run(): void if (!$this->isRowConfiguration($parameters)) { $filteredTables = array_filter($parameters['tables'], fn($table) => $table['export']); + unset($parameters['tables']); foreach ($filteredTables as $filteredTable) { $filteredTable = $this->validateTableItems($filteredTable); + $filteredTable = array_merge($parameters, $filteredTable); $writer->write($this->createExportConfig($filteredTable)); } } else { @@ -102,7 +104,7 @@ protected function getSyncActions(): array protected function getConfigDefinitionClass(): string { - if ($this->isRowConfiguration($this->getRawConfig())) { + if ($this->isRowConfiguration($this->getRawConfig()['parameters'])) { $action = $this->getRawConfig()['action'] ?? 'run'; if ($action === 'run') { return ConfigRowDefinition::class; diff --git a/src/Writer/Common.php b/src/Writer/Common.php index b58203c..385053c 100644 --- a/src/Writer/Common.php +++ b/src/Writer/Common.php @@ -53,6 +53,7 @@ protected function createWriteAdapter(): WriteAdapter return new PdoWriteAdapter( $this->connection, new DefaultQueryBuilder(), + $this->logger, ); } } diff --git a/src/run.php b/tests/Fixtures/run.php similarity index 87% rename from src/run.php rename to tests/Fixtures/run.php index 95d1d67..afe82c8 100644 --- a/src/run.php +++ b/tests/Fixtures/run.php @@ -6,9 +6,13 @@ use Keboola\Component\Logger; use Keboola\DbWriter\Application; -require __DIR__ . '/../vendor/autoload.php'; +require __DIR__ . '/../../vendor/autoload.php'; $logger = new Logger(); + +$app = new Application($logger); +$app->execute(); +exit(0); try { $app = new Application($logger); $app->execute(); diff --git a/tests/functional/DatadirTest.php b/tests/functional/DatadirTest.php new file mode 100644 index 0000000..36f12c5 --- /dev/null +++ b/tests/functional/DatadirTest.php @@ -0,0 +1,52 @@ +getTestFileDir() . '/../../tests/Fixtures/run.php'; + } + + protected function setUp(): void + { + parent::setUp(); + putenv('KBC_COMPONENT_RUN_MODE=run'); + + // Test dir, eg. "/code/tests/functional/full-load-ok" + $this->testProjectDir = $this->getTestFileDir() . '/' . $this->dataName(); + $this->testTempDir = $this->temp->getTmpFolder(); + + $isSsl = str_starts_with((string) $this->dataName(), 'ssl-'); + $this->connection = PdoTestConnection::createConnection(); + $this->closeSshTunnels(); + $this->dropAllTables($this->connection); + + // Load setUp.php file - used to init database state + $setUpPhpFile = $this->testProjectDir . '/setUp.php'; + if (file_exists($setUpPhpFile)) { + // Get callback from file and check it + $initCallback = require $setUpPhpFile; + if (!is_callable($initCallback)) { + throw new RuntimeException(sprintf('File "%s" must return callback!', $setUpPhpFile)); + } + + // Invoke callback + $initCallback($this); + } + } +} diff --git a/tests/functional/PdoTestConnection.php b/tests/functional/PdoTestConnection.php new file mode 100644 index 0000000..c459711 --- /dev/null +++ b/tests/functional/PdoTestConnection.php @@ -0,0 +1,44 @@ + getenv('COMMON_DB_HOST', true) ?: (string) getenv('COMMON_DB_HOST'), + 'port' => (string) getenv('COMMON_DB_PORT'), + 'user' => (string) getenv('COMMON_DB_USER'), + '#password' => (string) getenv('COMMON_DB_PASSWORD'), + 'database' => (string) getenv('COMMON_DB_DATABASE'), + ]; + + return $config; + } + + /** + * @throws UserException + */ + public static function createConnection(): PdoConnection + { + return new PdoConnection( + new NullLogger(), + sprintf( + 'mysql:host=%s;port=%s;dbname=%s;charset=utf8', + self::getDbConfigArray()['host'], + self::getDbConfigArray()['port'], + self::getDbConfigArray()['database'], + ), + self::getDbConfigArray()['user'], + self::getDbConfigArray()['#password'], + [], + ); + } +} diff --git a/tests/functional/get-tables-info/expected-code b/tests/functional/get-tables-info/expected-code new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/functional/get-tables-info/expected-code @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/functional/get-tables-info/expected-stderr b/tests/functional/get-tables-info/expected-stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/get-tables-info/expected-stdout b/tests/functional/get-tables-info/expected-stdout new file mode 100644 index 0000000..9657c80 --- /dev/null +++ b/tests/functional/get-tables-info/expected-stdout @@ -0,0 +1 @@ +{"status":"success","tables":{"simple":[{"Field":"id","Type":"int(11)","Null":"NO","Key":"PRI","Default":null,"Extra":"auto_increment"},{"Field":"name","Type":"varchar(255)","Null":"NO","Key":"","Default":null,"Extra":""},{"Field":"value","Type":"int(11)","Null":"NO","Key":"","Default":null,"Extra":""}]}} \ No newline at end of file diff --git a/tests/functional/get-tables-info/setUp.php b/tests/functional/get-tables-info/setUp.php new file mode 100644 index 0000000..6a502a6 --- /dev/null +++ b/tests/functional/get-tables-info/setUp.php @@ -0,0 +1,18 @@ +connection->exec($sql); +}; diff --git a/tests/functional/get-tables-info/source/data/config.json b/tests/functional/get-tables-info/source/data/config.json new file mode 100644 index 0000000..9a34767 --- /dev/null +++ b/tests/functional/get-tables-info/source/data/config.json @@ -0,0 +1,15 @@ +{ + "action": "getTablesInfo", + "parameters": { + "writer_class": "Common", + "data_dir": "/data", + "db": { + "driver": "mysql", + "host": "%env(string:COMMON_DB_HOST)%", + "port": "%env(string:COMMON_DB_PORT)%", + "database": "%env(string:COMMON_DB_DATABASE)%", + "user": "%env(string:COMMON_DB_USER)%", + "#password": "%env(string:COMMON_DB_PASSWORD)%" + } + } +} \ No newline at end of file diff --git a/tests/functional/run-action/expected-code b/tests/functional/run-action/expected-code new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/functional/run-action/expected-code @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/functional/run-action/expected-stderr b/tests/functional/run-action/expected-stderr new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/run-action/expected-stdout b/tests/functional/run-action/expected-stdout new file mode 100644 index 0000000..8da05ea --- /dev/null +++ b/tests/functional/run-action/expected-stdout @@ -0,0 +1,7 @@ +Creating PDO connection to "mysql:host=mysql;port=3306;dbname=testdb;charset=utf8". +Table "encoding" created +Data written to table "encoding". +Temporary Table "%s" created +Data written to table "%s". +Table "simple" created +Data upserted to table "simple". \ No newline at end of file diff --git a/tests/functional/run-action/source/data/config.json b/tests/functional/run-action/source/data/config.json new file mode 100644 index 0000000..d393dc6 --- /dev/null +++ b/tests/functional/run-action/source/data/config.json @@ -0,0 +1,102 @@ +{ + "parameters": { + "writer_class": "Common", + "data_dir": "/data", + "db": { + "driver": "mysql", + "host": "%env(string:COMMON_DB_HOST)%", + "port": "%env(string:COMMON_DB_PORT)%", + "database": "%env(string:COMMON_DB_DATABASE)%", + "user": "%env(string:COMMON_DB_USER)%", + "#password": "%env(string:COMMON_DB_PASSWORD)%" + }, + "tables": [ + { + "tableId": "encoding", + "dbName": "encoding", + "export": true, + "incremental": false, + "primaryKey": [], + "items": [ + { + "name": "col1", + "dbName": "col1", + "type": "VARCHAR", + "size": 255, + "nullable": null, + "default": null + }, + { + "name": "col2", + "dbName": "col2", + "type": "VARCHAR", + "size": 255, + "nullable": null, + "default": null + } + ] + }, + { + "tableId": "simple", + "dbName": "simple", + "export": true, + "incremental": true, + "primaryKey": [ + "id" + ], + "items": [ + { + "name": "id", + "dbName": "id", + "type": "int", + "size": null, + "nullable": null, + "default": null + }, + { + "name": "name", + "dbName": "name", + "type": "VARCHAR", + "size": 255, + "nullable": null, + "default": null + }, + { + "name": "glasses", + "dbName": "glasses", + "type": "VARCHAR", + "size": 20, + "nullable": null, + "default": null + } + ] + } + ] + }, + "storage": { + "input": { + "tables": [ + { + "source": "encoding", + "destination": "encoding.csv", + "columns": [ + "id", + "name", + "glasses", + "age" + ] + }, + { + "source": "simple", + "destination": "simple.csv", + "columns": [ + "id", + "name", + "glasses", + "age" + ] + } + ] + } + } +} \ No newline at end of file diff --git a/tests/data/deprecated/in/tables/encoding.csv b/tests/functional/run-action/source/data/in/tables/encoding.csv similarity index 100% rename from tests/data/deprecated/in/tables/encoding.csv rename to tests/functional/run-action/source/data/in/tables/encoding.csv diff --git a/tests/data/deprecated/in/tables/encoding.csv.manifest b/tests/functional/run-action/source/data/in/tables/encoding.csv.manifest similarity index 100% rename from tests/data/deprecated/in/tables/encoding.csv.manifest rename to tests/functional/run-action/source/data/in/tables/encoding.csv.manifest diff --git a/tests/data/deprecated/in/tables/simple.csv b/tests/functional/run-action/source/data/in/tables/simple.csv similarity index 100% rename from tests/data/deprecated/in/tables/simple.csv rename to tests/functional/run-action/source/data/in/tables/simple.csv diff --git a/tests/data/deprecated/in/tables/simple.csv.manifest b/tests/functional/run-action/source/data/in/tables/simple.csv.manifest similarity index 100% rename from tests/data/deprecated/in/tables/simple.csv.manifest rename to tests/functional/run-action/source/data/in/tables/simple.csv.manifest diff --git a/tests/data/deprecated/in/tables/simple_increment.csv b/tests/functional/run-action/source/data/in/tables/simple_increment.csv similarity index 100% rename from tests/data/deprecated/in/tables/simple_increment.csv rename to tests/functional/run-action/source/data/in/tables/simple_increment.csv diff --git a/tests/data/deprecated/in/tables/simple_increment.csv.manifest b/tests/functional/run-action/source/data/in/tables/simple_increment.csv.manifest similarity index 100% rename from tests/data/deprecated/in/tables/simple_increment.csv.manifest rename to tests/functional/run-action/source/data/in/tables/simple_increment.csv.manifest diff --git a/tests/data/deprecated/in/tables/simple_merged.csv b/tests/functional/run-action/source/data/in/tables/simple_merged.csv similarity index 100% rename from tests/data/deprecated/in/tables/simple_merged.csv rename to tests/functional/run-action/source/data/in/tables/simple_merged.csv diff --git a/tests/data/deprecated/in/tables/simple_merged.csv.manifest b/tests/functional/run-action/source/data/in/tables/simple_merged.csv.manifest similarity index 100% rename from tests/data/deprecated/in/tables/simple_merged.csv.manifest rename to tests/functional/run-action/source/data/in/tables/simple_merged.csv.manifest diff --git a/tests/data/deprecated/in/tables/types.csv b/tests/functional/run-action/source/data/in/tables/types.csv similarity index 100% rename from tests/data/deprecated/in/tables/types.csv rename to tests/functional/run-action/source/data/in/tables/types.csv diff --git a/tests/data/deprecated/in/tables/types.csv.manifest b/tests/functional/run-action/source/data/in/tables/types.csv.manifest similarity index 100% rename from tests/data/deprecated/in/tables/types.csv.manifest rename to tests/functional/run-action/source/data/in/tables/types.csv.manifest diff --git a/tests/phpunit/Base.php b/tests/phpunit/Base.php new file mode 100644 index 0000000..fd6980a --- /dev/null +++ b/tests/phpunit/Base.php @@ -0,0 +1,24 @@ +closeSshTunnels(); + parent::setUp(); + } + + protected function closeSshTunnels(): void + { + # Close SSH tunnel if created + $process = new Process(['sh', '-c', 'pgrep ssh | xargs -r kill']); + $process->mustRun(); + } +} \ No newline at end of file diff --git a/tests/data/deprecated/config.json b/tests/phpunit/data/deprecated/config.json similarity index 100% rename from tests/data/deprecated/config.json rename to tests/phpunit/data/deprecated/config.json diff --git a/tests/data/encoding/in/tables/encoding.csv b/tests/phpunit/data/deprecated/in/tables/encoding.csv similarity index 100% rename from tests/data/encoding/in/tables/encoding.csv rename to tests/phpunit/data/deprecated/in/tables/encoding.csv diff --git a/tests/data/encoding/in/tables/encoding.csv.manifest b/tests/phpunit/data/deprecated/in/tables/encoding.csv.manifest similarity index 100% rename from tests/data/encoding/in/tables/encoding.csv.manifest rename to tests/phpunit/data/deprecated/in/tables/encoding.csv.manifest diff --git a/tests/data/simple/in/tables/simple.csv b/tests/phpunit/data/deprecated/in/tables/simple.csv similarity index 100% rename from tests/data/simple/in/tables/simple.csv rename to tests/phpunit/data/deprecated/in/tables/simple.csv diff --git a/tests/data/simple/in/tables/simple.csv.manifest b/tests/phpunit/data/deprecated/in/tables/simple.csv.manifest similarity index 100% rename from tests/data/simple/in/tables/simple.csv.manifest rename to tests/phpunit/data/deprecated/in/tables/simple.csv.manifest diff --git a/tests/phpunit/data/deprecated/in/tables/simple_increment.csv b/tests/phpunit/data/deprecated/in/tables/simple_increment.csv new file mode 100644 index 0000000..6f563d5 --- /dev/null +++ b/tests/phpunit/data/deprecated/in/tables/simple_increment.csv @@ -0,0 +1,5 @@ +"id","name","glasses" +"7","Jakub Matejka","no" +"8","Ondrej Popelka","no" +"9","Pavel Dolezal","yes" +"10","Klara Koudelova","yes" diff --git a/tests/phpunit/data/deprecated/in/tables/simple_increment.csv.manifest b/tests/phpunit/data/deprecated/in/tables/simple_increment.csv.manifest new file mode 100644 index 0000000..99ffc5e --- /dev/null +++ b/tests/phpunit/data/deprecated/in/tables/simple_increment.csv.manifest @@ -0,0 +1,7 @@ +{ + "columns": [ + "id", + "name", + "glasses" + ] +} diff --git a/tests/phpunit/data/deprecated/in/tables/simple_merged.csv b/tests/phpunit/data/deprecated/in/tables/simple_merged.csv new file mode 100644 index 0000000..d499a6c --- /dev/null +++ b/tests/phpunit/data/deprecated/in/tables/simple_merged.csv @@ -0,0 +1,12 @@ +"id","name","glasses" +"0","Miro cillik","yes" +"1","Ondrej Hlavacek","no" +"2","Martin Halamicek","yes" +"3","Tomas Kacur","yes" +"4","Erik Zigo","no" +"5","Marc Raiser","sometimes" +"6","Petr Simecek","yes" +"7","Jakub Matejka","no" +"8","Ondrej Popelka","no" +"9","Pavel Dolezal","yes" +"10","Klara Koudelova","yes" diff --git a/tests/phpunit/data/deprecated/in/tables/simple_merged.csv.manifest b/tests/phpunit/data/deprecated/in/tables/simple_merged.csv.manifest new file mode 100644 index 0000000..99ffc5e --- /dev/null +++ b/tests/phpunit/data/deprecated/in/tables/simple_merged.csv.manifest @@ -0,0 +1,7 @@ +{ + "columns": [ + "id", + "name", + "glasses" + ] +} diff --git a/tests/phpunit/data/deprecated/in/tables/types.csv b/tests/phpunit/data/deprecated/in/tables/types.csv new file mode 100644 index 0000000..00eafab --- /dev/null +++ b/tests/phpunit/data/deprecated/in/tables/types.csv @@ -0,0 +1,4 @@ +"id","name","prize","description" +"1","notebook","299.9","cheap notebook bla bla bla" +"2","snapback","12.99","nice snapback" +"3","xiaomi phone","39.99","chinese phones are the best" \ No newline at end of file diff --git a/tests/phpunit/data/deprecated/in/tables/types.csv.manifest b/tests/phpunit/data/deprecated/in/tables/types.csv.manifest new file mode 100644 index 0000000..8ebe6cf --- /dev/null +++ b/tests/phpunit/data/deprecated/in/tables/types.csv.manifest @@ -0,0 +1,8 @@ +{ + "columns": [ + "id", + "name", + "prize", + "description" + ] +} diff --git a/tests/data/encoding/config.json b/tests/phpunit/data/encoding/config.json similarity index 100% rename from tests/data/encoding/config.json rename to tests/phpunit/data/encoding/config.json diff --git a/tests/phpunit/data/encoding/in/tables/encoding.csv b/tests/phpunit/data/encoding/in/tables/encoding.csv new file mode 100644 index 0000000..7ef86d3 --- /dev/null +++ b/tests/phpunit/data/encoding/in/tables/encoding.csv @@ -0,0 +1,11 @@ +"col1","col2" +"line with enclosure","second column" +"column with enclosure "", and comma inside text","second column enclosure in text """ +"columns with +new line","columns with tab" +"column with backslash \ inside","column with backslash and enclosure \""" +"column with \n \t \\","second col" +"unicode characters","ľščťžýáíéúäôň" +"first","something with + +double new line" diff --git a/tests/phpunit/data/encoding/in/tables/encoding.csv.manifest b/tests/phpunit/data/encoding/in/tables/encoding.csv.manifest new file mode 100644 index 0000000..ec2216b --- /dev/null +++ b/tests/phpunit/data/encoding/in/tables/encoding.csv.manifest @@ -0,0 +1,6 @@ +{ + "columns": [ + "col1", + "col2" + ] +} diff --git a/tests/data/simple/config.json b/tests/phpunit/data/simple/config.json similarity index 100% rename from tests/data/simple/config.json rename to tests/phpunit/data/simple/config.json diff --git a/tests/phpunit/data/simple/in/tables/simple.csv b/tests/phpunit/data/simple/in/tables/simple.csv new file mode 100644 index 0000000..4a8ab84 --- /dev/null +++ b/tests/phpunit/data/simple/in/tables/simple.csv @@ -0,0 +1,10 @@ +"id","name","glasses" +"0","Miro cillik","yes" +"1","Ondrej Hlavacek","no" +"2","Martin Halamicek","yes" +"3","Tomas Kacur","yes" +"4","Erik Zigo","no" +"5","Marc Raiser","sometimes" +"6","Petr Simecek","yes" +"7","Jakub Matejka","yes" +"8","Ondrej Popelka","no" diff --git a/tests/phpunit/data/simple/in/tables/simple.csv.manifest b/tests/phpunit/data/simple/in/tables/simple.csv.manifest new file mode 100644 index 0000000..99ffc5e --- /dev/null +++ b/tests/phpunit/data/simple/in/tables/simple.csv.manifest @@ -0,0 +1,7 @@ +{ + "columns": [ + "id", + "name", + "glasses" + ] +} diff --git a/tests/phpunit/ApplicationTest.php b/tests/testsOld/ApplicationTest.php similarity index 87% rename from tests/phpunit/ApplicationTest.php rename to tests/testsOld/ApplicationTest.php index 6ff89e5..f47371f 100644 --- a/tests/phpunit/ApplicationTest.php +++ b/tests/testsOld/ApplicationTest.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace Keboola\DbWriter\Tests; +namespace testsOld; -use Keboola\Csv\CsvWriter; use Keboola\DbWriter\Application; -use Keboola\DbWriter\Configuration\ConfigDefinition; -use Keboola\DbWriter\Configuration\Validator; use Keboola\DbWriter\Exception\UserException; use Keboola\DbWriter\Test\BaseTest; +use Keboola\DbWriter\Tests\ConfigDefinition; +use Keboola\DbWriter\Tests\CsvWriter; +use Keboola\DbWriter\Tests\TestLogger; +use Keboola\DbWriter\Tests\Validator; use Keboola\DbWriter\Writer; use PDO; use Psr\Log\LoggerInterface; -use Psr\Log\Test\TestLogger; use SplFileInfo; class ApplicationTest extends BaseTest @@ -143,23 +143,6 @@ public function testRunReorderColumns(): void $this->runApplication($this->getApp($this->config)); } - public function testGetTablesInfo(): void - { - $this->runApplication($this->getApp($this->config)); - - $config = $this->config; - $config['action'] = 'getTablesInfo'; - $result = $this->getApp($config)->run(); - $resultJson = json_decode($result, true); - - $this->assertContains('encoding', array_keys($resultJson['tables'])); - } - - protected function getApp(array $config, ?LoggerInterface $logger = null): Application - { - return new Application($config, $logger ?: new TestLogger()); - } - protected function runApplication(Application $app): void { $result = $app->run(); diff --git a/src/Test/BaseTest.php b/tests/testsOld/BaseTest.php similarity index 98% rename from src/Test/BaseTest.php rename to tests/testsOld/BaseTest.php index 8a273b4..1cb095a 100644 --- a/src/Test/BaseTest.php +++ b/tests/testsOld/BaseTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Keboola\DbWriter\Test; +namespace testsOld; use Exception; use Keboola\DbWriter\WriterFactory; diff --git a/tests/phpunit/Writer/CommonTest.php b/tests/testsOld/CommonTest.php similarity index 99% rename from tests/phpunit/Writer/CommonTest.php rename to tests/testsOld/CommonTest.php index 1522f8d..5739229 100644 --- a/tests/phpunit/Writer/CommonTest.php +++ b/tests/testsOld/CommonTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Keboola\DbWriter\Tests\Writer; +namespace testsOld; use Keboola\Csv\CsvReader; use Keboola\Csv\CsvWriter; diff --git a/tests/phpunit/ConfigRowApplicationTest.php b/tests/testsOld/ConfigRowApplicationTest.php similarity index 95% rename from tests/phpunit/ConfigRowApplicationTest.php rename to tests/testsOld/ConfigRowApplicationTest.php index 58d3781..aec11e6 100644 --- a/tests/phpunit/ConfigRowApplicationTest.php +++ b/tests/testsOld/ConfigRowApplicationTest.php @@ -2,17 +2,14 @@ declare(strict_types=1); -namespace Keboola\DbWriter\Tests; +namespace testsOld; -use Keboola\Csv\CsvWriter; use Keboola\DbWriter\Application; -use Keboola\DbWriter\Configuration\ConfigDefinition; -use Keboola\DbWriter\Configuration\Validator; use Keboola\DbWriter\Exception\UserException; -use Keboola\DbWriter\Test\BaseTest; +use Keboola\DbWriter\Tests\CsvWriter; +use Keboola\DbWriter\Tests\TestLogger; use PDO; use Psr\Log\LoggerInterface; -use Psr\Log\Test\TestLogger; use SplFileInfo; class ConfigRowApplicationTest extends BaseTest @@ -25,7 +22,6 @@ class ConfigRowApplicationTest extends BaseTest public function setUp(): void { parent::setUp(); - $validate = Validator::getValidator(new ConfigDefinition()); $this->config = $this->getConfig(); $this->config['parameters'] = $validate($this->config['parameters']); diff --git a/tests/phpunit/WriterFactoryTest.php b/tests/testsOld/WriterFactoryTest.php similarity index 95% rename from tests/phpunit/WriterFactoryTest.php rename to tests/testsOld/WriterFactoryTest.php index 197b257..dc9fb85 100644 --- a/tests/phpunit/WriterFactoryTest.php +++ b/tests/testsOld/WriterFactoryTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Keboola\DbWriter\Tests; +namespace testsOld; use Keboola\DbWriter\Configuration\ConfigDefinition; use Keboola\DbWriter\Configuration\Validator; diff --git a/tests/traits/CloseSshTunnelsTrait.php b/tests/traits/CloseSshTunnelsTrait.php new file mode 100644 index 0000000..807b23f --- /dev/null +++ b/tests/traits/CloseSshTunnelsTrait.php @@ -0,0 +1,17 @@ +mustRun(); + } +} \ No newline at end of file diff --git a/tests/traits/DropAllTablesTrait.php b/tests/traits/DropAllTablesTrait.php new file mode 100644 index 0000000..bf716fa --- /dev/null +++ b/tests/traits/DropAllTablesTrait.php @@ -0,0 +1,44 @@ +exec($sql); + } +} \ No newline at end of file