2013-10-07 193 views
10

我們使用phing來構建和測試我們的項目。我想盡可能地去除PEAR上的依賴項,這樣我就可以爲不同的項目運行不同版本的軟件包。我創建了安裝所有必要的軟件包Phing和作曲家

{ 
    "require": { 
     "php": ">=5.3.3", 
     "zendframework/zendframework": "2.2.*", 
     "doctrine/doctrine-orm-module": "*", 
     "phpoption/phpoption": "*" 
    }, 
    "require-dev": { 
     "phing/phing": "*", 
     "phpunit/phpunit": "*", 
     "pdepend/pdepend": "*", 
     "phpmd/phpmd": "*", 
     "phploc/phploc": "*", 
     "phpdocumentor/phpdocumentor": "*", 
     "squizlabs/php_codesniffer": "*", 
     "mayflower/php-codebrowser": "*", 
     "sebastian/phpcpd": "*", 
     "zendframework/zftool": "dev-master", 
     "zendframework/zend-form": "*", 
     "hounddog/doctrine-data-fixture-module": "*", 
     "pear/console_commandline": "dev-trunk", 
     "pear/log": "dev-master", 
     "pear/pear_exception": "dev-master" 
    }, 
    "config": { 
     "bin-dir": "vendor/bin/" 
    } 
} 

一個composer.json文件,我有一個phing的build.xml

<?xml version="1.0" encoding="UTF-8"?> 

<project name="SolExactConnector" default="build"> 
    <property name="basedir" value="." override="true"/> 
    <property name="source" value="${basedir}/module"/> 

    <fileset dir="${source}" id="sourceWithoutTests"> 
     <include name="**/*.php"/> 

     <exclude name="*/test/"/> 

     <exclude name="*/Module.php"/> 
     <exclude name="*/config/module.config.php"/> 
     <exclude name="*/test/Bootstrap.php"/> 
    </fileset> 

    <fileset dir="${source}" id="sourceWithTests"> 
     <include name="**/*.php"/> 

     <exclude name="*/Module.php"/> 
     <exclude name="*/config/module.config.php"/> 
     <exclude name="*/test/Bootstrap.php"/> 
    </fileset> 

    <fileset dir="${source}" id="tests"> 
     <include name="*/test/**/*Test.php"/> 
    </fileset> 


    <target name="prepare" description="Clean up and create artifact directories"> 
     <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"/> 
     <delete dir="${basedir}/build/docs"/> 

     <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/docs"/> 
    </target> 

    <target name="phpunit" description="Run unit tests" depends="prepare"> 
     <coverage-setup database="${basedir}/build/logs/coverage.db"> 
      <fileset refid="sourceWithoutTests"/> 
     </coverage-setup> 
     <phpunit haltonfailure="true" haltonerror="true" printsummary="true" bootstrap="test/Bootstrap.php" 
       codecoverage="true"> 
      <formatter todir="${basedir}/build/logs" type="clover" outfile="clover.xml"/> 
      <formatter todir="${basedir}/build/logs" type="xml" outfile="junit.xml"/> 
      <batchtest> 
       <fileset refid="tests"/> 
      </batchtest> 
     </phpunit> 
    </target> 

    <target name="lint" description="Perform syntax check of sourcecode files" depends="prepare"> 
     <phplint haltonfailure="true" cachefile="${basedir}/build/logs/lint.cache"> 
      <fileset refid="sourceWithTests"/> 
     </phplint> 
    </target> 


    <target name="pdepend" description="Generate jdepend.xml and software metrics charts using PHP_Depend" 
      depends="prepare"> 
     <phpdepend file="${source}"> 
      <logger type="jdepend-xml" outfile="${basedir}/build/logs/jdepend.xml"/> 
      <logger type="jdepend-chart" outfile="${basedir}/build/pdepend/dependencies.svg"/> 
      <logger type="overview-pyramid" outfile="${basedir}/build/pdepend/overview-pyramid.svg"/> 
     </phpdepend> 
    </target> 

    <target name="phpmd" description="Generate pmd.xml using PHPMD" depends="prepare"> 
     <phpmd file="${source}"> 
      <formatter type="xml" outfile="${basedir}/build/logs/pmd.xml"/> 
     </phpmd> 
    </target> 

    <target name="phpcpd" description="Generate pmd-cpd.xml using PHPCPD" depends="prepare"> 
     <phpcpd> 
      <formatter type="pmd" outfile="${basedir}/build/logs/pmd-cpd.xml"/> 
      <fileset refid="sourceWithTests"/> 
     </phpcpd> 
    </target> 

    <target name="phploc" description="Generate phploc.xml" depends="prepare"> 
     <phploc reportType="xml" reportName="phploc" 
       reportDirectory="${basedir}/build/logs"> 
      <fileset refid="sourceWithTests"/> 
     </phploc> 
    </target> 

    <target name="phpcs" description="Generate checkstyle.xml using PHP_CodeSniffer" depends="prepare"> 
     <phpcodesniffer 
       standard="PSR2" 
       showSniffs="true" 
       showWarnings="true"> 
      <fileset refid="sourceWithTests"/> 
      <formatter type="default" usefile="false"/> 
      <formatter type="checkstyle" outfile="${basedir}/build/logs/checkstyle-codesniffer.xml"/> 
     </phpcodesniffer> 
    </target> 

    <target name="hphpa" description="HipHop's static analyzer" depends="prepare"> 
     <exec executable="wget" checkreturn="true"> 
      <arg line="https://phar.phpunit.de/hphpa.phar"/> 
     </exec> 
     <exec executable="php hphpa.phar" checkreturn="true"> 
      <arg line="--checkstyle ${basedir}/build/logs/checkstyle-hphpa.xml"/> 
      <arg line="${source}"/> 
     </exec> 
     <delete file="hphpa.phar"/> 
    </target> 

    <target name="phpdoc2" description="Generate API documentation using phpDox" depends="prepare"> 
     <phpdoc2 title="API Documentation" 
       destdir="${basedir}/build/docs" 
       template="responsive-twig"> 
      <fileset refid="sourceWithTests"/> 
     </phpdoc2> 
    </target> 

    <target name="phpcb" description="Aggregate tool output with PHP_CodeBrowser" depends="prepare"> 
     <exec executable="phpcb"> 
      <arg line="--log ${basedir}/build/logs 
       --source ${source} 
       --output ${basedir}/build/code-browser"/> 
     </exec> 
    </target> 

    <target name="composer" description="Installing dependencies" depends="prepare"> 
     <delete dir="${basedir}/vendor"/> 

     <composer command="install"> 
      <arg value="--dev"/> 
     </composer> 
    </target> 

    <target name="doctrine" description="Building Database/Doctrine" depends="prepare"> 
     <copy file="${basedir}/config/autoload/local.php.test" tofile="${basedir}/config/autoload/local.php" 
       haltonerror="true"/> 
     <delete dir="${basedir}/data/db/"/> 
     <mkdir dir="${basedir}/data/db/"/> 
     <chmod file="${basedir}/data/db/" mode="777"/> 

     <exec executable="${basedir}/vendor/bin/doctrine-module"> 
      <arg value="orm:schema-tool:create"/> 
     </exec> 

     <delete dir="${basedir}/data/DoctrineORMModule/Proxy"/> 
     <mkdir dir="${basedir}/data/DoctrineORMModule/Proxy"/> 

     <exec executable="${basedir}/vendor/bin/doctrine-module"> 
      <arg value="orm:generate-proxies"/> 
     </exec> 

     <exec executable="${basedir}/vendor/bin/doctrine-module"> 
      <arg value="data-fixture:import"/> 
     </exec> 

    </target> 

    <target name="build" 
      depends="lint,pdepend,phpcs,phpcpd,phpmd,hphpa,phpdoc2,composer,doctrine,phpunit,phpcb"/> 
</project> 

一些指標(如PHPUnit的,phpmd和phploc)運行正常,但其他人別?例如。當我運行phpcpd我得到這個錯誤:

Execution of target "phpcpd" failed for the following reason: /home/munnik/Sites/SolExactConnector/trunk/build.xml:83:16: /home/munnik/Sites/SolExactConnector/trunk/build.xml:83:16: PHPCPDTask depends on PHPCPD being installed and on include_path.

BUILD FAILED /home/munnik/Sites/SolExactConnector/trunk/build.xml:83:16: /home/munnik/Sites/SolExactConnector/trunk/build.xml:83:16: PHPCPDTask depends on PHPCPD being installed and on include_path. Total time: 0.1250 seconds

我是否需要添加的作曲家自動加載或類似的東西?

+2

看來Phing是假設包使用PEAR安裝。在不同的任務中進行各種檢查以檢查PEAR路徑,並且不檢查作曲者路徑。我認爲這是Phing中的一個錯誤。 –

回答

21

要使用自動加載磁帶機的作曲家,而不是全球性的PEAR包,你可以添加下面一行到你的build.xml開始:

<php expression="include('vendor/autoload.php')"/> 

幫我PHPUnit的(我沒有一個全球性的PHPUnit的PEAR安裝)。認爲這將幫助您成功加載所有的作曲家軟件包。

+0

這對phpDoc – yegor256

+0

沒有任何幫助。重要的是要注意,''是一個標籤,位於頂級''標籤內 - 對於沒有Phing體驗的人來說,這可能並不明顯。 – Guss

1

要設置作曲家自動加載,你可以創建一個目標爲:

<target name="require.autoload"> 
    <adhoc><![CDATA[ 
    require_once 'lib/composer/autoload.php'; 
]]></adhoc> 
</target> 

然後所有需要自動加載的目標,有此要求

<target name="test.coverage.html" depends="require.autoload"> 

注: 要求一旦文件放置在

"config": { 
      "vendor-dir": "lib/composer" 
1

我遇到了完全相同的概率lem,但沒有太多的運氣來修改自動加載器。爲了簡單起見,我決定通過創建<exec>任務來解決問題。除了嵌套的<fileset>元素的丟失(這些需要被指定爲參數)之外,沒有什麼區別。

3

Phing現在提供了一個autoloader task,您可以使用它來包含自己的自動加載器或Composer的自動加載器。

例如:

<autoloader autoloaderpath="vendor/autoload.php"/>