Vin*_*opi 6 phpunit unit-testing cakephp cakephp-1.3
我一直在寻找帮助我将PHPUnit与CakePHP集成的教程.希望使用Selenium测试,所以更喜欢PHPUnit.
我一直在尝试按照http://cakebaker.42dh.com/2006/03/22/selenium/上的教程,但似乎无法让它工作.有什么好的教程吗?
谢谢!
这相对容易.我从作曲家安装中使用cake 1.3.这就是我的composer.json的样子:
{
"config": {
"vendor-dir": "vendors/composer"
},
"require": {
"phpunit/phpunit": "3.7.*",
"cakephp/cakephp-1.3": "1.3",
},
"repositories": [
{
"type": "package",
"package": {
"name": "cakephp/cakephp-1.3",
"version": "1.3",
"source": {
"url": "https://github.com/cakephp/cakephp.git",
"type": "git",
"reference": "1.3"
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后在tests目录中的phpunit bootstrap.php文件:
<?php
include('../vendors/composer/autoload.php');
include('../webroot/index.php');
Run Code Online (Sandbox Code Playgroud)
这是phpunit.xml表单相同的目录:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="bootstrap.php"
backupStaticAttributes="false"
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
testSuiteLoaderClass="PHPUnit_Runner_StandardTestSuiteLoader"
strict="false"
verbose="false"
>
<testsuites>
<testsuite name="AllTests">
<directory>.</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php"></directory>
<file></file>
<exclude>
<directory suffix=".php"></directory>
<file></file>
</exclude>
</blacklist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php"></directory>
<file></file>
<exclude>
<directory suffix=".php"></directory>
<file></file>
</exclude>
</whitelist>
</filter>
</phpunit>
Run Code Online (Sandbox Code Playgroud)
不要忘记在测试设置中加载应用程序类.你可以用cakephp的方式做到这一点.例如,如果您的控制器名为calendar,则calendarTest.php可能如下所示:
<?php
/**
* Class ComponentsCommonTest
* @property calendarController $calendarController
*/
class CalendarTest extends PHPUnit_Framework_TestCase
{
/**
* @var calendarController $calendarController
*/
private $calendarController;
function setUp()
{
App::import('Core', array('View', 'Controller', 'Model', 'Router'));
App::import('Controller', 'Calendar');
$this->calendarController =& new CalendarController();
$this->calendarController->constructClasses();
$this->calendarController->layout = null;
}
}
Run Code Online (Sandbox Code Playgroud)
对于模型,供应商类等也是如此.对我来说很棒.
不幸的是,CakePHP 的设计目的不是与 PHPUnit 一起工作。CakePHP 已改用SimpleTest,您将有两种选择之一:重构您的测试以使用 SimpleTest 或修改核心以使用 PHPUnit。
然而,应该指出的是,Mark Story 已经声明 CakePHP 2.0 将使用 PHPUnit作为其测试框架,因此,如果您能等到那时,这可能会是最好的选择。
归档时间: |
|
查看次数: |
2528 次 |
最近记录: |