Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Tests @depends on Single Test & Data Consistency #1331

Closed
jonmchan opened this issue Jul 15, 2014 · 2 comments
Closed

Multiple Tests @depends on Single Test & Data Consistency #1331

jonmchan opened this issue Jul 15, 2014 · 2 comments

Comments

@jonmchan
Copy link

Hello,

I have the following:

<?php

class Container{
    protected $container;

    function __construct()
    {
        $this->container = array();
    }

    function add($key,$value)
    {
        $this->container[$key] = $value;
    }

    function remove($key)
    {
        unset($this->container[$key]);
    }

    function getContents()
    {
        return $this->container;
    }
}

class PhpunitTest extends \PHPUnit_Framework_TestCase {
    public function testInit()
    {
        $container = new Container();
        $this->assertEmpty($container->getContents());
        return $container;
    }

    /**
     * @depends testInit
     **/
    public function testAddFoo($container)
    {
        $container->add("foo","fool");
        $this->assertEquals(array("foo" =>"fool") , $container->getContents());
    }



    /**
     * @depends testInit
     **/
    public function testAddBar($container)
    {
        $container->add("bar","barstand");
        $this->assertEquals(array("bar" =>"barstand") , $container->getContents());
    }

}

The last test - testAddBar() fails because the $container variable is tainted with the values set from testAddFoo(). Shouldn't the correct behavior be that testAddBar and testAddFoo are isolated and only inherit the pristine $container variable from testInit() ?

Are 2 tests allowed to depend on a single test or are my expectations wrong on how to test with @Depends?

@whatthejeff
Copy link
Contributor

Two tests are indeed allowed to depend on a single test. At the moment the behavior is as you've identified (the same value is passed to each test). In the future we'd like to allow an option for cloning the same return value for each test and an option for rerunning the depended upon test for each test.

We actually already have an issue open for this #11 and a PR that I need to find time to revisit #1060.

@lattwood
Copy link

lattwood commented Dec 1, 2015

Hey @whatthejeff, still exists. :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants