Skip to content

Commit

Permalink
Add auth to the MongoDB database(s), and use the new SQLite adapters …
Browse files Browse the repository at this point in the history
…instead of Doctrine DBAL
  • Loading branch information
christeredvartsen committed Sep 4, 2021
1 parent ac433a6 commit 0dc92e3
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 103 deletions.
24 changes: 21 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
image: mongo:${{ matrix.mongodb-versions }}
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password

steps:
- name: Setup PHP
Expand Down Expand Up @@ -61,6 +64,9 @@ jobs:
image: mongo:${{ matrix.mongodb-versions }}
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password

steps:
- name: Setup PHP
Expand Down Expand Up @@ -116,6 +122,9 @@ jobs:
image: mongo:${{ matrix.mongodb-versions }}
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password

steps:
- name: Setup PHP
Expand Down Expand Up @@ -156,7 +165,7 @@ jobs:
name: httpd-logs-mongodb-filesystem
path: build/logs

integration-tests-doctrine-sqlite-filesystem:
integration-tests-sqlite-filesystem:
name: Integration tests (SQLite / Filesystem)
strategy:
matrix:
Expand All @@ -171,6 +180,9 @@ jobs:
image: mongo:${{ matrix.mongodb-versions }}
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password

steps:
- name: Setup PHP
Expand Down Expand Up @@ -198,17 +210,20 @@ jobs:
- name: Install dependencies
run: composer install

- name: Create tables
run: sqlite3 /tmp/imbo-sqlite-integration-test.sq3 < ./vendor/imbo/imbo-sqlite-adapters/setup/000-imbo.sql

- name: Start PHP web server
run: |
mkdir -p build/logs
php -S localhost:8080 -t ./public features/bootstrap/router.php > build/logs/httpd.log 2>&1 &
- name: Run integration tests using Behat
run: vendor/bin/behat --strict --suite=doctrine-sqlite-filesystem
run: vendor/bin/behat --strict --suite=sqlite-filesystem

- uses: actions/upload-artifact@v2
with:
name: httpd-logs-doctrine-sqlite-filesystem
name: httpd-logs-sqlite-filesystem
path: build/logs

integration-tests-mysql-filesystem:
Expand All @@ -228,6 +243,9 @@ jobs:
image: mongo:${{ matrix.mongodb-versions }}
ports:
- 27017:27017
env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password

mysql:
image: mysql:${{ matrix.mysql-versions }}
Expand Down
12 changes: 10 additions & 2 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ default:
project_root: "%paths.base%"
contexts: [Imbo\Behat\FeatureContext]
database: MongoDB
database.uri: mongodb://localhost:27017
database.name: imbo_behat_test_database
database.username: admin
database.password: password
storage: GridFS
mongodb-filesystem:
project_root: "%paths.base%"
contexts: [Imbo\Behat\FeatureContext]
database: MongoDB
database.uri: mongodb://localhost:27017
database.username: admin
database.password: password
storage: Filesystem
doctrine-sqlite-filesystem:
sqlite-filesystem:
project_root: "%paths.base%"
contexts: [Imbo\Behat\FeatureContext]
database: DoctrineSQLite
database: SQLite
database.dsn: sqlite:/tmp/imbo-sqlite-integration-test.sq3
storage: Filesystem
mysql-filesystem:
project_root: "%paths.base%"
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@
"imbo/imbo-filesystem-adapters": "dev-main",
"imbo/imbo-mongodb-adapters": "dev-main",
"imbo/imbo-mysql-adapters": "dev-main",
"imbo/imbo-sqlite-adapters": "dev-main",
"micheh/psr7-cache": "^0.5",
"phpunit/phpunit": "^9.2"
},
"suggest": {
"imbo/imbo-s3-adapters": "Enables usage of AWS S3 for storing images",
"imbo/imbo-b2-adapters": "Enables usage of Backblaze B2 for storing images",
"imbo/imbo-filesystem-adapters": "Enables usage of a (local) filesystem for storing images",
"imbo/imbo-metadata-cache": "Enabled caching of metadata through an event listener",
"imbo/imbo-mysql-adapters": "Enabled usage of MySQL as database",
"imbo/imbo-mongodb-adapters": "Enables usage of MongoDB for storing images"
"imbo/imbo-metadata-cache": "Enables caching of metadata through an event listener",
"imbo/imbo-mysql-adapters": "Enables usage of MySQL as database",
"imbo/imbo-mongodb-adapters": "Enables usage of MongoDB for storing images",
"imbo/imbo-sqlite-adapters": "Enables usage of SQLite as database"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -88,12 +90,12 @@
"test:behat": [
"@test:behat:mongodb-gridfs",
"@test:behat:mongodb-filesystem",
"@test:behat:doctrine-sqlite-filesystem",
"@test:behat:sqlite-filesystem",
"@test:behat:mysql-filesystem"
],
"test:behat:mongodb-gridfs": "vendor/bin/behat --strict --suite=mongodb-gridfs",
"test:behat:mongodb-filesystem": "vendor/bin/behat --strict --suite=mongodb-filesystem",
"test:behat:doctrine-sqlite-filesystem": "vendor/bin/behat --strict --suite=doctrine-sqlite-filesystem",
"test:behat:sqlite-filesystem": "vendor/bin/behat --strict --suite=sqlite-filesystem",
"test:behat:mysql-filesystem": "vendor/bin/behat --strict --suite=mysql-filesystem",
"test": [
"@test:phpunit",
Expand Down
82 changes: 72 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 0 additions & 37 deletions features/bootstrap/DatabaseTest/DoctrineSQLite.php

This file was deleted.

41 changes: 18 additions & 23 deletions features/bootstrap/DatabaseTest/MongoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,29 @@
* Class for suites that want to use the MongoDB database adapter
*/
class MongoDB implements AdapterTest {
/**
* {@inheritdoc}
*/
static public function setUp(array $config) {
$databaseName = 'imbo_behat_test_database';
$client = new MongoClient(
$config['database.uri'],
[
'username' => $config['database.username'],
'password' => $config['database.password'],
],
);
$client->{$config['database.name']}->drop();

self::removeDatabase($databaseName);

return ['databaseName' => $databaseName];
}

/**
* {@inheritdoc}
*/
static public function tearDown(array $config) {
self::removeDatabase($config['databaseName']);
return $config;
}

/**
* Remove the test database
*
* @param string $databaseName Name of the database to drop
*/
static private function removeDatabase($databaseName) {
(new MongoClient())->{$databaseName}->drop();
}
static public function tearDown(array $config) {}

static public function getAdapter(array $config) : Database {
return new Database($config['databaseName']);
return new Database(
$config['database.name'],
$config['database.uri'],
[
'username' => $config['database.username'],
'password' => $config['database.password'],
],
);
}
}
28 changes: 28 additions & 0 deletions features/bootstrap/DatabaseTest/SQLite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);
namespace Imbo\Behat\DatabaseTest;

use Imbo\Behat\AdapterTest;
use Imbo\Database\PDOAdapter;
use Imbo\Database\SQLite as DatabaseAdapter;
use PDO;

/**
* Class for suites that want to use the SQLite database adapter
*/
class SQLite implements AdapterTest {
static public function setUp(array $config) {
$pdo = new PDO($config['database.dsn']);

foreach ([PDOAdapter::SHORTURL_TABLE, PDOAdapter::IMAGEINFO_TABLE] as $table) {
$pdo->query("DELETE FROM `{$table}`");
}

return $config;
}

static public function tearDown(array $config) {}

static public function getAdapter(array $config) : DatabaseAdapter {
return new DatabaseAdapter($config['database.dsn']);
}
}

0 comments on commit 0dc92e3

Please sign in to comment.