From 4a5ee1ff78a5600f047d33d03bd40be08d555c45 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 22 Feb 2024 09:50:03 -0500 Subject: [PATCH] Testing SQLite and no database GitHub Actions (#320) * Test not using a database * Testing CI * Testing CI * Change to main * Allow sqlite testing to be configured in the config script --- configure.php | 34 ++++++++++++++++++++++++++++++++++ phpunit.xml | 13 ++++++++++++- tests/bootstrap.php | 4 ---- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/configure.php b/configure.php index a0fcfc3b..eb3aeea0 100644 --- a/configure.php +++ b/configure.php @@ -350,6 +350,36 @@ function contributing_message( string $message ): void { echo "\t\e]8;;https://github.com/alleyinteractive/.github/blob/main/CONTRIBUTING.md#best-practices\e\\CONTRIBUTING.md\e]8;;\e\\\n\n"; } +function enable_sqlite_testing(): void { + if ( ! file_exists( __DIR__ . '/phpunit.xml' ) ) { + return; + } + + file_put_contents( + __DIR__ . '/phpunit.xml', + str_replace( + '', + '', + (string) file_get_contents( __DIR__ . '/phpunit.xml' ), + ), + ); + + if ( file_exists( __DIR__ . '/.github/workflows/unit-test.yml' ) ) { + file_put_contents( + __DIR__ . '/.github/workflows/unit-test.yml', + str_replace( + 'with:', + "with:\n database: 'false'", + (string) file_get_contents( __DIR__ . '/.github/workflows/unit-test.yml' ), + ), + ); + } +} + +// --------------------------------------------------------- +// Start of the script. Above this line are the functions. +// --------------------------------------------------------- + echo "\nWelcome friend to alleyinteractive/create-wordpress-plugin! 😀\nLet's setup your WordPress Plugin 🚀\n\n"; // Always delete the 'merge-develop-to-scaffold.yml' file (this is never used in @@ -717,6 +747,10 @@ function contributing_message( string $message ): void { } } +if ( $standalone && confirm( 'Do you want to use SQLite for unit testing?', true ) ) { + enable_sqlite_testing(); +} + // Offer to delete the built asset workflows if built assets aren't needed. if ( ! $needs_built_assets && file_exists( '.github/workflows/built-release.yml' ) && confirm( 'Delete the Github actions for built assets?', true ) ) { delete_files( diff --git a/phpunit.xml b/phpunit.xml index 9325a66e..a7fc0882 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,4 +1,12 @@ - + + tests/Feature @@ -7,4 +15,7 @@ tests/Unit + + + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index daad0506..475155b5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,10 +13,6 @@ \Mantle\Testing\manager() // Rsync the plugin to plugins/create-wordpress-plugin when testing. ->maybe_rsync_plugin() - - // Use SQLite for testing instead of SQL (disabled by default). - // ->with_sqlite() - // Load the main file of the plugin. ->loaded( fn () => require_once __DIR__ . '/../plugin.php' ) ->install();