Issue

ZF-4496: Zend_Test_PHPUnit_ControllerTestCase breaks data provider tests

Issue Type: Bug Created: 2008-10-06T05:34:45.000+0000 Last Updated: 2009-11-24T02:28:19.000+0000 Status: Resolved Fix version(s): Reporter: Bradley Holt (bradley.holt) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Test_PHPUnit

Related issues: Attachments:

Description

Data provider tests do not work within test cases that extend Zend_Test_PHPUnit_ControllerTestCase. In other test cases extending PHPUnit_Framework_TestCase directly, data providers seem to work fine. Here is a test within the CourseControllerTest class which extends Zend_Test_PHPUnit_ControllerTestCase:

/**
 * @dataProvider seedCourses
 * @param string $id
 */
public function testShowActionWithGetMethodAndIdParameterShouldContainCourseData($id)
{
    $this->getRequest()->setMethod('GET');
    $this->dispatch('/course/show/' . $id . '/');
    $this->assertResponseCode(200);
}

And the data provider (also within the CourseControllerTest class):

/**
 * @return array
 */
public static function seedCourses()
{
    return array(
        '1'          => array('1'),
        '65535'      => array('FFFF'),
    );
}

I expect the following when I run the test with "phpunit --testdox":

CourseController [x] Show action with get method and id parameter should contain course data with data set "1" [x] Show action with get method and id parameter should contain course data with data set "65535"

But instead I get:

CourseController [] Show action with get method and id parameter should contain course data

If I run without "--testdox" I see the following error message:

Missing argument 1 for CourseControllerTest::testShowActionWithGetMethodAndIdParameterShouldContainCourseData()

It appears that something within Zend_Test_PHPUnit_ControllerTestCase is preventing data provider tests from working correctly and this is just being seen as a "regular" test.

Comments

Posted by Bradley Holt (bradley.holt) on 2008-10-12T10:07:57.000+0000

I removed my constructor and now data driven tests work correctly. My constructor did have a call to parent::__construct() so I'm not sure why this makes a difference.

Posted by Matthew Weier O'Phinney (matthew) on 2008-11-07T12:00:13.000+0000

I just tried the following:

<pre class="highlight">
    /**
     * @dataProvider provider
     */
    public function testIteration($id)
    {
        $url = '/index/index/id/' . $id;
        $this->dispatch($url);
        $this->assertEquals($id, $this->request->getParam('id'));
    }

    public function provider()
    {
        return array(
            array(1),
            array(2),
            array(3),
        );
    }

and it worked as expected.

Posted by Bradley Holt (bradley.holt) on 2008-11-07T13:37:39.000+0000

Try adding a constructor and it should break:

<pre class="highlight">
    public function __construct()
    {
        parent::__construct(); 
    }

Posted by Matthew Weier O'Phinney (matthew) on 2008-11-09T12:27:54.000+0000

I just tested, and what you say is true. However, it's also true of any TestCase extending PHPUnit_Framework_TestCase -- I verified this by writing the following:

<pre class="highlight">
<?php
class FooTest extends PHPUnit_Framework_TestCase
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @dataProvider provider
     */
    public function testProvider($id)
    {
        $this->assertNotNull($id);
    }

    public function provider()
    {
        return array(
            array(1),
            array(2),
            array(3),
        );
    }
}
?>

This results in the same error -- "Missing argument 1 for FooTest::testProvider()".

I'm filing a report upstream to the PHPUnit project.

Posted by Matthew Weier O'Phinney (matthew) on 2008-11-09T12:39:14.000+0000

A ticket already exists for it: http://www.phpunit.de/ticket/602

I re-opened the ticket, which was closed for PHPUnit 3.3.4, after verifying that the code still does not work as expected. Please track the PHPUnit ticket for updates, as this is an upstream issue, and not a ZF issue.

Posted by Tim Brayshaw (twisty) on 2009-11-24T02:28:18.000+0000

Also see http://www.phpunit.de/ticket/824, which has disabled the functionality to print the data set information.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2019 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts