wp-browser Copier extension

Introducing the Copier extension to WP-Browser.

The problem

The work in progress version of wp-browser features a new extension that scratches an itch I’ve had while developing a theme oriented support for the next version of wp-browser: I needed a way to copy a test theme to the WordPress test installation before my suite would run to see how the WPLoader module would handle it.
The wp-browser package already has a symbolic linking extension that’s useful to test plugins from a central folder to different target installations but there are still some hiccups in handling symbolically linked themes in WordPress and I wanted to take that potential problem out of the equation.
I was able to setup some procedures in the tests setUp and tearDown methods to do it but the functionality might come useful more than once and there is little sense in not baking it into wp-browser.

The Copier extension

The copier extension does two things:

  • copy some files from a source folder to a destination folder before the suite modules are initialized
  • remove the copied files after the tests ran

To use the extension the drill is the same used for any other Codeception extension; an example codeception.yml configuration file is the one below:

actor: Tester
paths:
    tests: tests
    log: tests/_output
    data: tests/_data
    helpers: tests/_support
settings:
    bootstrap: _bootstrap.php
    colors: true
    memory_limit: 1024M
extensions:
    enabled:
        - tad\WPBrowser\Extension\Copier
    config:
        tad\WPBrowser\Extension\Copier:
            files:
               'src/drop-ins/my-experimental-cache.php': '/var/www/wordpress/wp-content/my-experimental-cache.php'
               'vendor/acme/required-plugin': '/var/www/wordpress/wp-content/plugins/required-plugin'
               'tests/_data/themes/dummy': '/var/www/wordpress/wp-content/themes/dummy'
               'tests/_data/themes/broken': '/var/www/wordpress/wp-content/themes/broken'

When running the codecept command the files required to fulfill the test pre-conditions are copied from the source folders to the development WordPress installation preserving the file structure.
The extension allows specifying folders and files as sources and handles relative paths (as I’m doing when specifying the sources) and will be part of wp-browser next release along with explicit theme support.

I appreciate your input