cvs: peardoc /en/guide/developers/recommendations unittestconfig.xml

From: Date: Thu, 08 May 2008 16:54:14 +0000
Subject: cvs: peardoc /en/guide/developers/recommendations unittestconfig.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-10766@lists.php.net to get a copy of this message
cweiske Thu May 8 16:54:14 2008 UTC Modified files: /peardoc/en/guide/developers/recommendations unittestconfig.xml Log: Add sample how to check for config file http://cvs.php.net/viewvc.cgi/peardoc/en/guide/developers/recommendations/unittestconfig.xml?r1=1.1&r2=1.2&diff_format=u Index: peardoc/en/guide/developers/recommendations/unittestconfig.xml diff -u peardoc/en/guide/developers/recommendations/unittestconfig.xml:1.1 peardoc/en/guide/developers/recommendations/unittestconfig.xml:1.2 --- peardoc/en/guide/developers/recommendations/unittestconfig.xml:1.1 Tue Apr 29 20:49:43 2008 +++ peardoc/en/guide/developers/recommendations/unittestconfig.xml Thu May 8 16:54:14 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <sect1 id="developers.recommendations.unittestconfig"> <title>Unit test configuration</title> @@ -40,4 +40,54 @@ ]]></programlisting> </example> + + <para> + You should not <function>die</function> if no config file is found but + let the unit test continue gracefully - this is important in combined + suites, when several packages are unit tested in a row. + </para> + + <para> + Instead, you should check if it exists first: + </para> + + <example> + <title>Checking if the configuration file exists</title> + <programlisting role="php"><![CDATA[ +<?php +//... + +class My_Package_ClassTest extends PHPUnit_Framework_TestCase +{ + protected $configExists = null; + + //... + + public function __construct($name = null) + { + parent::__construct($name); + + $configFile = dirname(__FILE__) . '/config.php'; + $this->configExists = file_exists($configFile); + if ($this->configExists) { + include_once $configFile; + } + } + + //... + + public function setUp() + { + if (!$this->configExists) { + $this->markTestSkipped('Unit test configuration is missing.'); + } + //... + } + + //... +} +?> + ]]></programlisting> + </example> + </sect1> \ No newline at end of file

« previous php.pear.doc (#10766) next »