[Solved]Yii's Fixture Can't Use with setUp() and tearDown()


class SalesTest extends CDbTestCase {


	private $object;

	public $fixtures = array('stock' => 'Stock', 'sales'=>'Sales');

	protected function setUp() {

		$this->object = new Sales;

	}

	

	protected function tearDown() {

		unset($this->object);

	}


public function testTransact_Normal_ReturnEquals() {

		//set

		$model = $this->sales('sales1');

		$stock =$this->stock('stok2');

		

		//act

		$model->transact();

		

		//assert

		$this->assertEquals(90, $stock->qty);

	}



I got this error:

SalesTest::testTransact_Normal_ReturnEquals()

Exception: Unknown method ‘sales’ for class ‘SalesTest’.

If I remove setUp() and tearDown() no error, but I really do hope can put setUp() and tearDown().

So what is the workaround to use fixtures and setUp()/tearDown() ?

try calling parent::setUp() in your setUp method…




protected function setUp()

{

    parent::setUp();

    $this->object = new Sales

}



wow, it’s work! Thanks wk :)

Lol 2 hours of searching and I find this topic AFTER I figured this out :P Ohh well, I can truthfully say I’ve learned the material now ;)