Skip to content

Commit

Permalink
Merge pull request #629 from lucatume/v4-metal-build
Browse files Browse the repository at this point in the history
v4 metal build
  • Loading branch information
lucatume authored Sep 10, 2023
2 parents b0934dc + e15dcc3 commit 0c6a0d1
Show file tree
Hide file tree
Showing 78 changed files with 5,019 additions and 4,635 deletions.
40 changes: 20 additions & 20 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/.git export-ignore
/.gitattributes export-ignore
/.gitbook.yaml export-ignore
/.github export-ignore
/.gitignore export-ignore
/.idea export-ignore
/Makefile export-ignore
/bin export-ignore
/codeception.dist.yml export-ignore
/composer.lock export-ignore
/config export-ignore
/docker-compose.yml export-ignore
/docs export-ignore
/dynamicReturnTypeMeta.json export-ignore
/phpcs.xml export-ignore
/phpstan.neon.dist export-ignore
/tests export-ignore
/var export-ignore
/vendor export-ignore
/version-4-todos.txt export-ignore
/.DS_Store export-ignore
/.cache export-ignore
/.git export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.idea export-ignore
/Makefile export-ignore
/bin export-ignore
/codeception.dist.yml export-ignore
/composer.lock export-ignore
/config export-ignore
/docker-compose.yml export-ignore
/docs export-ignore
/dynamicReturnTypeMeta.json export-ignore
/mkdocs.yml export-ignore
/tests export-ignore
/todo.txt export-ignore
/var export-ignore
/vendor export-ignore
99 changes: 40 additions & 59 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

name: Test

on: # yamllint disable-line rule:truthy
on: # yamllint disable-line rule:truthy
pull_request: null
push:
branches:
Expand All @@ -20,45 +20,30 @@ jobs:
strategy:
matrix:
php_version: [ '8.0', '8.1', '8.2' ]
name: PHP ${{ matrix.php_version }}
suite:
- acceptance
- climodule
- functional
- muloader
- unit
- webdriver
- wpcli_module
- wploader_multisite
- wploader_wpdb_interaction
- wploadersuite
name: ${{ matrix.suite }} php@${{ matrix.php_version }}
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v2

- name: Build WordPress image
uses: docker/build-push-action@v4
with:
context: config/containers/php
file: config/containers/php/Dockerfile
load: true
push: false
tags: wp-browser-wordpress:php${{ matrix.php_version }}-apache
cache-from: type=gha,scope=${{ github.ref }}-${{ matrix.php_version }}-wordpress
cache-to: type=gha,scope=${{ github.ref }}-${{ matrix.php_version }}-wordpress
build-args: |
PHP_VERSION=${{ matrix.php_version }}
TARGET=wordpress
- name: Build Codeception image
uses: docker/build-push-action@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
context: config/containers/php
file: config/containers/php/Dockerfile
load: true
push: false
tags: wp-browser-wordpress:php${{ matrix.php_version }}-codeception
cache-from: type=gha,scope=${{ github.ref }}-${{ matrix.php_version }}-codeception
cache-to: type=gha,scope=${{ github.ref }}-${{ matrix.php_version }}-codeception
build-args: |
PHP_VERSION=${{ matrix.php_version }}
TARGET=codeception
- name: Build
run: bin/stack -p${{ matrix.php_version }} -s build
php-version: ${{ matrix.php_version }}
extensions: uopz, sqlite3, gd
ini-values: post_max_size=256M, max_execution_time=180, uopz.exit=1
tools: composer

- name: Cache Composer dependencies
uses: actions/cache@v3
Expand All @@ -67,34 +52,30 @@ jobs:
key: ${{ runner.os }}-${{ hashFiles('**/composer.json') }}

- name: Install dependencies
run: bin/stack -p${{ matrix.php_version }} composer_update

- name: acceptance
run: bin/stack -p${{ matrix.php_version }} run acceptance --ext DotReporter
run: composer update

- name: climodule
run: bin/stack -p${{ matrix.php_version }} run climodule --ext DotReporter
- name: Update ChromeDriver
run: vendor/bin/codecept chromedriver:update --binary /usr/bin/google-chrome

- name: functional
run: bin/stack -p${{ matrix.php_version }} run functional --ext DotReporter
- name: Create var/wordpress directory
run: mkdir -p var/wordpress

- name: muloader
run: bin/stack -p${{ matrix.php_version }} run muloader --ext DotReporter
- name: Start services
run: vendor/bin/codecept dev:start

- name: unit
run: bin/stack -p${{ matrix.php_version }} run unit --debug -f
- name: Setup WordPress
run: php bin/setup-wp.php

- name: webdriver
run: bin/stack -p${{ matrix.php_version }} run webdriver --ext DotReporter
- name: Run tests
id: test
run: vendor/bin/codecept run ${{ matrix.suite }}

- name: wpcli_module
run: bin/stack -p${{ matrix.php_version }} run wpcli_module --ext DotReporter

- name: wploader_multisite
run: bin/stack -p${{ matrix.php_version }} run wploader_multisite --ext DotReporter

- name: wploader_wpdb_interaction
run: bin/stack -p${{ matrix.php_version }} run wploader_wpdb_interaction --ext DotReporter

- name: wploadersuite
run: bin/stack -p${{ matrix.php_version }} run wploadersuite --ext DotReporter
- name: Upload Artifacts
uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: ${{ matrix.suite }}-php@${{ matrix.php_version }}-screenshots
path: |
var/_output/*.html
var/_output/*.png
retention-days: 3
69 changes: 36 additions & 33 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Update code to be compatible with Codeception v5, PHP 8.0+ and Composer API 2.2+.
- Added support for the `WPLoader.stylesheet` configuration parameter to allow specifying a distinct `template` and `stylesheet`.
- Changed name of the `WPLoader.theme` to `WPLoader.template`.
- Added the following configuration keys to the `WPLoader` module:
- `dump` - allows specifying one or more dump files to be loaded after the installation and before the first test runs.
- `dbUrl` - allows providing the db name, user, password and host using a single URL, e.g. `mysql://user:password@host:port/db_name`.
- `AUTH_KEY` - `SECURE_AUTH_KEY` - `LOGGED_IN_KEY` - `NONCE_KEY` - `AUTH_SALT` - `SECURE_AUTH_SALT` - `LOGGED_IN_SALT` - `NONCE_SALT` - allows specifying the WordPress salts.
- Support configuring the module using the WordPress constant name directly according to the following map (keys are aliased):
- `ABSPATH` or `wpRootFolder`
- `DB_NAME` or `dbName`
- `DB_USER` or `dbUser`
- `DB_HOST` or `dbHost`
- `DB_PASSWORD` or `dbPassword`
- `DB_CHARSET` or `dbCharset`
- `DB_COLLATE` or `dbCollate`
- `WP_TESTS_MULTISITE` or `multisite`
- `WP_DEFAULT_THEME` or `theme`
- `WP_TESTS_DOMAIN` or `domain`
- `WP_TESTS_EMAIL` or `adminEmail`
- `WP_TESTS_TITLE` or `title`
- Added support for the `dbUrl` configuration parameter to the `WPDb` module; it allows providing the database username, password and DSN with a single URL; e.g. `mysql://user:password@host:port/db_name`.
- Added the `WPCLI::dontSeeShellOutputMatches` method

### Breaking changes

- Move classes in the `tad\WPBrowser` namespace to the `lucatume\WPBrowser` one.
- Move classes in the `Codeception` namespace to the `lucatume\WPBrowser` one.
- Moved functions from the `lucatume\WPBrowser` namespace to dedicated classes in the `lucatume\WPBrowser\Utils`
Expand All @@ -17,8 +41,6 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Removed the `lucatume\WPBrowser` Composer-related functions.
- Removed the `tad\WPBrowser\pregErrorMessage` function.
- Removed support for the `WPLoader.isolatedInstall` configuration parameter; installation always happens in isolation.
- Added support for the `WPLoader.stylesheet` configuration parameter to allow specifying a distinct `template` and `stylesheet`.
- Changed name of the `WPLoader.theme` to `WPLoader.template`.
- Deprecated the `WPLoaer.activatePlugins` parameter: the `WPLoader.plugins` parameter should be used instead.
- Removed the `tad\WPBrowser\processStatus`, `tad\WPBrowser\processReadPipe`, `tad\WPBrowser\process` and `tad\WPBrowser\buildCommandLine` functions.
- Removed the `isolatedInstall` parameter from the `WPLoader` configuration: installation will always happen in isolation.
Expand All @@ -39,37 +61,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- `skipPluggables` - no more required.
- `wpDebug` - the `WP_DEBUG` constant is always set to `true` during tests.
- `activatePlugins` - plugins specified in the `plugins` configuration key will be always activated.
- Added the following configuration keys to the `WPLoader` module:
- `dump` - allows specifying one or more dump files to be loaded after the installation and before the first test runs.
- `dbUrl` - allows providing the db name, user, password and host using a single URL, e.g. `mysql://user:password@host:port/db_name`.
- `AUTH_KEY` - `SECURE_AUTH_KEY` - `LOGGED_IN_KEY` - `NONCE_KEY` - `AUTH_SALT` - `SECURE_AUTH_SALT` - `LOGGED_IN_SALT` - `NONCE_SALT` - allows specifying the WordPress salts.
- Support configuring the module using the WordPress constant name directly according to the following map (keys are aliased):
- `ABSPATH` or `wpRootFolder`
- `DB_NAME` or `dbName`
- `DB_USER` or `dbUser`
- `DB_HOST` or `dbHost`
- `DB_PASSWORD` or `dbPassword`
- `DB_CHARSET` or `dbCharset`
- `DB_COLLATE` or `dbCollate`
- `WP_TESTS_MULTISITE` or `multisite`
- `WP_DEFAULT_THEME` or `theme`
- `WP_TESTS_DOMAIN` or `domain`
- `WP_TESTS_EMAIL` or `adminEmail`
- `WP_TESTS_TITLE` or `title`
- Added support for the `dbUrl` configuration parameter to the `WPDb` module; it allows providing the database username, password and DSN with a single URL; e.g. `mysql://user:password@host:port/db_name`.
- Rewrite the `WPCLI` module to use the `Symfony\Component\Process\Process` class under the hood.
- Added the `WPCLI::dontSeeShellOutputMatches` method
- Update the `WPCLI` module to use supported configuration parameters as strict arguments by default
- Removed the `WithWordPressFilters` trait
- Temporarily remove the `preserveGlobalState` test method support to reimplement support later.
- Removed the `generate:wpajax` command and related support classes.
- Removed the `generate:wpcanonical` command and related support classes.
- Removed the `generate:wprest` command and related support classes.
- Removed the `generate:wprestcontroller` command and related support classes.
- Removed the `generate:wprestposttypecontroller` command and related support classes.
- Removed the `generate:wpxmlrpc` command and related support classes.
- Removed the `Copier` and `Symlinker` extensions.
- Removed support for PHPUnit's `@runInSeparateProcess` annotation.
- Removed support for PHPUnit's `@runInSeparateProcess` annotation.
- Removed the `Copier` and `Symlinker` extensions.
- Removed the `WithWordPressFilters` trait
- Removed the `generate:wpajax` command and related support classes.
- Removed the `generate:wpcanonical` command and related support classes.
- Removed the `generate:wprest` command and related support classes.
- Removed the `generate:wprestcontroller` command and related support classes.
- Removed the `generate:wprestposttypecontroller` command and related support classes.
- Removed the `generate:wpxmlrpc` command and related support classes.
- Rewrite the `WPCLI` module to use the `Symfony\Component\Process\Process` class under the hood.
- Temporarily remove the `preserveGlobalState` test method support to reimplement support later.
- Update the `WPCLI` module to use supported configuration parameters as strict arguments by default

## [3.1.6] 2022-04-28;

Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,12 @@ update_sqlite_plugin:

docs_serve:
mkdocs serve -a 0.0.0.0:8000

wordpress_install:
php bin/setup-wp.php

clean_procs:
pgrep -f 'php -S' | xargs kill
pgrep chromedriver | xargs kill
rm -f var/_output/*.pid var/_output/*.running
.PHONY: clean_procs
121 changes: 121 additions & 0 deletions bin/setup-wp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php

use Codeception\Configuration;
use lucatume\WPBrowser\Utils\Filesystem;
use lucatume\WPBrowser\WordPress\ConfigurationData;
use lucatume\WPBrowser\WordPress\Database\MysqlDatabase;
use lucatume\WPBrowser\WordPress\Installation;
use lucatume\WPBrowser\WordPress\InstallationState\Configured;
use lucatume\WPBrowser\WordPress\InstallationState\EmptyDir;
use lucatume\WPBrowser\WordPress\InstallationState\InstallationStateInterface;
use lucatume\WPBrowser\WordPress\InstallationState\Scaffolded;

require_once dirname(__DIR__) . '/vendor/autoload.php';

global $_composer_autoload_path, $_composer_bin_dir;
$_composer_autoload_path = $_composer_autoload_path ?: (dirname(__DIR__) . '/vendor/autoload.php');
$_composer_bin_dir = $_composer_bin_dir ?: (dirname(__DIR__) . '/vendor/bin');
Configuration::append(['paths' => ['output' => dirname(__DIR__) . '/var/_output']]);

// Source the tests/.env file.
$dotenv = Dotenv\Dotenv::createImmutable(dirname(__DIR__) . '/tests');
$env = $dotenv->load();

$wpRootDir = $env['WORDPRESS_ROOT_DIR'];

echo "Checking WordPress directory $wpRootDir ...\n";
if (!is_dir($wpRootDir) && mkdir($wpRootDir, 0777, true) && !is_dir($wpRootDir)) {
throw new InvalidArgumentException("The WordPress root directory $wpRootDir does not exist.");
}

$installation = new Installation($wpRootDir);

echo "Checking WordPress installation in $wpRootDir ...\n";
if ($installation->getState() instanceof EmptyDir) {
echo "Scaffolding WordPress in $wpRootDir ...\n";
$installation = Installation::scaffold($wpRootDir);
}

echo "Creating database {$env['WORDPRESS_DB_NAME']} ...\n";
$db = new MysqlDatabase(
$env['WORDPRESS_DB_NAME'],
$env['WORDPRESS_DB_USER'],
$env['WORDPRESS_DB_PASSWORD'],
$env['WORDPRESS_DB_HOST'],
$env['WORDPRESS_TABLE_PREFIX'],
);
$db->create();

echo "Checking WordPress configuration in $wpRootDir ...\n";
if ($installation->getState() instanceof Scaffolded) {
echo "Configuring WordPress in $wpRootDir ...\n";
$configData = new ConfigurationData();
$extraPHP = <<< PHP
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
define( 'DISABLE_CRON', true );
PHP;
$configData->setExtraPHP($extraPHP);
$installation = $installation->configure(
$db,
InstallationStateInterface::MULTISITE_SUBFOLDER,
$configData
);
}

echo "Checking WordPress installation in $wpRootDir ...\n";
if ($installation->getState() instanceof Configured) {
$db->drop()->create();
echo "Installing WordPress in $wpRootDir ...\n";
$installation = $installation->install(
$env['WORDPRESS_URL'],
$env['WORDPRESS_ADMIN_USER'],
$env['WORDPRESS_ADMIN_PASSWORD'],
$env['WORDPRESS_ADMIN_USER'] . '@example.com',
'TEST',
);
}

echo "Allowing external connections in $wpRootDir ...\n";
$installation->runWpCliCommand(['config', 'delete', 'WP_HTTP_BLOCK_EXTERNAL']);

foreach (['test_subdir', 'test_subdomain', 'test_empty'] as $dbName) {
echo "Creating database $dbName ...\n";
$db->query("CREATE DATABASE IF NOT EXISTS `$dbName`");
}

echo "Checking TwentyTwenty theme in $wpRootDir ...\n";
if (!is_dir($wpRootDir . '/wp-content/themes/twentytwenty')) {
echo "Installing TwentyTwenty theme in $wpRootDir ...\n";
$installation->runWpCliCommandOrThrow(['theme', 'install', 'twentytwenty', '--activate']);
}

echo "Installing required test plugins in $wpRootDir ...\n";
$installation->runWpCliCommandOrThrow(['plugin', 'install', 'woocommerce', 'akismet', 'hello-dolly']);

echo "Blocking external connections in $wpRootDir ...\n";
$installation->runWpCliCommandOrThrow(['config', 'set', 'WP_HTTP_BLOCK_EXTERNAL', 'true']);

echo "Copying over dummy theme to $wpRootDir ...\n";
if (!is_dir('var/wordpress/wp-content/themes/dummy')
&& !Filesystem::recurseCopy('tests/_data/themes/dummy', 'var/wordpress/wp-content/themes/dummy')) {
throw new RuntimeException('Could not copy dummy theme.');
}

echo "Copying over mu-plugin-1 to $wpRootDir ...\n";
if (!is_dir($wpRootDir . '/wp-content/plugins/mu-plugin-1')
&& !Filesystem::recurseCopy('tests/_data/plugins/mu-plugin-1', $wpRootDir . '/wp-content/plugins/mu-plugin-1')) {
throw new RuntimeException('Could not copy mu-plugin-1.');
}

if (!is_file($wpRootDir . '/wp-cli.yml')) {
$url = $env['WORDPRESS_URL'];
if (!file_put_contents(
$wpRootDir . '/wp-cli.yml',
<<<YAML
url: $url
YAML
)) {
throw new RuntimeException('Could not create wp-cli.yml file.');
}
}
Loading

0 comments on commit 0c6a0d1

Please sign in to comment.