我有一個創建了一個簡單doctrine2/Zend的骨架項目,我試圖讓單元測試與Zend Studio的工作。無法獲得的Zend Studio和PHPUnit的共同努力
測試工作完全通過PHPUnit的CLI,但我不能讓他們在Zend Studio的工作。
它有錯誤出現說:「沒有考試被執行」,並在調試窗口中下面的輸出:
X-Powered-By: PHP/5.2.14 ZendServer/5.0
Set-Cookie: ZendDebuggerCookie=127.0.0.1%3A10137%3A0||084|77742D65|1016; path=/
Content-type: text/html
<br />
<b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/var/www/z2d2/tests/application/models/UserModelTest.php</b> on line <b>8</b><br />
<br />
<b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/var/www/z2d2/tests/application/models/UserModelTest.php</b> on line <b>8</b><br />
<br />
<b>Parse error</b>: syntax error, unexpected T_STRING in <b>/var/www/z2d2/tests/application/models/UserModelTest.php</b> on line <b>8</b><br />
測試如下:
<?php
require_once 'Zend/Application.php';
require_once 'Zend/Test/PHPUnit/ControllerTestCase.php';
abstract class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
public function setUp()
{
$this->bootstrap = new Zend_Application(
'testing',
APPLICATION_PATH . '/configs/application.ini'
);
parent::setUp();
}
public function tearDown()
{
parent::tearDown();
}
}
<?php
class IndexControllerTest extends ControllerTestCase
{
public function testDoesHomePageExist()
{
$this->dispatch('/');
$this->assertController('index');
$this->assertAction('index');
}
}
<?php
class ModelTestCase extends PHPUnit_Framework_TestCase
{
protected $em;
public function setUp()
{
$application = new Zend_Application(
'testing',
APPLICATION_PATH . '/configs/application.ini'
);
$bootstrap = $application->bootstrap()->getBootstrap();
$this->em = $bootstrap->getResource('entityManager');
parent::setUp();
}
public function tearDown()
{
parent::tearDown();
}
}
<?php
class UserModelTest extends ModelTestCase
{
public function testCanInstantiateUser()
{
$this->assertInstanceOf('\Entities\User', new \Entities\User);
}
public function testCanSaveAndRetrieveUser()
{
$user = new \Entities\User;
$user->setFirstname('wjgilmore-test');
$user->setemail('[email protected]');
$user->setpassword('jason');
$user->setAddress1('calle san antonio');
$user->setAddress2('albayzin');
$user->setSurname('testman');
$user->setConfirmed(TRUE);
$this->em->persist($user);
$this->em->flush();
$user = $this->em->getRepository('Entities\User')->findOneByFirstname('wjgilmore-test');
$this->assertEquals('wjgilmore-test', $user->getFirstname());
}
public function testCanDeleteUser()
{
$user = new \Entities\User;
$user = $this->em->getRepository('Entities\User')->findOneByFirstname('wjgilmore-test');
$this->em->remove($user);
$this->em->flush();
}
}
和自舉:
<?php
define('BASE_PATH', realpath(dirname(__FILE__) . '/../../'));
define('APPLICATION_PATH', BASE_PATH . '/application');
set_include_path(
'.'
. PATH_SEPARATOR . BASE_PATH . '/library'
. PATH_SEPARATOR . get_include_path()
);
require_once 'controllers/ControllerTestCase.php';
require_once 'models/ModelTestCase.php';
以下是在將PHP可執行文件設置爲5.3之後出現的新錯誤:Gordon建議:
X-Powered-By: PHP/5.3.3 ZendServer/5.0
Set-Cookie: ZendDebuggerCookie=127.0.0.1%3A10137%3A0||084|77742D65|1000; path=/
Content-type: text/html
<br />
<b>Fatal error</b>: Class 'ModelTestCase' not found in <b>/var/www/z2d2/tests/application/models/UserModelTest.php</b> on line <b>4</b><br />
鑑於它說,在/var/www/z2d2/tests/application/models/UserModelTest.php意外T_STRING看到這個文件會更有趣。 – Gordon
對不起,我不確定你的意思。 – dimbo
'警告:在輸入字符意外: '\'(ASCII = 92)狀態= 1 ...'看起來像PHP 5.3的代碼與PHP 5.2 – edorian