Skip to content

Commit

Permalink
refactor(src) fast setup work
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Jul 18, 2023
1 parent 55036e8 commit 1d53e41
Show file tree
Hide file tree
Showing 254 changed files with 9,796 additions and 26,651 deletions.
5 changes: 0 additions & 5 deletions .gitbook.yaml

This file was deleted.

10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- 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.

## [3.1.6] 2022-04-28;

### Changed
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ package: update_core_phpunit_includes test
bin/gitattributes-update
.PHONY: package

update_wp_sqlite_db:
bin/update_wp_sqlite_db

163 changes: 88 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,108 @@

[![CI](https://github.com/lucatume/wp-browser/workflows/CI/badge.svg)](https://github.com/lucatume/wp-browser/actions?query=branch%3Amaster)

wp-browser provides easy acceptance, functional, integration and unit testing for WordPress plugins, themes and
whole sites using [Codeception](http://codeception.com/ "Codeception - BDD-style PHP testing.").
You can use wp-browser to test WordPress sites, plugins and themes.

Find out more in [the documentation](https://wpbrowser.wptestkit.dev).
## Installation

## Installation and setup - the really fast version

Using [Composer](https://getcomposer.org/) require `wp-browser` as a development dependency:
Add wp-browser to your project as a development dependency using [Composer](https://getcomposer.org/):

```bash
cd my-wordrpess-project
composer require --dev lucatume/wp-browser
vendor/bin/codecept init wpbrowser
```

Answer the questions and you will be ready to test your project. Find out more about the setup in [the project
documentation][1].

## Using wp-browser with Codeception 4.0

Codeception version `4.0`, while still being compatible with PHP `5.6` and wp-browser, did break its structure into discrete modules.

If you want to use wp-browser with Codeception version `4.0+` you will need to make sure you've got all the required packages.
Add the following requirements in your `composer.json` file, in the `require-dev` section:

```json
{
"require-dev": {
"lucatume/wp-browser": "^3.0",
"codeception/module-asserts": "^1.0",
"codeception/module-phpbrowser": "^1.0",
"codeception/module-webdriver": "^1.0",
"codeception/module-db": "^1.0",
"codeception/module-filesystem": "^1.0",
"codeception/module-cli": "^1.0",
"codeception/util-universalframework": "^1.0"
}
}
Initialize wp-browser to quickly configured to suite your project and setup:

```bash
vendor/bin/codecept init wpbrowser
```

You might not need all of them depending on the modules you use in your suites, but this will cover all the modules for this project.
The command walks you through a series of questions to configure wp-browser for your project by either following a
default configuration or by asking you to provide the information needed to configure it.

[Read more here.][2]
### Configuration

## Usage
The project provides a number of modules to ease the testing of WordPress projects; you can find out more in the
[modules section of the documentation][3].
Here's a quick example acceptance test you can write:
The default configuration will get you started in little time using:

```php
// tests/acceptance/PrivatePostsCept.php
$I->haveManyPostsInDatabase(3, ['post_title' => 'Test post {{n}}', 'post_status' => 'private']);
* MySQL as the database engine, using [Docker][1] to run the database server
* PHP built-in web server to serve the WordPress site
* Chromedriver installed using [the `webdriver-binary/binary-chromedriver`][2] Composer package

$I->loginAs('subscriber', 'secret');
$I->amOnPage('/');
$I->see('Nothing found');
If you're working on a plugin or theme project, he default configuration will add some extra steps:

* install the latest version of WordPress in the `tests/_wordpress` directory
* create a `tests/_plugins` directory: any file or directory in this directory will be symlinked into the WordPress
installation in `tests/_wordpress/wp-content/plugins`
* create a `tests/_themes` directory: any file or directory in this directory will be symlinked into the WordPress
installation in `tests/_wordpress/wp-content/themes`

For most projects this configuration will be enough to get started with testing.
The default configuration will start all the required services before running the tests; you can start and stop the
running services with the following commands:

```bash
vendor/bin/codecept wp:dev-start
vendor/bin/codecept wp:dev-stop
````

$I->loginAs('editor', 'secret');
$I->amOnPage('/');
$I->see('Test post 0');
$I->see('Test post 1');
$I->see('Test post 2');
If you decide to skip the default configuration, you will be able to set up `wp-browser` to suit your needs and local
setup by editing the `tests/.env` file.
The inline documentation in the file will guide you through the configuration process.

### Running tests

The configuration will set up two test suites:

* `integration` to run your project code in the context of WordPress. This suite works like the one used
by [WordPress Core][6] to run [PHPUnit][3] tests. Integration tests are often referred to as "unit tests" in the
WordPress ecosystem. These are usually low-level and fast tests.
* `end2end` to run tests that interact with the WordPress site using a browser. The default configuration will "drive"
Chrome using ChromeDriver. These tests are high-level and slower than integration tests.

You can run all the tests using this command:

```bash
vendor/bin/codecept run
```

This is just a bite though, find out more in [the documentation][1].

## Current Sponsors

My sincere thanks to my sponsors: you make maintaining this project easier.

* [@Borlabs-Ben](https://github.com/Borlabs-Ben)
* [@DrewAPicture](https://github.com/DrewAPicture)
* [@Luc45](https://github.com/Luc45)
* [@TimothyBJacobs](https://github.com/TimothyBJacobs)
* [@bordoni](https://github.com/bordoni)
* [@borkweb](https://github.com/borkweb)
* [@cliffordp](https://github.com/cliffordp)
* [@dingo-d](https://github.com/dingo-d)
* [@francescamarano](https://github.com/francescamarano)
* [@jchristopher](https://github.com/jchristopher)
* [@jerclarke](https://github.com/jerclarke)
* [@johnbillion](https://github.com/johnbillion)
* [@joppuyo](https://github.com/joppuyo)
* [@moraleida](https://github.com/johnbillion/moreleida)
* [@pods-framework](https://github.com/pods-framework)
* [@roborourke](https://github.com/roborourke)
* [@ryanshoover](https://github.com/ryanshoover)
* [@zackkatz](https://github.com/zackkatz)

[1]: https://wpbrowser.wptestkit.dev/
[2]: https://wpbrowser.wptestkit.dev/levels-of-testing
[3]: https://wpbrowser.wptestkit.dev/modules
> Note: the project replaces Codeception `run` command with one that will run each suite in a separate process. You can
> invoke the original Codeception command using the `codeception:run` command.

You can run a single test suite using this command:

```bash
vendor/bin/codecept run integration
vendor/bin/codecept run end2end
```

There are more commands available to run tests, you can find them in the [Codeception documentation][4].

## Getting support for wp-browser configuration and usage

The best place to get support for wp-browser is [the project documentation][7].
Since this project builds on top of [PHPUnit][3] and [Codeception][4], you can also refer to their documentation.

If you can't find the answer to your question here you can ask on
the ["Issues" section of the wp-browser repository][5].
Finally, you can [contact me directly][7] to set up a call to discuss your project needs and how wp-browser can help
you.
## Sponsors
A thanks to my sponsors: you make maintaining this project easier.
[1]: https://www.docker.com/
[2]: https://packagist.org/packages/webdriver-binary/binary-chromedriver
[3]: https://phpunit.de/
[4]: https://codeception.com/
[5]: https://github.com/lucatume/wp-browser/issues
[6]: https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/
[7]: /docs/README.md
3 changes: 2 additions & 1 deletion bin/stack
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ phpstan)
docker compose exec -u "$(id -u):$(id -g)" -w "$(pwd)" codecept bash -c "composer run stan"
;;
ps)
docker compose ps
shift
docker compose ps "${@}"
;;
ssh)
service=${2:-codecept}
Expand Down
15 changes: 15 additions & 0 deletions bin/update_wp_sqlite_db
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#! /usr/bin/env sh

script_dir=$(dirname "$0")
root_dir=$(cd "$script_dir/.." && pwd)
dropin_file_src="https://raw.githubusercontent.com/aaemnnosttv/wp-sqlite-db/master/src/db.php"
readme_src="https://raw.githubusercontent.com/aaemnnosttv/wp-sqlite-db/master/README.md"
changelog_src="https://raw.githubusercontent.com/aaemnnosttv/wp-sqlite-db/master/CHANGELOG.md"
includes_dir="${root_dir}/includes/wp-sqlite-db"
dropin_file_dest="${includes_dir}/db.php"
readme_dest="${includes_dir}/README.md"
changelog_dest="${includes_dir}/CHANGELOG.md"

curl "${dropin_file}" -o "${dropin_file_dest}"
curl "${readme_src}" -o "${readme_dest}"
curl "${changelog_src}" -o "${changelog_dest}"
31 changes: 15 additions & 16 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@ coverage:
wpFolder: '%WORDPRESS_ROOT_DIR%'
extensions:
enabled:
- lucatume\WPBrowser\Extension\Copier
- lucatume\WPBrowser\Extension\ChromeDriverController
- lucatume\WPBrowser\Extension\BuiltInServerController
- lucatume\WPBrowser\Extension\DockerComposeController
config:
lucatume\WPBrowser\Extension\Copier:
files:
'tests/_data/themes/dummy': '%WORDPRESS_ROOT_DIR%/wp-content/themes/dummy'
'tests/_data/themes/isolated': '%WORDPRESS_ROOT_DIR%/wp-content/themes/isolated'
'tests/_data/plugins/mu-plugin-1': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/mu-plugin-1'
'tests/_data/plugins/test': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/test'
'tests/_data/plugins/isolated-test-plugin': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/isolated-test-plugin'
'tests/_data/plugins/isolated-test-plugin-two': '%WORDPRESS_ROOT_DIR%/wp-content/plugins/isolated-test-plugin-two'
lucatume\WPBrowser\Extension\ChromeDriverController:
port: '%CHROMEDRIVER_PORT%'
lucatume\WPBrowser\Extension\BuiltInServerController:
docroot: '%WORDPRESS_ROOT_DIR%'
workers: 5
port: '%BUILT_IN_SERVER_PORT%'
lucatume\WPBrowser\Extension\DockerComposeController:
compose-file: 'tests/docker-compose.yml'
env-file: 'tests/.env'
commands:
- "lucatume\\WPBrowser\\Command\\RunOriginal"
- "lucatume\\WPBrowser\\Command\\RunAll"
- "lucatume\\WPBrowser\\Command\\GenerateWPUnit"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestApi"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestController"
- "lucatume\\WPBrowser\\Command\\GenerateWPRestPostTypeController"
- "lucatume\\WPBrowser\\Command\\GenerateWPAjax"
- "lucatume\\WPBrowser\\Command\\GenerateWPCanonical"
- "lucatume\\WPBrowser\\Command\\GenerateWPXMLRPC"

- "lucatume\\WPBrowser\\Command\\DevStart"
- "lucatume\\WPBrowser\\Command\\DevStop"
13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"codeception/module-filesystem": "^2.0 || ^3.0",
"codeception/module-cli": "^2.0 || ^3.0",
"symfony/process": ">=4.4.24 <7.0",
"vlucas/phpdotenv": "^5.0"
"vlucas/phpdotenv": "^5.0",
"ifsnop/mysqldump-php": "^2.12"
},
"require-dev": {
"ext-sockets": "*",
Expand All @@ -44,7 +45,8 @@
"szepeviktor/phpstan-wordpress": "^1.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-symfony": "^1.3",
"squizlabs/php_codesniffer": "^3.7"
"squizlabs/php_codesniffer": "^3.7",
"webdriver-binary/binary-chromedriver": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -70,7 +72,8 @@
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
"phpstan/extension-installer": true,
"webdriver-binary/binary-chromedriver": true
}
},
"scripts": {
Expand All @@ -86,5 +89,9 @@
"cs-fix": [
"phpcbf --standard=config/phpcs.xml src"
]
},
"suggest": {
"ext-sqlite3": "For SQLite database support.",
"ext-pdo_sqlite": "For SQLite database support."
}
}
11 changes: 0 additions & 11 deletions docs/.gitignore

This file was deleted.

4 changes: 0 additions & 4 deletions docs/.vscode/extensions.json

This file was deleted.

11 changes: 0 additions & 11 deletions docs/.vscode/launch.json

This file was deleted.

21 changes: 0 additions & 21 deletions docs/LICENSE

This file was deleted.

Loading

0 comments on commit 1d53e41

Please sign in to comment.