Skip to content

Instantly share code, notes, and snippets.

@tolleiv
Last active December 14, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tolleiv/5128874 to your computer and use it in GitHub Desktop.
Save tolleiv/5128874 to your computer and use it in GitHub Desktop.
PHPUnit setup with Composer, a sample project structure and a tiny sample test.
#!/bin/bash -e
# Use guard like described in http://erichogue.ca/2012/09/php/continuous-testing-in-php-with-guard/
# But without guard-phpunit as this isn't ready for the composer setup...
sudo aptitude install ruby1.9.3
sudo gem install guard guard-shell rb-inotify --no-rdoc --no-ri
cat > Guardfile << "EOF"
guard :shell do
watch(%r{^.+Test\.php$}) { |m| `clear ; date; ./vendor/bin/phpunit --colors #{m[0]}` }
end
EOF
guard
#!/bin/bash -e
mkdir -p {Classes,Tests}
curl -sS https://getcomposer.org/installer | php
cat > composer.json <<EOF
{
"name": "aoe/testing",
"license": "BSD-3-Clause",
"authors": [{ "name": "Tolleiv Nietsch" }],
"require-dev": {
"phpunit/phpunit": "*"
},
"minimum-stability": "dev"
}
EOF
php composer.phar install --dev --quiet
cat > phpunit.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false" backupStaticAttributes="false" colors="true" processIsolation="false" stopOnFailure="false" syntaxCheck="true">
<testsuites>
<testsuite name="suite">
<directory>./Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./Classes</directory>
</whitelist>
</filter>
</phpunit>
EOF
cat > ./Tests/DemoTest.php << "EOF"
<?php
class DemoTest extends PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function first() {
$this->assertTrue(false);
}
}
?>
EOF
./vendor/bin/phpunit ./Tests/StackTest.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment