You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?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?
The text was updated successfully, but these errors were encountered:
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.
Hello,
I have the following:
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?
The text was updated successfully, but these errors were encountered: