Skip to content

Instantly share code, notes, and snippets.

@davebarnwell
Last active September 7, 2018 09:37
Show Gist options
  • Save davebarnwell/83b8de3f87c8302befbeb0334768876e to your computer and use it in GitHub Desktop.
Save davebarnwell/83b8de3f87c8302befbeb0334768876e to your computer and use it in GitHub Desktop.
PHPUnit seed

base PHPUnit directory structure

Assumes following dir structure

  ./vendor                  # composer pulling in phpunit
  ./tests                   # directory containing tests namespace prefix \Test\...
  ./tests/run.sh            # This script
  ./tests/phpunit.xml.dist  # PHPUnit xml config
  ./tests/bootstrap.php     # bootstrap for php Tests
  ./composer.json           # composer file to pull in depandancies
<?php
/**
* Unit test bootstrap
*/
// Composer used to get PHPUnit and autoload Test/ namespace
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
// Any additional project specific initialisation
// Set test specific environment variables in the phpunit.xml.dist file along with any other constants, ini settings etc
{
"name": "sched/code",
"description": "main code base",
"type": "project",
"require": {
},
"require-dev": {
"phpunit/phpunit": "^6"
},
"autoload": {
"psr-4": {
"Test\\": "tests/"
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="All">
<directory suffix="Test.php">./</directory>
<!--<exclude>/path/to/exclude</exclude>-->
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<!--<includePath>.</includePath>-->
<!--<ini name="foo" value="bar"/>-->
<!--<const name="foo" value="bar"/>-->
<!--<var name="foo" value="bar"/>-->
<!--<env name="foo" value="bar"/>-->
<!--<post name="foo" value="bar"/>-->
<!--<get name="foo" value="bar"/>-->
<!--<cookie name="foo" value="bar"/>-->
<!--<server name="foo" value="bar"/>-->
<!--<files name="foo" value="bar"/>-->
<!--<request name="foo" value="bar"/>-->
</php>
</phpunit>
#!/usr/bin/env bash
#
# Usage:
# ./run.sh # run all tests
# ./run.sh DIR_NAME # run all tests under DIR_NAME
#
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd "$(dirname "$0")"
echo "running $@"
${DIR}/../vendor/bin/phpunit "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment