Can I use phpunit.xml for credentials and phpunit.xml.dist for testsuites?

廉价感情. 提交于 2019-12-12 04:34:59

问题


What I wanted to do was have credentials in the phpunit.xml and the test suites in phpunit.xml.dist. The problem with this setup seems to be that anytime a test is added every developer needs to add it to their own personal phpunit.xml. To get around this, my idea was to have the test suites come from the .dist version. Despite trying a lot of different versions, I'm not sure what I am missing. Here is what I am trying to do

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"
    xmlns:xi="http://www.w3.org/2001/XInclude"
    bootstrap="cfg/phpunit_autoload.php">
<php>
    <var name="DB_DSN" value="mysql:dbname=mysql;host=localhost;port=3306"/>
    <var name="DB_USER" value="root"/>
    <var name="DB_PASS" value="your_local_pass"/>
    <var name="DB_DEFAULTDB" value="mysql"/>        
</php>
<xi:include href="tests/phpunit.xml.dist" parse="xml" xpointer="test-suites">
    <xi:fallback>
        <testsuites id="test-suites">
            <testsuite name="MTD">
                <directory>tests/app/MTD</directory>
            </testsuite>
        </testsuites>
    </xi:fallback>
</xi:include>

The idea is that when someone was getting started for the first time they would copy the .dist file from /tests into root as .xml and replace with their credentials. So instead of the normal setup where .dist and .xml live in the same folder I would have the .xml file at project root and .dist in /tests. Because of the way it was set up, the test suites could come from the versioned file. That way was new testsuites were added, they would get pulled by everyone. Tests would be run using the non versioned .xml as the configuration files and the testsuites element would be included from the versioned .dist file in the /tests folder.

The fallback doesn't seem to work like I was thinking however. The xml parsing seems to get from the .xml file to the .dist file, but it doesn't fallback and return id="test-suites" element, instead the error message is "failed to load external entity "file:/{my_path}/tests/tests/phpunit.xml.dist".

I don't see from the documentation for fallback why it wouldn't be working.


回答1:


What I ended up doing keeping phpunit.xml as a versioned file, not using a phpunit.xml.dist, and putting credentials in a non-versioned phpunit.creds.xml which I refered to using XInclude. I then used a versioned phpunit.creds.xml.dist for a template.



来源:https://stackoverflow.com/questions/41821429/can-i-use-phpunit-xml-for-credentials-and-phpunit-xml-dist-for-testsuites

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!