2011-11-15 38 views
1

我有一个创建了一个简单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 /> 
+0

鉴于它说,在/var/www/z2d2/tests/application/models/UserModelTest.php意外T_STRING看到这个文件会更有趣。 – Gordon

+0

对不起,我不确定你的意思。 – dimbo

+2

'警告:在输入字符意外: '\'(ASCII = 92)状态= 1 ...'看起来像PHP 5.3的代码与PHP 5.2 – edorian

回答

0

的第一个问题是,IDE设置为使用PHP 5.2,但鳕鱼是PHP 5.3。

Unexpected character in input: '\' (ASCII=92) state=1 

通常会提示该问题。

固定,其他错误是一类不能被找到之后。那是因为PHP找不到所需的类。很可能Zend Framework自动加载器没有按照它的设置。

如果这种情况发生在测试时请确保您的phpunit.xml包含<phpunit bootstrap="yourApplicationBootstrap.php" ...条目,其中磁带自动加载机进行初始化。

如何工作出在ZF文档,并没有什么记录PHPUnit的工作可以为你:)

+0

谢谢。为什么PHPunit可以在Zend Studio之外正常工作?我想我已经按照你的建议设置了它:我的phpunit.xml指向我的phpunit bootstrap,它需要缺少的ModelTestCase。我在这里错过了非常基本的东西吗? – dimbo

+0

@dimbo如果Zend Studio确实关心phpunit配置文件,我不知道。我可以看到并解决的问题是PHP版本,但是您可能想要打开另一个问题或在Zend Forums中寻找额外问题..也许您需要在Zend Studio配置中再次指定引导文件?对不起,我只能帮你让PHPUnit运行,而不是详细的IDE,因为我不关心它,并且不使用它:) – edorian

+0

谢谢edorian和Gordon。你是对的,最初的问题解决了。我会再提出一个问题:引导问题。 – dimbo