Last active
December 14, 2015 16:38
-
-
Save kaz29/5116408 to your computer and use it in GitHub Desktop.
(CakePHPとか)PHPのテストについての勉強会 - CakePHP2+Jenkinsで継続的インテグレーション
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project name="name-of-project" default="build"> | |
<target name="build" depends="prepare,lint,phploc,pdepend,phpcb,phpmd-ci,phpcs-ci,phpcpd,phpunit"/> | |
<target name="build-parallel" depends="prepare,lint,tools-parallel,phpunit"/> | |
<target name="tools-parallel" description="Run tools in parallel"> | |
<parallel threadCount="3"> | |
<sequential> | |
<antcall target="pdepend"/> | |
<antcall target="phpmd-ci"/> | |
</sequential> | |
<antcall target="phpcpd"/> | |
<antcall target="phpcs-ci"/> | |
<antcall target="phploc"/> | |
<antcall target="phpcb"/> | |
</parallel> | |
</target> | |
<target name="clean" description="Cleanup build artifacts"> | |
<delete dir="${basedir}/build/api"/> | |
<delete dir="${basedir}/build/code-browser"/> | |
<delete dir="${basedir}/build/coverage"/> | |
<delete dir="${basedir}/build/logs"/> | |
<delete dir="${basedir}/build/pdepend"/> | |
</target> | |
<target name="prepare" depends="clean" description="Prepare for build"> | |
<mkdir dir="${basedir}/build/api"/> | |
<mkdir dir="${basedir}/build/code-browser"/> | |
<mkdir dir="${basedir}/build/coverage"/> | |
<mkdir dir="${basedir}/build/logs"/> | |
<mkdir dir="${basedir}/build/pdepend"/> | |
<mkdir dir="${basedir}/build/phpdox"/> | |
</target> | |
<target name="lint" description="Perform syntax check of sourcecode files"> | |
<apply executable="php" failonerror="true"> | |
<arg value="-l" /> | |
<fileset dir="${basedir}/app"> | |
<include name="**/*.php" /> | |
<include name="**/*.ctp" /> | |
<modified /> | |
</fileset> | |
</apply> | |
</target> | |
<target name="phploc" description="Measure project size using PHPLOC"> | |
<exec executable="phploc"> | |
<arg value="--log-csv" /> | |
<arg value="${basedir}/build/logs/phploc.csv" /> | |
<arg value="--exclude"/> | |
<arg value="Test" /> | |
<arg value="--exclude"/> | |
<arg value="Config/Migration" /> | |
<arg value="--exclude"/> | |
<arg value="Plugin" /> | |
<arg path="${basedir}/app" /> | |
</exec> | |
</target> | |
<target name="pdepend" description="Calculate software metrics using PHP_Depend"> | |
<exec executable="pdepend"> | |
<arg value="--jdepend-xml=${basedir}/build/logs/jdepend.xml" /> | |
<arg value="--jdepend-chart=${basedir}/build/pdepend/dependencies.svg" /> | |
<arg value="--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg" /> | |
<arg value="--exclude=${basedir}/app/Vendor,${basedir}/app/webroot" /> | |
<arg path="${basedir}/app" /> | |
</exec> | |
</target> | |
<target name="phpmd" | |
description="Perform project mess detection using PHPMD and print human readable output. Intended for usage on the command line before committing."> | |
<exec executable="phpmd"> | |
<arg path="${basedir}/app" /> | |
<arg value="text" /> | |
<arg value="${basedir}/build/phpmd.xml" /> | |
</exec> | |
</target> | |
<target name="phpmd-ci" description="Perform project mess detection using PHPMD creating a log file for the continuous integration server"> | |
<exec executable="phpmd"> | |
<arg path="${basedir}/app" /> | |
<arg value="xml" /> | |
<arg value="codesize,unusedcode,design,${basedir}/build/phpmd-naming.xml" /> | |
<arg value="--reportfile" /> | |
<arg value="${basedir}/build/logs/pmd.xml" /> | |
<arg value="--exclude" /> | |
<arg value="Test,Config,Vendor,Plugin" /> | |
</exec> | |
</target> | |
<target name="phpcs" | |
description="Find coding standard violations using PHP_CodeSniffer and print human readable output. Intended for usage on the command line before committing."> | |
<exec executable="phpcs"> | |
<arg value="--standard=${basedir}/build/phpcs.xml" /> | |
<arg path="${basedir}/app" /> | |
</exec> | |
</target> | |
<target name="phpcs-ci" description="Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server"> | |
<exec executable="phpcs"> | |
<arg value="--report=checkstyle" /> | |
<arg value="--report-file=${basedir}/build/logs/checkstyle.xml" /> | |
<arg value="--standard=${basedir}/build/phpcs.xml" /> | |
<arg value="--extensions=php"/> | |
<arg value="-p"/> | |
<arg path="${basedir}/app" /> | |
</exec> | |
</target> | |
<target name="phpcpd" description="Find duplicate code using PHPCPD"> | |
<exec executable="phpcpd"> | |
<arg value="--log-pmd" /> | |
<arg value="${basedir}/build/logs/pmd-cpd.xml" /> | |
<arg value="--exclude"/> | |
<arg value="Test" /> | |
<arg value="--exclude"/> | |
<arg value="Config/Migration" /> | |
<arg value="--exclude"/> | |
<arg value="Plugin/" /> | |
<arg path="${basedir}/app" /> | |
</exec> | |
</target> | |
<target name="phpdox" description="Generate API documentation using phpDox"> | |
<exec executable="phpdox"/> | |
</target> | |
<target name="make-tmp-folders"> | |
<mkdir dir="${basedir}/app/tmp/"/> | |
<mkdir dir="${basedir}/app/tmp/cache"/> | |
<mkdir dir="${basedir}/app/tmp/cache/persistent"/> | |
<mkdir dir="${basedir}/app/tmp/cache/models"/> | |
<mkdir dir="${basedir}/app/tmp/cache/views"/> | |
<mkdir dir="${basedir}/app/tmp/logs"/> | |
<mkdir dir="${basedir}/app/tmp/tests"/> | |
<mkdir dir="${basedir}/app/tmp/sessions"/> | |
</target> | |
<target name="migration"> | |
<exec executable="bash" failonerror="true" dir="${basedir}/app"> | |
<arg value="Console/cake"/> | |
<arg value="Migrations.migration"/> | |
<arg value="run"/> | |
<arg value="all"/> | |
</exec> | |
</target> | |
<target name="phpunit" depends="make-tmp-folders,migration" description="Run unit tests with PHPUnit"> | |
<exec executable="bash" failonerror="true" dir="${basedir}/app"> | |
<arg value="Console/cake"/> | |
<arg value="test"/> | |
<arg value="app"/> | |
<arg value="AllTests"/> | |
<arg value="--configuration"/> | |
<arg path="${basedir}/build/phpunit.xml"/> | |
</exec> | |
</target> | |
<target name="phpcb" description="Aggregate tool output with PHP_CodeBrowser"> | |
<exec executable="phpcb"> | |
<arg value="--log" /> | |
<arg path="${basedir}/build/logs" /> | |
<arg value="--source" /> | |
<arg path="${basedir}/app" /> | |
<arg value="--output" /> | |
<arg path="${basedir}/build/code-browser" /> | |
<arg value="--exclude=*/Config/*,*/Test/*,*/Vendor/*,*/View/*" /> | |
</exec> | |
</target> | |
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<ruleset name="Custom Standard"> | |
<!-- http://pear.php.net/manual/en/package.php.php-codesniffer.annotated-ruleset.php --> | |
<description>My custom coding standard</description> | |
<exclude-pattern>*/Test/*</exclude-pattern> | |
<exclude-pattern>*/Config/*</exclude-pattern> | |
<exclude-pattern>*/Console/cake.php</exclude-pattern> | |
<exclude-pattern>*/webroot/*</exclude-pattern> | |
<exclude-pattern>*/app/Vendor/*</exclude-pattern> | |
<exclude-pattern>*/app/Plugin/*</exclude-pattern> | |
<rule ref="PSR1"> | |
<exclude name="Generic.NamingConventions.CamelCapsFunctionName"/> | |
<exclude name="PSR1.Files.SideEffects"/> | |
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/> | |
</rule> | |
<rule ref="PSR2"> | |
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/> | |
<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/> | |
</rule> | |
</ruleset> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<ruleset name="Naming Rules" | |
xmlns="http://pmd.sf.net/ruleset/1.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" | |
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> | |
<description> | |
The Naming Ruleset contains a collection of rules about names - too long, too short, and so forth. | |
</description> | |
<rule name="ShortVariable" | |
since="0.2" | |
message="Avoid variables with short names like {0}. Configured minimum length is {1}." | |
class="PHP_PMD_Rule_Naming_ShortVariable" | |
externalInfoUrl="http://phpmd.org/rules/naming.html#shortvariable"> | |
<description> | |
Detects when a field, local, or parameter has a very short name. | |
</description> | |
<priority>3</priority> | |
<properties> | |
<property name="minimum" description="Minimum length for a variable, property or parameter name" value="2"/> | |
</properties> | |
<example> | |
<![CDATA[ | |
class Something { | |
private $q = 15; // VIOLATION - Field | |
public static function main( array $as ) { // VIOLATION - Formal | |
$r = 20 + $this->q; // VIOLATION - Local | |
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR) | |
$r += $this->q; | |
} | |
} | |
} | |
]]> | |
</example> | |
</rule> | |
<rule name="LongVariable" | |
since="0.2" | |
message="Avoid excessively long variable names like {0}. Keep variable name length under {1}." | |
class="PHP_PMD_Rule_Naming_LongVariable" | |
externalInfoUrl="http://phpmd.org/rules/naming.html#longvariable"> | |
<description> | |
Detects when a field, formal or local variable is declared with a long name. | |
</description> | |
<priority>3</priority> | |
<properties> | |
<property name="maximum" description="The variable length reporting threshold" value="20"/> | |
</properties> | |
<example> | |
<![CDATA[ | |
class Something { | |
protected $reallyLongIntName = -3; // VIOLATION - Field | |
public static function main( array $argumentsList[] ) { // VIOLATION - Formal | |
$otherReallyLongName = -5; // VIOLATION - Local | |
for ($interestingIntIndex = 0; // VIOLATION - For | |
$interestingIntIndex < 10; | |
$interestingIntIndex++ ) { | |
} | |
} | |
} | |
]]> | |
</example> | |
</rule> | |
<rule name="ShortMethodName" | |
since="0.2" | |
message="Avoid using short method names like {0}::{1}(). The configured minimum method name length is {2}." | |
class="PHP_PMD_Rule_Naming_ShortMethodName" | |
externalInfoUrl="http://phpmd.org/rules/naming.html#shortmethodname"> | |
<description> | |
Detects when very short method names are used. | |
</description> | |
<priority>3</priority> | |
<properties> | |
<property name="minimum" description="Minimum length for a method or function name" value="3"/> | |
</properties> | |
<example> | |
<![CDATA[ | |
class ShortMethod { | |
public function a( $index ) { // Violation | |
} | |
} | |
]]> | |
</example> | |
</rule> | |
<rule name="ConstructorWithNameAsEnclosingClass" | |
since="0.2" | |
message="Classes should not have a constructor method with the same name as the class" | |
class="PHP_PMD_Rule_Naming_ConstructorWithNameAsEnclosingClass" | |
externalInfoUrl="http://phpmd.org/rules/naming.html#constructorwithnameasenclosingclass"> | |
<description> | |
A constructor method should not have the same name as the enclosing class, consider | |
to use the PHP 5 __construct method. | |
</description> | |
<priority>3</priority> | |
<example> | |
<![CDATA[ | |
class MyClass { | |
// this is bad because it is PHP 4 style | |
public function MyClass() {} | |
// this is good because it is a PHP 5 constructor | |
public function __construct() {} | |
} | |
]]> | |
</example> | |
</rule> | |
<rule name="ConstantNamingConventions" | |
since="0.2" | |
message="Constant {0} should be defined in uppercase" | |
class="PHP_PMD_Rule_Naming_ConstantNamingConventions" | |
externalInfoUrl="http://phpmd.org/rules/naming.html#constantnamingconventions"> | |
<description> | |
Class/Interface constant nanmes should always be defined in uppercase. | |
</description> | |
<priority>4</priority> | |
<properties /> | |
<example> | |
<![CDATA[ | |
class Foo { | |
const MY_NUM = 0; // ok | |
const myTest = ""; // fail | |
} | |
]]> | |
</example> | |
</rule> | |
<rule name="BooleanGetMethodName" | |
since="0.2" | |
message="The '{0}()' method which returns a boolean should be named 'is...()' or 'has...()'" | |
class="PHP_PMD_Rule_Naming_BooleanGetMethodName" | |
externalInfoUrl="http://phpmd.org/rules/naming.html#booleangetmethodname"> | |
<description> | |
Looks for methods named 'getX()' with 'boolean' as the return type. The convention | |
is to name these methods 'isX()' or 'hasX()'. | |
</description> | |
<priority>4</priority> | |
<properties> | |
<property name="checkParameterizedMethods" value="false" description="Applies only to methods without parameter when set to true" /> | |
</properties> | |
<example> | |
<![CDATA[ | |
class Foo { | |
/** | |
* @return boolean | |
*/ | |
public function getFoo() {} // bad | |
/** | |
* @return bool | |
*/ | |
public function isFoo(); // ok | |
/** | |
* @return boolean | |
*/ | |
public function getFoo($bar); // ok, unless checkParameterizedMethods=true | |
} | |
]]> | |
</example> | |
</rule> | |
</ruleset> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<phpunit> | |
<logging> | |
<log type="coverage-html" target="coverage/" title="Project Name" charset="UTF-8" yui="true" highlight="true" lowUpperBound="35" highLowerBound="70"/> | |
<log type="coverage-clover" target="coverage.xml"/> | |
<log type="junit" target="logs/junit.xml" logIncompleteSkipped="false"/> | |
</logging> | |
<filter> | |
<blacklist> | |
<directory suffix=".php">../lib</directory> | |
<directory suffix=".php">../app/Test</directory> | |
<directory suffix=".php">../app/Vendor</directory> | |
<directory suffix=".php">../app/Config</directory> | |
<directory suffix=".php">../plugins</directory> | |
<directory suffix=".php">../app/Plugin</directory> | |
</blacklist> | |
</filter> | |
<php> | |
<ini name="memory_limit" value="1024M"/> | |
</php> | |
</phpunit> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - | |
echo "deb http://pkg.jenkins-ci.org/debian binary/" > /etc/apt/sources.list.d/jenkins.list | |
apt-get update | |
apt-get install jenkins jenkins-cli git ttf-vlgothic imagemagick libgraphicsmagick1-dev libgraphicsmagick++1-dev libmagickwand-dev -y | |
mkdir -p /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/fonts/fallback | |
ln -s /usr/share/fonts/truetype/vlgothic/VL-PGothic-Regular.ttf /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/fonts/fallback/ | |
echo "JAVA_ARGS=\"-Dfile.encoding=utf-8\"" >> /etc/default/jenkins | |
jenkins-cli -s http://localhost:8080 install-plugin git-client git phing xunit dry pmd checkstyle clover cloverphp notification github github-api jdepend | |
jenkins-cli -s http://localhost:8080 safe-restart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo su - jenkins | |
cd jobs | |
mkdir php-template | |
cd php-template | |
wget https://raw.github.com/sebastianbergmann/php-jenkins-template/master/config.xml | |
jenkins-cli -s http://localhost:8080 reload-configuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt-get install -y php5 php5-pgsql php5-curl php5-cli php5-xdebug postgresql-9.1 postgresql-client-9.1 php-pear php5-imagick | |
pear upgrade-all | |
pear config-set auto_discover 1 | |
pear install pear.phpunit.de/PHPUnit | |
pear install PHP_CodeSniffer | |
pear channel-discover pear.pdepend.org | |
pear channel-discover pear.phpmd.org | |
pear install --alldeps pdepend/PHP_Depend-beta | |
pear install --alldeps phpmd/PHP_PMD-alpha | |
pear install phpunit/phpcpd | |
pear install pear.phpunit.de/phploc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment