Skip to content

Instantly share code, notes, and snippets.

@masayuki5160
Last active July 31, 2017 05:21
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 masayuki5160/5a4d510164faa0516d4dd62b8388fe59 to your computer and use it in GitHub Desktop.
Save masayuki5160/5a4d510164faa0516d4dd62b8388fe59 to your computer and use it in GitHub Desktop.
Dockerを使い手軽にPHPUnitをはじめる ref: http://qiita.com/masayuki5160/items/b305d5a19f3ec632f3e3
$ docker pull php:5.6-apache
$ docker run -p 80:80 -v /(ホストの任意のパス)/:/var/www/html --name php56 -d php:5.6-apache
$ docker exec -ti php56 bash
$ apt-get update
$ apt-get install git vim
$ curl -sS https://getcomposer.org/installer | php
{
"name": "phpunit",
"description": "PHPUnit",
"require": {
"phpunit/phpunit": "5.7.*"
},
"config": {
"bin-dir": "/usr/local/bin/"
}
}
$ ./composer.pha install
$ php -v
PHP 5.6.31 (cli) (built: Jul 13 2017 18:38:40)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
$ phpunit --v
PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
<?php
// 2017/07/31 tadsanさんにコメント頂き修正(test/bootstrap.phpへ移した)
// require_once 'vendor/autoload.php';
class firstTest extends PHPUnit_Framework_TestCase
{
public function testMinimumViableTest()
{
$this->assertTrue(false, "falseはtrueではない");
}
}
<?php
require_once __DIR__ . '/../vendor/autoload.php';
<phpunit>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
<!--bootstrap="/path/to/bootstrap.php"-->
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
<!--printerFile="/path/to/ResultPrinter.php"-->
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
<!--testSuiteLoaderFile="/path/to/StandardTestSuiteLoader.php"-->
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="false">
<testsuites>
<testsuite name="My Test Suite">
<file>./firstTest.php</file>
</testsuite>
</testsuites>
</phpunit>
$ phpunit -c phpunit.xml
PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 348 ms, Memory: 3.00MB
There was 1 failure:
1) firstTest::testMinimumViableTest
falseはtrueではない
Failed asserting that false is true.
/var/www/html/firstTest.php:9
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
<phpunit>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"<!-- 2017/07/31 tadsanさんにコメント頂き修正 -->
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
<!--printerFile="/path/to/ResultPrinter.php"-->
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
<!--testSuiteLoaderFile="/path/to/StandardTestSuiteLoader.php"-->
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="false">
<testsuites>
<testsuite name="My Test Suite">
<file>./firstTest.php</file>
</testsuite>
</testsuites>
</phpunit>
$ phpunit -c phpunit.xml
PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 348 ms, Memory: 3.00MB
There was 1 failure:
1) firstTest::testMinimumViableTest
falseはtrueではない
Failed asserting that false is true.
/var/www/html/firstTest.php:9
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment