zend framework单元测试

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/h058/article/details/2682937

 zend 的效率问题一项使人迷惑,但从单元测试的页面看出来,zend关注了大量的细节
<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    UnitTests
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: TestHelper.php 8064 2008-02-16 10:58:39Z thomas $
 */

require_once &apos;PHPUnit/Framework.php&apos;;
require_once &apos;PHPUnit/Framework/IncompleteTestError.php&apos;;
require_once &apos;PHPUnit/Framework/TestCase.php&apos;;
require_once &apos;PHPUnit/Framework/TestSuite.php&apos;;
require_once &apos;PHPUnit/Runner/Version.php&apos;;
require_once &apos;PHPUnit/TextUI/TestRunner.php&apos;;
require_once &apos;PHPUnit/Util/Filter.php&apos;;

/*
 * Set error reporting to the level to which Zend Framework code must comply.
 */
error_reporting( E_ALL | E_STRICT );

/*
 * Determine the root, library, and tests directories of the framework
 * distribution.
 */
$zfRoot        = dirname(dirname(__FILE__));
$zfCoreLibrary = $zfRoot . DIRECTORY_SEPARATOR . &apos;library&apos;;
$zfCoreTests   = $zfRoot . DIRECTORY_SEPARATOR . &apos;tests&apos;;

/*
 * Prepend the Zend Framework library/ and tests/ directories to the
 * include_path. This allows the tests to run out of the box and helps prevent
 * loading other copies of the framework code and tests that would supersede
 * this copy.
 */
$path = array(
    $zfCoreLibrary,
    $zfCoreTests,
    get_include_path()
    );
set_include_path(implode(PATH_SEPARATOR, $path));

/*
 * Load the user-defined test configuration file, if it exists; otherwise, load
 * the default configuration.
 */
if (is_readable($zfCoreTests . DIRECTORY_SEPARATOR . &apos;TestConfiguration.php&apos;)) {
    require_once $zfCoreTests . DIRECTORY_SEPARATOR . &apos;TestConfiguration.php&apos;;
} else {
    require_once $zfCoreTests . DIRECTORY_SEPARATOR . &apos;TestConfiguration.php.dist&apos;;
}

/*
 * Add Zend Framework library/ directory to the PHPUnit code coverage
 * whitelist. This has the effect that only production code source files appear
 * in the code coverage report and that all production code source files, even
 * those that are not covered by a test yet, are processed.
 */
if (defined(&apos;TESTS_GENERATE_REPORT&apos;) && TESTS_GENERATE_REPORT === true &&
    version_compare(PHPUnit_Runner_Version::id(), &apos;3.1.6&apos;, &apos;>=&apos;)) {
    PHPUnit_Util_Filter::addDirectoryToWhitelist($zfCoreLibrary);
}

/*
 * Unset global variables that are no longer needed.
 */
unset($zfRoot, $zfCoreLibrary, $zfCoreTests, $path);

 
这么长一段代码,唯有最后一句是个亮点,曾几何时,我写代码的时候也是这么注重效率,但现在由于使用大量的类还有函数,那么这些垃圾变量都会自动回收

展开阅读全文

没有更多推荐了,返回首页