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

Dependency hierarchy branches affect eachother #1057

Closed
RSSchermer opened this issue Nov 19, 2013 · 1 comment
Closed

Dependency hierarchy branches affect eachother #1057

RSSchermer opened this issue Nov 19, 2013 · 1 comment

Comments

@RSSchermer
Copy link

I may be doing something wrong or maybe I'm missing something. This is a very simplified version of the type of class I'm trying to test:

class SomeStack
{
    private $items = array();

    public function addItem($item)
    {
        $this->items[] = $item;
    }

    public function getItems()
    {
        return $this->items;
    }
}

And the test:

class SomeStackTest extends \PHPUnit_Framework_TestCase
{
    public function testStackInitiallyEmpty()
    {
        $stack = new SomeStack();

        $this->assertEmpty($stack->getItems());

        return $stack;
    }

    /**
     * @depends testStackInitiallyEmpty
     */
    public function testAddItem($stack)
    {
        $stack->addItem('SomeItem');

        $this->assertNotEmpty($stack->getItems());
    }

    /**
     * @depends testStackInitiallyEmpty
     */
    public function testSomethingElseThatWantsAnEmptyStack($stack)
    {
        $this->assertEmpty($stack->getItems()); // Fails
    }
}

In the example there's two different 'dependency hierarchy branches'. I was expecting to receive an empty stack in testSomethingElseThatWantsAnEmptyStack, but instead it seems that the earlier branch affected the state of the stack. Is this intended behavior? Am i doing something wrong? Is this a known limitation that is unfortunately a necessary evil for performance reasons? (I think the dependency would need to be rerun for every branch?)

There are workarounds of course, but they don't seem as elegant as having multiple tests that depend on the same 'parent' test.

@whatthejeff
Copy link
Contributor

Thanks for the bug report, @RSSchermer. Unfortunately, this is a known issue. See #11 and #1060 for further discussions.

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

Successfully merging a pull request may close this issue.

2 participants