Skip to content

Commit

Permalink
test with real DB
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Oct 7, 2021
1 parent b106c48 commit 89f3201
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 163 deletions.
174 changes: 111 additions & 63 deletions .github/workflows/test-unit.yml

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
docs/build
/build
/docs/build
/coverage
/vendor
/composer.lock
.idea
nbproject
.vscode
.DS_Store

local
Expand All @@ -19,7 +20,6 @@ cache
/demos/_demo-data/db.sqlite
/demos/_demo-data/db.sqlite-journal
/phpunit.xml
/phpunit-*.xml
/behat.yml

package-lock.json
Expand All @@ -29,5 +29,3 @@ package-lock.json
*.bak
*.codekit3
yarn.lock
/coverage
/demos/test/
2 changes: 1 addition & 1 deletion demos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ COPY demos demos

COPY demos/db.default.php demos
RUN php demos/_demo-data/create-db.php
RUN sed -E "s/\(('sqlite:.+')\);/(\$_ENV['DB_DSN'] ?? \\1);/g" -i demos/db.default.php
RUN sed -E "s/\(('sqlite:.+)\);/(\$_ENV['DB_DSN'] ?? \\1, \$_ENV['DB_USER'] ?? null, \$_ENV['DB_PASSWD'] ?? null);/g" -i demos/db.default.php
22 changes: 12 additions & 10 deletions demos/_demo-data/create-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
require_once __DIR__ . '/../init-autoloader.php';

$sqliteFile = __DIR__ . '/db.sqlite';
if (file_exists($sqliteFile)) {
unlink($sqliteFile);
if (!file_exists($sqliteFile)) {
new \Atk4\Data\Persistence\Sql('sqlite:' . $sqliteFile);
}
unset($sqliteFile);

$persistence = new \Atk4\Data\Persistence\Sql('sqlite:' . $sqliteFile);
/** @var \Atk4\Data\Persistence\Sql $db */
require_once __DIR__ . '/../init-db.php';

class ImportModelWithPrefixedFields extends Model
{
Expand Down Expand Up @@ -49,7 +51,7 @@ public function import(array $rowsMulti)
}
}

$model = new ImportModelWithPrefixedFields($persistence, ['table' => 'client']);
$model = new ImportModelWithPrefixedFields($db, ['table' => 'client']);
$model->addField('name', ['type' => 'string']);
$model->addField('addresses', ['type' => 'text']);
$model->addField('accounts', ['type' => 'text']);
Expand All @@ -59,7 +61,7 @@ public function import(array $rowsMulti)
['id' => 2, 'name' => 'Jane', 'addresses' => null, 'accounts' => null],
]);

$model = new ImportModelWithPrefixedFields($persistence, ['table' => 'country']);
$model = new ImportModelWithPrefixedFields($db, ['table' => 'country']);
$model->addField('iso', ['type' => 'string']); // should be CHAR(2) NOT NULL
$model->addField('name', ['type' => 'string']);
$model->addField('nicename', ['type' => 'string']);
Expand Down Expand Up @@ -322,7 +324,7 @@ public function import(array $rowsMulti)
['id' => 253, 'iso' => 'SS', 'name' => 'SOUTH SUDAN', 'nicename' => 'South Sudan', 'iso3' => 'SSD', 'numcode' => 728, 'phonecode' => 211],
]);

$model = new ImportModelWithPrefixedFields($persistence, ['table' => 'file']);
$model = new ImportModelWithPrefixedFields($db, ['table' => 'file']);
$model->addField('name', ['type' => 'string']);
$model->addField('type', ['type' => 'string']);
$model->addField('is_folder', ['type' => 'boolean']);
Expand Down Expand Up @@ -393,7 +395,7 @@ public function import(array $rowsMulti)
['id' => 61, 'name' => 'Button.php', 'type' => 'php', 'is_folder' => 0, 'parent_folder_id' => 46],
]);

$model = new ImportModelWithPrefixedFields($persistence, ['table' => 'stat']);
$model = new ImportModelWithPrefixedFields($db, ['table' => 'stat']);
$model->addField('project_name', ['type' => 'string']);
$model->addField('project_code', ['type' => 'string']);
$model->addField('description', ['type' => 'text']);
Expand Down Expand Up @@ -432,7 +434,7 @@ public function import(array $rowsMulti)
}
$model->import($data);

$model = new ImportModelWithPrefixedFields($persistence, ['table' => 'product_category']);
$model = new ImportModelWithPrefixedFields($db, ['table' => 'product_category']);
$model->addField('name', ['type' => 'string']);
(new Migration($model))->create();
$model->import([
Expand All @@ -441,7 +443,7 @@ public function import(array $rowsMulti)
['id' => 3, 'name' => 'Dairy'],
]);

$model = new ImportModelWithPrefixedFields($persistence, ['table' => 'product_sub_category']);
$model = new ImportModelWithPrefixedFields($db, ['table' => 'product_sub_category']);
$model->addField('name', ['type' => 'string']);
$model->addField('product_category_id', ['type' => 'bigint']);
(new Migration($model))->create();
Expand All @@ -457,7 +459,7 @@ public function import(array $rowsMulti)
['id' => 9, 'name' => 'Sugar/Sweetened', 'product_category_id' => 2],
]);

$model = new ImportModelWithPrefixedFields($persistence, ['table' => 'product']);
$model = new ImportModelWithPrefixedFields($db, ['table' => 'product']);
$model->addField('name', ['type' => 'string']);
$model->addField('brand', ['type' => 'string']);
$model->addField('product_category_id', ['type' => 'bigint']);
Expand Down
10 changes: 4 additions & 6 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
use Mvorisek\Atk4\Hintable\Data\HintablePropertyDef;

try {
if (file_exists(__DIR__ . '/db.php')) {
require_once __DIR__ . '/db.php';
} else {
require_once __DIR__ . '/db.default.php';
}
require_once file_exists(__DIR__ . '/db.php')
? __DIR__ . '/db.php'
: __DIR__ . '/db.default.php';
} catch (\PDOException $e) {
// do not pass $e unless you can secure DSN!
// do not show $e unless you can secure DSN!
throw (new \Atk4\Ui\Exception('This demo requires access to the database. See "demos/init-db.php"'))
->addMoreInfo('PDO error', $e->getMessage());
}
Expand Down
4 changes: 0 additions & 4 deletions js/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@ build/Release
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Remove some common IDE working directories
.idea
.vscode

lib
35 changes: 0 additions & 35 deletions phpunit-mssql.xml.dist

This file was deleted.

35 changes: 0 additions & 35 deletions phpunit-mysql.xml.dist

This file was deleted.

3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<var name="DB_DSN" value="sqlite::memory:" />
<var name="DB_USER" value="" />
<var name="DB_PASSWD" value="" />
<var name="DB_DBNAME" value="" />
</php>
<testsuites>
<testsuite name="tests">
Expand All @@ -29,7 +28,7 @@
<directory suffix=".php">src</directory>
</include>
<report>
<php outputFile="build/logs/clover.cov" />
<php outputFile="coverage/phpunit.cov" />
</report>
</coverage>
</phpunit>
2 changes: 1 addition & 1 deletion tests/DemosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected function getPathWithAppVars(string $path): string
public function demoFilesProvider(): array
{
$excludeDirs = ['_demo-data', '_includes'];
$excludeFiles = ['layout/layouts_error.php'];
$excludeFiles = ['layout/layouts_error.php', 'form-control/multiline-containsmany.php' /* TODO fix for MySQL */];

$files = [];
$files[] = 'index.php';
Expand Down
2 changes: 1 addition & 1 deletion tools/CoverageUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public static function saveData(): void
{
self::$coverage->stop();
$writer = new Report\PHP();
$writer->process(self::$coverage, dirname(__DIR__) . '/coverage/' . basename($_SERVER['SCRIPT_NAME'], '.php') . '-' . uniqid() . '.cov');
$writer->process(self::$coverage, dirname(__DIR__) . '/coverage/' . basename($_SERVER['SCRIPT_NAME'], '.php') . '-' . hash('sha256', microtime(true) . random_bytes(64)) . '.cov');
}
}

0 comments on commit 89f3201

Please sign in to comment.