Esempio n. 1
0
def run(name):
    """
    Run unit tests for a theme or plugin
    """
    require('settings', provided_by=[
        'vagrant',
    ])

    with cd(env.path):
        plugins = json.loads(
            helpers.capture('wp plugin list --format=json --fields=name',
                            cmd_type='run'))
        themes = json.loads(
            helpers.capture('wp theme list --format=json --fields=name',
                            cmd_type='run'))

        test = {'name': name}
        if test in plugins:
            directory = get_path('plugin', name)
        elif test in themes:
            directory = get_path('theme', name)

    shell_env_vars = {'WP_TESTS_DIR': WP_TESTS_DIR, 'WP_CORE_DIR': WP_CORE_DIR}
    with cd(directory), shell_env(**shell_env_vars), settings(warn_only=True):
        if env.verbose:
            run_cmd('phpunit --verbose')
        else:
            run_cmd('phpunit')
Esempio n. 2
0
def install_phpunit():
    """
    Install phpunit on target environment
    """
    require('settings', provided_by=['dev', 'staging', 'production'])
    run_cmd('wget https://phar.phpunit.de/phpunit.phar')
    run_cmd('chmod +x phpunit.phar')
    sudo('mv phpunit.phar /usr/local/bin/phpunit')
Esempio n. 3
0
def scaffold_tests(dir=None):
    with cd(dir), settings(warn_only=True), shell_env(
            WP_TESTS_DIR=WP_TESTS_DIR, WP_CORE_DIR=WP_CORE_DIR):
        with hide('running'):
            tests_dir = run_cmd('ls tests')
            if tests_dir.find('No such file or directory') > -1:
                print(colors.cyan("Copying essential test files..."))

                sudo('mkdir tests')
                print(colors.cyan("Created 'tests' directory..."))

                # Install some basic sample test files
                print(
                    colors.green("Copying test-sample.php and bootstrap.php"))
                put('tools/fablib/etc/test-sample.php',
                    'tests/test-sample.php',
                    use_sudo=True)
                put('tools/fablib/etc/bootstrap-sample.php',
                    'tests/bootstrap.php',
                    use_sudo=True)
            else:
                print(
                    colors.yellow(
                        "Skip copying essential test files ('tests' directory already exists)..."
                    ))

            config_file = run_cmd('ls phpunit.xml')
            if config_file.find('No such file or directory') > -1:
                print(colors.green("Copying base phpunit.xml..."))
                put('tools/fablib/etc/phpunit-sample.xml',
                    'phpunit.xml',
                    use_sudo=True)
            else:
                print(
                    colors.yellow(
                        "Skip copying phpunit.xml (file already exists)..."))

            # Install the WP test framework
            sudo('rm -Rf %s' % WP_TESTS_DIR)
            print(
                colors.green("Installing the WordPress testing framework..."))
            vagrant.destroy_db(WP_TEST_DB)
            put('tools/fablib/etc/install-wp-tests.sh',
                '/tmp/install-wp-tests.sh',
                use_sudo=True)
            sudo('bash /tmp/install-wp-tests.sh %s root root localhost "%s"' %
                 (WP_TEST_DB, WP_VERSION))