From 7818aebdd6bb26e657ba7a0f6d0a6a0387440f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Pujol=20Ahull=C3=B3?= Date: Tue, 10 Aug 2021 13:29:48 +0200 Subject: [PATCH] #128 - add Oracle support --- .github/workflows/test.yml | 6 ++++ src/Command/InstallCommand.php | 2 +- src/Installer/Database/DatabaseResolver.php | 4 +-- src/Installer/Database/OracleDatabase.php | 2 +- .../Database/DatabaseResolverTest.php | 4 +++ .../Installer/Database/OracleDatabaseTest.php | 30 +++++++++++++++++++ 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tests/Installer/Database/OracleDatabaseTest.php diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a8df7ce..4d21ac37 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,6 +37,12 @@ jobs: ports: - 5432:5432 options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 + oracle: + image: moodlehq/moodle-db-oracle-r2 + env: + ORACLE_DISABLE_ASYNCH_IO: true + ports: + - 1521:1521 strategy: fail-fast: false diff --git a/src/Command/InstallCommand.php b/src/Command/InstallCommand.php index 1046130a..71c9163f 100644 --- a/src/Command/InstallCommand.php +++ b/src/Command/InstallCommand.php @@ -89,7 +89,7 @@ protected function configure() ->addOption('repo', null, InputOption::VALUE_REQUIRED, 'Moodle repository to clone', $repo) ->addOption('branch', null, InputOption::VALUE_REQUIRED, 'Moodle git branch to clone, EG: MOODLE_29_STABLE', $branch) ->addOption('plugin', null, InputOption::VALUE_REQUIRED, 'Path to Moodle plugin', $plugin) - ->addOption('db-type', null, InputOption::VALUE_REQUIRED, 'Database type, mysqli, pgsql or mariadb', $type) + ->addOption('db-type', null, InputOption::VALUE_REQUIRED, 'Database type, mysqli, pgsql, mariadb or oci', $type) ->addOption('db-user', null, InputOption::VALUE_REQUIRED, 'Database user') ->addOption('db-pass', null, InputOption::VALUE_REQUIRED, 'Database pass', '') ->addOption('db-name', null, InputOption::VALUE_REQUIRED, 'Database name', 'moodle') diff --git a/src/Installer/Database/DatabaseResolver.php b/src/Installer/Database/DatabaseResolver.php index d2b87615..4404bebe 100644 --- a/src/Installer/Database/DatabaseResolver.php +++ b/src/Installer/Database/DatabaseResolver.php @@ -60,7 +60,7 @@ private function resolveDatabaseType($type) return $database; } } - throw new \DomainException(sprintf('Unknown database type (%s). Please use mysqli, pgsql or mariadb.', $type)); + throw new \DomainException(sprintf('Unknown database type (%s). Please use mysqli, pgsql, mariadb or oci.', $type)); } /** @@ -68,6 +68,6 @@ private function resolveDatabaseType($type) */ private function getDatabases() { - return [new MySQLDatabase(), new PostgresDatabase(), new MariaDBDatabase()]; + return [new MySQLDatabase(), new PostgresDatabase(), new MariaDBDatabase(), new OracleDatabase()]; } } diff --git a/src/Installer/Database/OracleDatabase.php b/src/Installer/Database/OracleDatabase.php index 9cb97e04..19d8a541 100644 --- a/src/Installer/Database/OracleDatabase.php +++ b/src/Installer/Database/OracleDatabase.php @@ -28,6 +28,6 @@ class OracleDatabase extends AbstractDatabase { public $type = 'oci'; public function getCreateDatabaseCommand() { - // For Oracle 12 or superior. + return "echo 'All done!'"; } } diff --git a/tests/Installer/Database/DatabaseResolverTest.php b/tests/Installer/Database/DatabaseResolverTest.php index a11552ed..caf1870b 100644 --- a/tests/Installer/Database/DatabaseResolverTest.php +++ b/tests/Installer/Database/DatabaseResolverTest.php @@ -32,6 +32,10 @@ public function testType() 'MoodlePluginCI\Installer\Database\MariaDBDatabase', $resolver->resolveDatabase('mariadb') ); + $this->assertInstanceOf( + 'MoodlePluginCI\Installer\Database\OracleDatabase', + $resolver->resolveDatabase('oci') + ); } public function testTypeError() diff --git a/tests/Installer/Database/OracleDatabaseTest.php b/tests/Installer/Database/OracleDatabaseTest.php new file mode 100644 index 00000000..37d76168 --- /dev/null +++ b/tests/Installer/Database/OracleDatabaseTest.php @@ -0,0 +1,30 @@ +name = 'TestName'; + $database->user = 'TestUser'; + $database->pass = 'TestPass'; + $database->host = 'TestHost'; + + $expected = 'echo \'All done!\''; + $this->assertSame($expected, $database->getCreateDatabaseCommand()); + } +}