Skip to content

Commit

Permalink
Testing SQLite and no database GitHub Actions (#320)
Browse files Browse the repository at this point in the history
* Test not using a database

* Testing CI

* Testing CI

* Change to main

* Allow sqlite testing to be configured in the config script
  • Loading branch information
srtfisher authored Feb 22, 2024
1 parent 3937d2d commit 4a5ee1f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
34 changes: 34 additions & 0 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<!-- <env name="MANTLE_USE_SQLITE" value="true" /> -->',
'<env name="MANTLE_USE_SQLITE" value="true" />',
(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
Expand Down Expand Up @@ -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(
Expand Down
13 changes: 12 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<phpunit bootstrap="tests/bootstrap.php" backupGlobals="false" colors="true" convertDeprecationsToExceptions="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true">
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="Feature">
<directory suffix=".php">tests/Feature</directory>
Expand All @@ -7,4 +15,7 @@
<directory suffix=".php">tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<!-- <env name="MANTLE_USE_SQLITE" value="true" /> -->
</php>
</phpunit>
4 changes: 0 additions & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 4a5ee1f

Please sign in to comment.