composer test에서 QA 도구 실행

개요


phpunit , phpcs , phpmdcomposer test 명령으로 쉽게 실행할 수 있도록 합니다.

준비



※ 현재의 BEAR.Sunday의 어플리케이션 스켈레톤은 이 준비는 완료하고 있습니다.
composer.json 에 다음의 엔트리를 기술합니다.
    "require-dev": {
        "phpunit/phpunit": "~4.8",
        "squizlabs/php_codesniffer": "~2.3",
        "phpmd/phpmd": "~2.3"
    },
    "scripts" :{
        "test": [
            "php vendor/phpmd/phpmd/src/bin/phpmd src text ./phpmd.xml",
            "php vendor/squizlabs/php_codesniffer/scripts/phpcs",
            "php vendor/phpunit/phpunit/phpunit"
        ]
    }
phpunit.xml.dist , phpcs.xml , phpmd.xml 파일을 준비합니다.

phpunit.xml.dist
<phpunit bootstrap="vendor/autoload.php">
    <testsuites>
        <testsuite>
            <directory suffix="Test.php">tests</directory>
        </testsuite>
    </testsuites>

    <logging>
        <log type="coverage-html" target="build/coverage"/>
        <log type="coverage-clover" target="build/logs/clover.xml"/>
        <log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
    </logging>

    <filter>
        <whitelist>
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>

phpcs.xml
<?xml version="1.0"?>
<ruleset>
    <description>The coding standard used for applications using BEAR.Sunday Framework.</description>
    <rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
    <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
    <rule ref="Generic.Strings.UnnecessaryStringConcat"/>
    <rule ref="PSR2">
        <exclude name="Generic.Files.LineLength"/>
        <exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
        <exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
    </rule>
    <rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
    <rule ref="PEAR.Commenting.FunctionComment">
        <exclude name="PEAR.Commenting.FunctionComment.MissingReturn"/>
        <exclude name="PEAR.Commenting.FunctionComment.MissingParamComment"/>
        <exclude name="PEAR.Commenting.FunctionComment.SpacingBeforeTags"/>
        <exclude name="PEAR.Commenting.FunctionComment.MissingParamTag"/>
        <exclude name="PEAR.Commenting.FunctionComment.Missing"/>
        <exclude name="PEAR.Commenting.FunctionComment.MissingReturn"/>
        <exclude name="PEAR.Commenting.FunctionComment.ParameterCommentsNotAligned"/>
        <exclude name="PEAR.Commenting.FileComment.Missing"/>
    </rule>
    <file>src</file>
    <file>tests</file>
</ruleset>

phpmd.xml
<ruleset
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://pmd.sf.net/ruleset/1.0.0"
        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">
    <!--codesize-->
    <rule ref="rulesets/codesize.xml/CyclomaticComplexity">
        <properties>
            <property name="reportLevel" value="20"/>
        </properties>
    </rule>
    <rule ref="rulesets/codesize.xml/NPathComplexity">
        <properties>
            <property name="minimum" value="200"/>
        </properties>
    </rule>
    <rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
        <properties>
            <property name="maximum" value="100"/>
        </properties>
    </rule>
    <rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
    <rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
    <rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
    <rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
    <rule ref="rulesets/codesize.xml/TooManyFields"/>
    <rule ref="rulesets/codesize.xml/TooManyMethods"/>
    <!--design-->
    <rule ref="rulesets/design.xml/EvalExpression"/>
    <rule ref="rulesets/design.xml/ExitExpression"/>
     <rule ref="rulesets/design.xml/GotoStatement" />
    <rule ref="rulesets/design.xml/NumberOfChildren"/>
    <rule ref="rulesets/design.xml/DepthOfInheritance"/>
    <!-- <rule ref="rulesets/design.xml/CouplingBetweenObjects" /> -->
    <!--naming-->
    <rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
    <rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
    <!--unusedcode-->
    <rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>
    <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
    <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
    <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
    <!--controversial-->
    <rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
    <rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
    <rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
    <!--cleancode-->
    <rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
    <!-- <rule ref="rulesets/cleancode.xml/ElseExpression" /> -->
</ruleset>

phpunit 실행


vendor/bin/phpunit 에서 실행한 유닛 테스트는 build/coverage/index.html 에서 테스트 커버리지를 확인할 수 있습니다.
$ vendor/bin/phpunit 
....

Time: 2.76 seconds, Memory: 14.50Mb

OK (4 tests, 5 assertions)

Generating code coverage report in Clover XML format ... done

Generating code coverage report in HTML format ... done



composer test 실행


composer test 명령으로 phpunit 뿐만 아니라 phpcs 또는 phpmd 를 함께 실행할 수 있습니다.
composer test
> php vendor/phpmd/phpmd/src/bin/phpmd src text ./phpmd.xml
> php vendor/squizlabs/php_codesniffer/scripts/phpcs
> php vendor/phpunit/phpunit/phpunit

설정값 조정


phpmd 또는 phpcs의 설정 파일을 자신의 프로젝트 정책에 맞게 조정합니다.

phpmd


CyclomaticComplexity , NPathComplexity , ExcessiveClassComplexity 는 프로그램의 복잡성()에 대한 값입니다. <properties> 태그의 값을 반으로 하면 디폴트의 엄격한 값이 됩니다.

else 구는 사용하지 않는다」라고 하는 룰을 채용하는 경우는 <rule ref="rulesets/cleancode.xml/ElseExpression" /> 의 코멘트를 제외합니다.
(BEAR.Sunday는 모든 패키지에서 채택하고 있습니다.

규칙에 대한 자세한 내용은 htp // tk 라마 r. bgs포 t. jp / 2008 / 01 / 에일 세이 s-에 ゃ l. HTML을 참조하십시오.

phpcs



phpcs는 elsesrc/ 폴더를 대상으로합니다.
규칙에 대한 자세한 내용은 htp://phpmd. 오 rg/루ぇs/어서 x. HTML을 참조하십시오.

활용 팁



git hook



커밋 시 테스트가 실행됩니다.

.git/hooks/pre-commit
#!/bin/sh

composer test

phpStorm의 External Tools에서



htps : // 기주 b. 이 m/s 쿠이→아 bs/PHP_코로 S 니후ぇr/우우키/안오타테 d-루 ぇ세 t. xml

Tools > External Tools > QA Tools에서 실행할 수 있습니다.

좋은 웹페이지 즐겨찾기