2013-10-07 12 views
10

हम अपनी परियोजना बनाने और परीक्षण करने के लिए फ़िंग का उपयोग करते हैं। मैं जितना संभव हो सके पियर पर निर्भरता को हटाना चाहता हूं ताकि मैं विभिन्न परियोजनाओं के लिए पैकेज के विभिन्न संस्करण चला सकूं। मैं एक composer.json फ़ाइल जो सभी आवश्यक संकुलफ़िंग और संगीतकार

{ 
    "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/" 
    } 
} 

स्थापित बनाया है और मैं एक 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 की तरह)

ठीक चलाने, लेकिन दूसरों के लिए है नहीं करते हैं? जैसे

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

मैं संगीतकार autoload या ऐसा ही कुछ जोड़ने की आवश्यकता है: जब मैं phpcpd चलाने मैं इस त्रुटि मिलती है?

+2

यह Phing संभालने है संकुल नाशपाती का उपयोग कर स्थापित कर रहे हैं लगता है। विभिन्न कार्यों में विभिन्न जांच PEAR पथों की जांच करें और संगीतकार पथों की जांच न करें। मुझे लगता है कि यह फ़िंग में एक बग है। –

उत्तर

21

संगीतकार autoloader के बजाय वैश्विक नाशपाती संकुल का उपयोग करने के लिए आप अपने build.xml की शुरुआत में निम्नलिखित पंक्ति जोड़ सकते हैं:

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

यह मैं PHPUnit (मैं न एक वैश्विक PHPUnit नाशपाती स्थापना की है) के साथ मदद की। सोचें कि इससे आपको अपने सभी संगीतकार पैकेजों को सफलतापूर्वक लोड करने में मदद मिलेगी।

+0

यह phpDoc – yegor256

+0

के साथ मदद नहीं करता है यह ध्यान रखना महत्वपूर्ण है कि '' एक टैग है जो शीर्ष-स्तर ' 'टैग के अंदर जाता है - यह फ़िंग अनुभव वाले लोगों के लिए स्पष्ट नहीं हो सकता है । – Guss

1

संगीतकार autoloader आप एक लक्ष्य बना सकते हैं सेट करने के लिए के रूप में:

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

तो सभी लक्ष्यों autoloader जरूरत है कि, इस आवश्यकता है

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

नोट: की आवश्यकता होती है एक बार फ़ाइल में रखा

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

मैं बिल्कुल वही जांच में भाग गया लेम, लेकिन ऑटोलोडर संशोधित करने में बहुत भाग्य नहीं था। मैंने सादगी के लिए <exec> कार्यों को बनाकर काम करने का फैसला किया। नेस्टेड <fileset> तत्वों के नुकसान के अलावा बहुत अंतर नहीं है (इन्हें इसके बजाय तर्क के रूप में निर्दिष्ट करने की आवश्यकता है)।

3

फ़िंग अब autoloader task प्रदान करता है, जिसका उपयोग आप अपने स्वयं के ऑटोलोडर या संगीतकार के ऑटोलोडर को शामिल करने के लिए कर सकते हैं।

उदाहरण के लिए:

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