From edbe0ccd30cf11d5f9ea9959b730acfb748fbbaa Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 23 Jan 2024 09:13:47 +0100 Subject: [PATCH 1/3] doc(README.md) add Requirements section, improve site failure messaging --- docs/README.md | 24 ++++++++++++++ src/Project/SiteProject.php | 31 ++++++++++--------- .../WPBrowser/Project/SiteProjectTest.php | 4 +-- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/docs/README.md b/docs/README.md index 0e852f240..44ec6b7bc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,6 +3,26 @@ The wp-browser library provides a set of [Codeception][4] modules and middleware to enable the testing of WordPress sites, plugins and themes. +## Requirements + +Depending on the nature of your project, there are different requirements it will need to satisfy before getting started. + +### Site + +* Ensure you're running the `vendor/bin/codecept init wpbrowser` command from the root directory of your WordPress site. +* Ensure the directory contains the WordPress installation files. In a standard scenario you should have extracted WordPress files in this directory. +* Ensure your installation is configured: it should contain a `wp-config.php` file. + +### Plugin + +* Ensure you're running the `vendor/bin/codecept init wpbrowser` command from the root directory of your plugin; this should be the directory that contains the PHP file defining the [plugin header][6]. + +### Theme + +* Ensure you're running the `vendor/bin/codecept init wpbrowser` command from the root directory of your theme; this should be the directory that contains the `style.css` file defining [the theme header][7]. + +If you decide to use the quick installation, then your PHP version should have the `sqlite3` extensions installed and activated. You can check this using the `php -m` command and verifying the `sqlite3` extension is among the active extensions. + ## Installation Add wp-browser to your project as a development dependency using [Composer][1] @@ -66,3 +86,7 @@ project needs and how wp-browser can help you. [4]: https://codeception.com/ [5]: https://github.com/lucatume/wp-browser/issues/new/choose + +[6]: https://developer.wordpress.org/plugins/plugin-basics/header-requirements/ + +[7]: https://developer.wordpress.org/themes/basics/main-stylesheet-style-css/ diff --git a/src/Project/SiteProject.php b/src/Project/SiteProject.php index 3d0f677f2..44be67349 100644 --- a/src/Project/SiteProject.php +++ b/src/Project/SiteProject.php @@ -38,20 +38,6 @@ public function __construct(InputInterface $input, OutputInterface $output, prot try { $this->installation = Installation::findInDir($this->workDir, false); $installationState = $this->installation->getState(); - - if ($installationState instanceof EmptyDir) { - throw new RuntimeException( - 'The WordPress installation directory is empty' - ); - } - - if ($installationState instanceof Scaffolded) { - throw new RuntimeException( - 'The WordPress installation directory is scaffolded, but not configured.' - ); - } - - $this->testEnvironment = new TestEnvironment(); } catch (Throwable $t) { throw new RuntimeException( 'Failed to initialize the WordPress installation: ' . lcfirst($t->getMessage()), @@ -59,6 +45,23 @@ public function __construct(InputInterface $input, OutputInterface $output, prot $t ); } + + $suggest = "Make sure you're initializing wp-browser at the root of your site project,". + " and that the directory contains the WordPress files and a wp-config.php file."; + + if ($installationState instanceof EmptyDir) { + throw new RuntimeException( + "The WordPress installation directory is empty.\n{$suggest}" + ); + } + + if ($installationState instanceof Scaffolded) { + throw new RuntimeException( + "The WordPress installation directory is scaffolded, but not configured.\n{$suggest}" + ); + } + + $this->testEnvironment = new TestEnvironment(); } public function getType(): string diff --git a/tests/unit/lucatume/WPBrowser/Project/SiteProjectTest.php b/tests/unit/lucatume/WPBrowser/Project/SiteProjectTest.php index 36150dbe6..917013894 100644 --- a/tests/unit/lucatume/WPBrowser/Project/SiteProjectTest.php +++ b/tests/unit/lucatume/WPBrowser/Project/SiteProjectTest.php @@ -43,11 +43,11 @@ public function should_throw_if_trying_scaffold_on_site_that_is_empty(): void } /** - * It should throw if trying to scaffol on site that is not configured + * It should throw if trying to scaffold on site that is not configured * * @test */ - public function should_throw_if_trying_to_scaffol_on_site_that_is_not_configured(): void + public function should_throw_if_trying_to_scaffold_on_site_that_is_not_configured(): void { $composerFileCode = <<< EOT { From 719efcab6c5ac7ba16193ab6eb3ed0abfb98db16 Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Tue, 23 Jan 2024 09:40:20 +0100 Subject: [PATCH 2/3] test(wploadersuite) fix WC+Ajax issue --- .../_generated/WploaderTesterActions.php | 30 +++++++++---------- tests/wploadersuite/AjaxTest.php | 3 ++ tests/wploadersuite/_bootstrap.php | 9 ++++++ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/tests/_support/_generated/WploaderTesterActions.php b/tests/_support/_generated/WploaderTesterActions.php index 9c489023a..7d2b32418 100644 --- a/tests/_support/_generated/WploaderTesterActions.php +++ b/tests/_support/_generated/WploaderTesterActions.php @@ -1,4 +1,4 @@ -getPluginsFolder(); * $hello = $this->getPluginsFolder('hello.php'); * ``` * + * @param string $path A relative path to append to te plugins directory absolute path. + * + * @return string The absolute path to the `pluginsFolder` path or the same with a relative path appended if `$path` + * is provided. * @see \lucatume\WPBrowser\Module\WPLoader::getPluginsFolder() */ public function getPluginsFolder(string $path = ""): string { @@ -69,16 +69,16 @@ public function getPluginsFolder(string $path = ""): string { * * Returns the absolute path to the themes directory. * - * @param string $path A relative path to append to te themes directory absolute path. - * - * @return string The absolute path to the `themesFolder` path or the same with a relative path appended if `$path` - * is provided. * @example * ```php * $themes = $this->getThemesFolder(); * $twentytwenty = $this->getThemesFolder('/twentytwenty'); * ``` * + * @param string $path A relative path to append to te themes directory absolute path. + * + * @return string The absolute path to the `themesFolder` path or the same with a relative path appended if `$path` + * is provided. * @see \lucatume\WPBrowser\Module\WPLoader::getThemesFolder() */ public function getThemesFolder(string $path = ""): string { @@ -93,15 +93,15 @@ public function getThemesFolder(string $path = ""): string { * This method gives access to the same factories provided by the * [Core test suite](https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/). * - * @return FactoryStore A factory store, proxy to get hold of the Core suite object - * factories. - * * @example * ```php * $postId = $I->factory()->post->create(); * $userId = $I->factory()->user->create(['role' => 'administrator']); * ``` * + * @return FactoryStore A factory store, proxy to get hold of the Core suite object + * factories. + * * @link https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/ * @see \lucatume\WPBrowser\Module\WPLoader::factory() */ @@ -115,9 +115,6 @@ public function factory(): \lucatume\WPBrowser\Module\WPLoader\FactoryStore { * * Returns the absolute path to the WordPress content directory. * - * @param string $path An optional path to append to the content directory absolute path. - * - * @return string The content directory absolute path, or a path in it. * @example * ```php * $content = $this->getContentFolder(); @@ -125,6 +122,9 @@ public function factory(): \lucatume\WPBrowser\Module\WPLoader\FactoryStore { * $twentytwenty = $this->getContentFolder('themes/twentytwenty'); * ``` * + * @param string $path An optional path to append to the content directory absolute path. + * + * @return string The content directory absolute path, or a path in it. * @see \lucatume\WPBrowser\Module\WPLoader::getContentFolder() */ public function getContentFolder(string $path = ""): string { diff --git a/tests/wploadersuite/AjaxTest.php b/tests/wploadersuite/AjaxTest.php index 67774a377..c5399bdb4 100644 --- a/tests/wploadersuite/AjaxTest.php +++ b/tests/wploadersuite/AjaxTest.php @@ -1,9 +1,12 @@ Date: Tue, 23 Jan 2024 09:42:37 +0100 Subject: [PATCH 3/3] build(.github/workflows) do not push docs on PR --- .github/workflows/docs.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3609c838b..1e5726f80 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,10 +1,5 @@ name: docs on: - pull_request: - paths: - - 'docs/**' - - 'mkdocs.yml' - - '.github/workflows/docs.yml' push: paths: - 'docs/**'