diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5086f3d..a0e7173 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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:bedita@127.0.0.1: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:bedita@127.0.0.1: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' @@ -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~"' diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b2fbaa4..16cfb85 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -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()); @@ -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();