ds19891231 2009-11-18 20:18
浏览 52
已采纳

如何在Zend Framework 1.8+中测试我的表单?

So I've set up testing in my ZF 1.9.5 application thanks to this tutorial, I am able to test my controllers, now I want to create a test for a form. However, I'm having the problem that PHPUnit can't find my form.

Fatal error: Class 'Default_Form_AccountProfile' not found

I'm extending PHPUnit_Framework_TestCase instead of Zend_Test_PHPUnit_ControllerTestCase since it is not a controller. Is that the right thing to do? Here is my test:

<?php

class AccountProfileTest extends PHPUnit_Framework_TestCase
{
    public function testPopulate()
    {
        $form = new Default_Form_AccountProfile();
        $user = array(
            'firstName' => 'Joe',
            'lastName' => 'Schmoe'
        );
        $form->populate($user);
        $this->assertEquals($form->getElement('firstName')->getValue(), 'Joe');
        $this->assertEquals($form->getElement('lastName')->getValue(), 'Schmoe');
    }
}

What am I doing wrong? What would be the correct way to test a form in Zend Framework?

  • 写回答

2条回答 默认 最新

  • douyi4912 2009-11-18 20:24
    关注

    The simplest solution to your problem is to 'require_once' the php file where your form is located at the beginning of this file (or before calling new Default_Form...).

    BTW, is there a specific reason why are you testing the default behavior of the Zend_Form? Tests for Zend_Form are already written and you can get them if you download the full version of ZF. If the form you are using has it's own, specific methods, or is overwriting some of the Zend_Forms methods than it makes sense to test those.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭