Teodor Talov
Teodor Talov

Reputation: 1943

Zend Studio and PHPUnit getting started problems

I am trying to create my first unit test. I use Zend Studio, and I have added the phpUnit library to my project by going to:

Project -> Properties -> Add Library

When I run it as PHP Unit Test I get the following error:

Unable to run a PHPUnit session. Only PHPUNIT classes can be run as PHPUnit tests. Reason: Not tests found in IndexControllerTest.php

IndexControllerTest.php:

<?php
require_once 'application\controllers\IndexController.php';
require_once 'PHPUnit\Framework\TestCase.php';
/**
 * IndexController test case.
 */
class IndexControllerTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var IndexController
     */
    private $IndexController;
    /**
     * Prepares the environment before running a test.
     */
    protected function setUp ()
    {
        parent::setUp();
        // TODO Auto-generated IndexControllerTest::setUp()
        $this->IndexController = new IndexController(/* parameters */);
    }
    /**
     * Cleans up the environment after running a test.
     */
    protected function tearDown ()
    {
        // TODO Auto-generated IndexControllerTest::tearDown()
        $this->IndexController = null;
        parent::tearDown();
    }
    /**
     * Constructs the test case.
     */
    public function __construct ()
    {
        // TODO Auto-generated constructor
    }
    /**
     * Tests IndexController->init()
     */
    public function testInit ()
    {
        // TODO Auto-generated IndexControllerTest->testInit()
        $this->markTestIncomplete("init test not implemented");
        $this->IndexController->init(/* parameters */);
    }
    /**
     * Tests IndexController->indexAction()
     */
    public function testIndexAction ()
    {
        // TODO Auto-generated IndexControllerTest->testIndexAction()
        $this->markTestIncomplete("indexAction test not implemented");
        $this->IndexController->indexAction(/* parameters */);
    }
}

How do I fix that?

Upvotes: 2

Views: 4176

Answers (1)

David Harkness
David Harkness

Reputation: 36562

You must remove the test case's __construct() method. PHPUnit passes parameters to the constructor so you must either pass them along to parent::__construct() or--more likely--remove the constructor entirely.

Also, if you are using Zend Framework and testing Zend_Controller_Action classes, you may want to consider using Zend_Test_PHPUnit_ControllerTestCase as it provides a lot of scaffolding for you. Note that each test will go from a route straight through to the rendered content which might not be fine-grained enough for your needs. It wasn't for ours so I created base test case classes for controllers and views separately.

Upvotes: 3

Related Questions