gpt4 book ai didi

php - Yii 装置 --- 异常 : Unknown property 'projects' for class 'ProjectTest'

转载 作者:搜寻专家 更新时间:2023-10-31 21:40:31 24 4
gpt4 key购买 nike

我正在阅读“使用 yii 1.1 和 php5 进行敏捷 Web 应用程序开发”一书,并且正在使用固定装置进行测试部分。我遵循了他们的代码,但我无法访问灯具...

我正在用 phpunit 运行我的测试,它返回给我这个

c:\wamp\www\agileBook\protected\tests>phpunit unit/ProjectTest.php
PHPUnit 3.6.11 by Sebastian Bergmann.

Configuration read from C:\wamp\www\agileBook\protected\tests\phpunit.xml

←[31;1mE←[0m

Time: 0 seconds, Memory: 5.75Mb

There was 1 error:

1) ProjectTest::testRead
Exception: Unknown property 'projects' for class 'ProjectTest'.

C:\wamp\yii\framework\test\CDbTestCase.php:63
C:\wamp\www\agileBook\protected\tests\unit\ProjectTest.php:11
C:\wamp\bin\php\php5.3.13\phpunit:46

←[37;41m←[2KFAILURES!
←[0m←[37;41m←[2KTests: 1, Assertions: 0, Errors: 1.
←[0m←[2K

我怎样才能让它发挥作用?

感谢您的帮助

我的夹具: C:\wamp\www\agileBook\protected\tests\fixtures\tbl_project.php

<?php 

return array(

'project1' => array(
'name' => 'Test Project 1',
'description' =>'This is test project 1',
'create_time' =>'',
'create_user_id' =>'',
'update_time' =>'',
'update_user_id' =>'',
),
'project2' => array(
'name' => 'Test Project 2',
'description' =>'This is test project 2',
'create_time' =>'',
'create_user_id' =>'',
'update_time' =>'',
'update_user_id' =>'',
),

),

?>

我的项目测试类: C:\wamp\www\agileBook\protected\tests\unit\ProjectTest.php

我将 $this->projects('project1')(从书中)更改为 $this->projects['project1'],因为我在论坛帖子中看到 projects 是一个数组而不是一个方法。

<?php

class ProjectTest extends CDbTestCase{

public $fixture = array('projects'=>'Project');

public function testRead(){
// READ the new project
$receivedProject = $this->projects['project1'];
$this->assertTrue($receivedProject instanceof Project);
$this->assertEquals($receivedProject->name,'Test Project 1');

}

}

?>

我的测试配置: C:\wamp\www\agileBook\protected\config\test.php

<?php

return CMap::mergeArray(
require(dirname(__FILE__).'/main.php'),
array(
'components'=>array(
'fixture'=>array(
'class'=>'system.test.CDbFixtureManager',
),
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=trackstar_test',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
),
)
);

最佳答案

如前所述,$fixture必须更正为$fixtures,

我只是想对此发表评论:

I changed $this->projects('project1') (from the book) for $this->projects['project1'], cause i see in a forum post that projects is an array and not a method.

如果你这样做,上面的测试将会失败。 Yii 文档中的原因:

    // return all rows in the 'Comment' fixture table
$comments = $this->comments;
// return the row whose alias is 'sample1' in the `Post` fixture table
$post = $this->posts['sample1'];
// return the AR instance representing the 'sample1' fixture data row
$post = $this->posts('sample1');

http://www.yiiframework.com/doc/guide/1.1/en/test.unit

关于php - Yii 装置 --- 异常 : Unknown property 'projects' for class 'ProjectTest' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11712109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com