Zend Framework: how to run PHPUnit to test forms?

I am having problems so that my filters / validators work correctly in my form, so I want to create a Unit test to verify that the data that I submit to my form is filtered and validated correctly.

I started by auto-generating the PHPUnit test in Zend Studio, which gives me the following:

<?php
require_once 'PHPUnit/Framework/TestCase.php';

/**
 * Form_Event test case.
 */
class Form_EventTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var Form_Event
     */
    private $Form_Event;
    /**
     * Prepares the environment before running a test.
     */
    protected function setUp ()
    {
        parent::setUp();
        // TODO Auto-generated Form_EventTest::setUp()
        $this->Form_Event = new Form_Event(/* parameters */);
    }
    /**
     * Cleans up the environment after running a test.
     */
    protected function tearDown ()
    {
        // TODO Auto-generated Form_EventTest::tearDown()
        $this->Form_Event = null;
        parent::tearDown();
    }
    /**
     * Constructs the test case.
     */
    public function __construct ()
    {    // TODO Auto-generated constructor
    }
    /**
     * Tests Form_Event->init()
     */
    public function testInit ()
    {
        // TODO Auto-generated Form_EventTest->testInit()
        $this->markTestIncomplete(
        "init test not implemented");
        $this->Form_Event->init(/* parameters */);
    }
    /**
     * Tests Form_Event->getFormattedMessages()
     */
    public function testGetFormattedMessages ()
    {
        // TODO Auto-generated Form_EventTest->testGetFormattedMessages()
        $this->markTestIncomplete(
        "getFormattedMessages test not implemented");
        $this->Form_Event->getFormattedMessages(/* parameters */);
    }
}

so I open the terminal, go to the directory and try to run the test:

$ cd my_app/tests/unit/application/forms
$ phpunit EventTest.php

Fatal error: Class 'Form_Event' not found in .../tests/unit/application/forms/EventTest.php on line 19

, require_once , Form . , . . , , .. Zend_Form. ? , , , . ?

+3
1

Zend Framework Unittests. "XML" Config PHPUnit, Bootstrap, , .

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="TestConfig.php">
    <testsuite name="XY">
        <directory>./</directory>
    </testsuite>
</phpunit>

TestConfig.php AutoLoader config.ini , .

$includeConfig = parse_ini_file(TEST_PATH . '/config/config.ini', true);

set_include_path(
    implode(PATH_SEPARATOR, $includeConfig['includes'])
    . PATH_SEPARATOR
    . TEST_PATH . PATH_SEPARATOR
    . get_include_path()
);
unset($includeConfig);

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('App_');

, Zend Framework PHPUNIT PHPUnit + Zend Framework

+3

Source: https://habr.com/ru/post/1750378/


All Articles