2012-02-25 11 views
0

私はYiiのThe Definitive Guideに例のような機能テストをしようとします。Yii functional testing

これはtbl_showcase.phpに私の治具である:

return array(
    'sample1'=>array(
     'title'=>'Welcome', 
     'content'=>'A main page test', 
     'row_type'=>1, 
    ), 
    'sample2'=>array(
     'title'=>'About', 
     'content'=>'An about page test', 
     'row_type'=>2, 
    ), 
); 

これは私のテストクラスである:

class ShowcaseTest extends WebTestCase 
{ 
    public $fixtures = array('showcase'=>'Showcase'); 

    public function testIndex() 
    { 
     $this->open('/'); 

     $this->assertTextPresent($this->showcase['sample1']['title']); 
     $this->assertTextPresent('Welcome'); 

     $this->assertTextPresent($this->showcase['sample1']['content']); 
     $this->assertTextPresent('A main page test'); 
    } 
} 

私はテスト

phpunit functional/ShowcaseTest.php 

を開始し、次のエラーが表示されます。

Time: 8 seconds, Memory: 6.25Mb 

There was 1 error: 

1) ShowcaseTest::testIndex 
Exception: Unknown property 'name' for class 'ShowcaseTest'. 

/home/myfolder/web/yii/framework/test/CWebTestCase.php:48 

FAILURES! 
Tests: 1, Assertions: 0, Errors: 1. 

答えて

1

あなたは明示的にそのように、ShowcaseTestクラスにnameプロパティを与えることによって、それを回避することができます:

public $fixtures = array('showcase'=>'Showcase'); 
public $name = 'Something Meaningful'; 

またはプロパティが定義されている場合、ファイル自体備品に見えます。

+0

私はYiiで初心者です。 「ShowcaseTestクラスに明示的に名前プロパティを与える」についてもう少し詳しくお聞かせください。可能であれば、コード例を表示してください。私はロシア人とウクライナ人と話すことができます。 – starter

+0

「名前」プロパティは何か分かりません。名前は誰ですか? – starter

+0

テストインフラストラクチャはテストクラスの名前プロパティに依存しますが、手動でプロパティを割り当てない限り、何らかの方法で定義したクラスにはそのクラスがありません。このプロパティの値は実際には関係ありません。 – raina77ow