Skip to content

Commit

Permalink
WIP: Test database (#3)
Browse files Browse the repository at this point in the history
* WIP: Test Database

* WIP: Fail artifact

* WIP: Zip artifact

* WIP: Get database driver

* WIP: Get driver name

* WIP: Verbose output

* WIP: Get database driver

* WIP: Get driver

* WIP: grup testing

* WIP: Regisrar database config

* WIP: codeigniter database test

* WIP: Fix missing primary key

* WIP: Fix missing primary key

* WIP: Fix missing primary key

* WIP: Remove default value field json

* WIP: Overwrite default connection

* WIP: second connection

* WIP: Database second connection

* WIP: Remove test Count Pagination Grouping

* WIP: teardown drop table

* WIP: Fix Sqlsrv drop table

* WIP: Remove test for postgre, sqlsrv for now
  • Loading branch information
agungsugiarto authored Feb 14, 2022
1 parent d9d591b commit 06430ca
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 55 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1']
db-platforms: ['MySQLi', 'Postgre', 'SQLite3', 'SQLSRV']
db-platforms: ['MySQLi', 'SQLite3',]
mysql-versions: ['5.7']
include:
- php-versions: '7.4'
Expand Down Expand Up @@ -53,7 +53,6 @@ jobs:
- name: Create database for MSSQL Server
if: matrix.db-platforms == 'SQLSRV'
run: sqlcmd -S 127.0.0.1 -U sa -P 1Secure*Password1 -Q "CREATE DATABASE test"

- name: Checkout
uses: actions/checkout@v2

Expand Down Expand Up @@ -83,7 +82,7 @@ jobs:
composer update --ansi --no-interaction
- name: Test with PHPUnit
run: script -e -c "vendor/bin/phpunit --color=always"
run: script -e -c "vendor/bin/phpunit"
env:
DB: ${{ matrix.db-platforms }}
TERM: xterm-256color
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fluent CodeIgniter4 ORM

[![tests](https://github.com/agungsugiarto/codeigniter4-orm/actions/workflows/php.yml/badge.svg)](https://github.com/agungsugiarto/codeigniter4-orm/actions/workflows/test-phpunit.yml)
[![tests](https://github.com/agungsugiarto/codeigniter4-orm/actions/workflows/test-phpunit.yml/badge.svg)](https://github.com/agungsugiarto/codeigniter4-orm/actions/workflows/test-phpunit.yml)
[![Latest Stable Version](https://poser.pugx.org/agungsugiarto/codeigniter4-orm/v)](https://github.com/agungsugiarto/codeigniter4-orm/releases)
[![Total Downloads](https://poser.pugx.org/agungsugiarto/codeigniter4-orm/downloads)](https://packagist.org/packages/agungsugiarto/codeigniter4-orm/stats)
[![Latest Unstable Version](https://poser.pugx.org/agungsugiarto/codeigniter4-orm/v/unstable)](https://packagist.org/packages/agungsugiarto/codeigniter4-orm)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
}
},
"scripts": {
"test": "phpunit --dont-report-useless-tests --colors=always"
"test": "phpunit --dont-report-useless-tests --colors=always --verbose"
}
}
8 changes: 0 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,5 @@
<const name="HOMEPATH" value="./"/>
<const name="CONFIGPATH" value="./vendor/codeigniter4/framework/app/Config/"/>
<const name="PUBLICPATH" value="./vendor/codeigniter4/framework/public/"/>

<env name="database.tests.database" value=":memory:"/>
<env name="database.tests.DBDriver" value="SQLite3"/>
<env name="database.tests.DBPrefix" value=""/>

<env name="database.default.database" value=":memory:"/>
<env name="database.default.DBDriver" value="SQLite3"/>
<env name="database.default.DBPrefix" value=""/>
</php>
</phpunit>
177 changes: 177 additions & 0 deletions tests/Config/Registrar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Fluent\Orm\Tests\Config;

/**
* Class Registrar
*
* Provides a basic registrar class for testing BaseConfig registration functions.
*/
class Registrar
{
/**
* DB config array for testing purposes.
*
* @var array
*/
protected static $dbConfig = [
'MySQLi' => [
'DSN' => '',
'hostname' => '127.0.0.1',
'username' => 'root',
'password' => '',
'database' => 'test',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
],
'Postgre' => [
'DSN' => '',
'hostname' => 'localhost',
'username' => 'postgres',
'password' => 'postgres',
'database' => 'test',
'DBDriver' => 'Postgre',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 5432,
],
'SQLite3' => [
'DSN' => '',
'hostname' => '127.0.0.1',
'username' => '',
'password' => '',
'database' => ':memory:',
'DBDriver' => 'SQLite3',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
],
'second_connection' => [
'DSN' => '',
'hostname' => '127.0.0.1',
'username' => '',
'password' => '',
'database' => ':memory:',
'DBDriver' => 'SQLite3',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 3306,
],
'SQLSRV' => [
'DSN' => '',
'hostname' => 'localhost',
'username' => 'sa',
'password' => '1Secure*Password1',
'database' => 'test',
'DBDriver' => 'SQLSRV',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 1433,
],
'OCI8' => [
'DSN' => 'localhost:1521/XEPDB1',
'hostname' => '',
'username' => 'ORACLE',
'password' => 'ORACLE',
'database' => '',
'DBDriver' => 'OCI8',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
],
];

/**
* Override database config
*
* @return array
*/
public static function Database()
{
$config = [];

// Under GitHub Actions, we can set an ENV var named 'DB'
// so that we can test against multiple databases.
if ($group = getenv('DB')) {
if (! empty(self::$dbConfig[$group])) {
$config['tests'] = self::$dbConfig[$group];
}
}

$config['second_connection'] = self::$dbConfig['second_connection'];

return $config;
}

/**
* Demonstrates Publisher security.
*
* @see PublisherRestrictionsTest::testRegistrarsNotAllowed()
*
* @return array
*/
public static function Publisher()
{
return [
'restrictions' => [SUPPORTPATH => '*'],
];
}
}
6 changes: 6 additions & 0 deletions tests/DatabaseEloquentHasOneThroughIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function createSchema()
'updated_at' => ['type' => 'datetime', 'null' => true],
'deleted_at' => ['type' => 'datetime', 'null' => true],
])
->addPrimaryKey('id')
->createTable('users', true);

$this->schema()->addField([
Expand All @@ -42,6 +43,7 @@ public function createSchema()
'created_at' => ['type' => 'datetime', 'null' => true],
'updated_at' => ['type' => 'datetime', 'null' => true],
])
->addPrimaryKey('id')
->createTable('contracts', true);

$this->schema()->addField([
Expand All @@ -51,6 +53,7 @@ public function createSchema()
'created_at' => ['type' => 'datetime', 'null' => true],
'updated_at' => ['type' => 'datetime', 'null' => true],
])
->addPrimaryKey('id')
->createTable('positions', true);
}

Expand Down Expand Up @@ -319,6 +322,7 @@ protected function migrateDefault()
'created_at' => ['type' => 'datetime', 'null' => true],
'updated_at' => ['type' => 'datetime', 'null' => true],
])
->addPrimaryKey('id')
->createTable('users_default', true);

$this->schema()->addField([
Expand All @@ -329,6 +333,7 @@ protected function migrateDefault()
'created_at' => ['type' => 'datetime', 'null' => true],
'updated_at' => ['type' => 'datetime', 'null' => true],
])
->addPrimaryKey('id')
->createTable('contracts_default', true);

$this->schema()->addField([
Expand All @@ -337,6 +342,7 @@ protected function migrateDefault()
'created_at' => ['type' => 'datetime', 'null' => true],
'updated_at' => ['type' => 'datetime', 'null' => true],
])
->addPrimaryKey('id')
->createTable('positions_default', true);
}

Expand Down
Loading

0 comments on commit 06430ca

Please sign in to comment.