1

I have a problem. Simple code

use PHPUnit\Framework\TestCase;

class StringTest extends TestCase
{
    protected $stack = '';

    public function testModify()
    {
        $this->stack .= 'modify';
        $this->assertEquals('modify', $this->stack);
    }

    public function testEmpty()
    {
        $this->assertEquals('', $this->stack);
    }

}

Why validation pass? Why in second test $this->stack doesn't has modifyvalue?

3
  • what do you want to achieve? Commented Jun 19, 2016 at 17:02
  • 2
    I started learning phpunit and this result surprised me ;) Commented Jun 19, 2016 at 17:36
  • Sure, you can write test that depends each other by the result of the first Commented Jun 19, 2016 at 17:59

1 Answer 1

2

Each test (each test method) is run in isolation (on a separate test object).

Sign up to request clarification or add additional context in comments.

2 Comments

I read about it. Is turning off process isolation great idea? I watched a few tutorials and programmers was setting it to false.
This is not process isolation, that would give you even more isolation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.