Chinnu
Chinnu

Reputation: 304

Phpunit setup function calling multiple times while executing the test

Setup function call multiple time. I need to execute only once. I am new to the phpunit.can anyone give the solution for this.I need to execute 4 tests in this file and i need to use the same variable name

class XSCBookModelTest extends TestCase
{
    public $categoryID;
    public $categoryName = "Motivations";
    public $parentID = 0;

    protected function setUp()
    { 
        $this->XSCBooksModelObj = new XSCBooksModel();

        $categoryObjModel = new XSCCategoryModel();

        $this->categoryID = $categoryObjModel->AddCategory($this->categoryName, $this->parentID);
        $this->setup = 0;

        $this->assertNotEquals($this->categoryID, 0);
    }

Upvotes: 2

Views: 696

Answers (1)

Sebastian Bergmann
Sebastian Bergmann

Reputation: 8326

setUp() is supposed to be called once before each test method, see the documentation for details.

Upvotes: 1

Related Questions