Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,29 @@ jobs:
fail-fast: false
matrix:
php-version: [8.3, 8.4]
db:
- '{"vendor": "MySQL 8.4", "pdo": "mysql", "dsn": "mysql://bedita:[email protected]:3306/bedita", "image": "mysql:8.4", "options": "--health-cmd \"mysqladmin ping -h localhost\" --health-interval 10s --health-timeout 5s --health-retries 5"}'
- '{"vendor": "SQLite", "pdo": "sqlite", "dsn": "sqlite://tmp/test.sql", "db_name": "", "image": "nginx:alpine", "options": "--health-cmd \"/bin/true\" --health-interval 1s --health-timeout 2s --health-retries 5"}'
- '{"vendor": "PostgreSQL 18", "pdo": "pgsql", "dsn": "postgres://bedita:[email protected]:5432/bedita", "image": "postgres:18", "options": "--health-cmd \"pg_isready\" --health-interval 10s --health-timeout 5s --health-retries 5"}'
env:
PHP_VERSION: '${{ matrix.php-version }}'
DATABASE_URL: '${{ fromJson(matrix.db).dsn }}'
DATABASE_TEST_URL: '${{ fromJson(matrix.db).dsn }}'

services:
db:
image: '${{ fromJson(matrix.db).image }}'
env:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
MYSQL_USER: 'bedita'
MYSQL_PASSWORD: 'bedita'
MYSQL_DATABASE: 'bedita'
POSTGRES_USER: 'bedita'
POSTGRES_PASSWORD: 'bedita'
POSTGRES_DB: 'bedita'
ports:
- '5432:5432'
options: '${{ fromJson(matrix.db).options }}'

steps:
- name: 'Checkout current revision'
Expand All @@ -52,7 +73,7 @@ jobs:
with:
php-version: '${{ matrix.php-version }}'
tools: 'composer'
extensions: 'mbstring, intl'
extensions: 'mbstring, intl, pdo_${{ fromJson(matrix.db).pdo }}'
coverage: 'pcov'
ini-values: 'pcov.directory=., pcov.exclude="~vendor~"'

Expand Down
54 changes: 21 additions & 33 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,21 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

use Cake\Cache\Cache;
use Cake\Chronos\Chronos;
use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\ConnectionHelper;
use Migrations\TestSuite\Migrator;

/**
* Test runner bootstrap.
*
* Add additional configuration/setup your application needs when running
* unit tests in this file.
*/
require dirname(__DIR__) . '/vendor/autoload.php';

require dirname(__DIR__) . '/config/bootstrap.php';
require dirname(__DIR__) . '/vendor/bedita/core/config/bootstrap.php';

if (empty($_SERVER['HTTP_HOST']) && !Configure::read('App.fullBaseUrl')) {
Configure::write('App.fullBaseUrl', 'http://localhost');
}

// DebugKit skips settings these connection config if PHP SAPI is CLI / PHPDBG.
// But since PagesControllerTest is run with debug enabled and DebugKit is loaded
// in application, without setting up these config DebugKit errors out.
ConnectionManager::setConfig('test_debug_kit', [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Sqlite',
'database' => TMP . 'debug_kit.sqlite',
'encoding' => 'utf8',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
]);

ConnectionManager::alias('test_debug_kit', 'debug_kit');

// Fixate now to avoid one-second-leap-issues
Chronos::setTestNow(Chronos::now());

Expand All @@ -56,19 +38,25 @@
// has been written to.
session_id('cli');

if (!defined('API_KEY')) {
define('API_KEY', 'API_KEY');
}

// Connection aliasing needs to happen before migrations are run.
// Otherwise, table objects inside migrations would use the default datasource
ConnectionHelper::addTestAliases();

// Use migrations to build test database schema.
//
// Will rebuild the database if the migration state differs
// from the migration history in files.
//
// If you are not using CakePHP's migrations you can
// hook into your migration tool of choice here or
// load schema from a SQL dump file with
// use Cake\TestSuite\Fixture\SchemaLoader;
// (new SchemaLoader())->loadSqlFiles('./tests/schema.sql', 'test');
Cache::drop('_bedita_object_types_');
Cache::setConfig('_bedita_object_types_', ['className' => 'Null']);

if (defined('UNIT_TEST_RUN')) {
Cache::clearAll();
$migrator = new Migrator();
$migrator->runMany([
['plugin' => 'BEdita/Core'],
[],
]);
}

// (new Migrator())->run();
Cache::clearAll();
TableRegistry::getTableLocator()->clear();
Loading