[TYPO3-dev] Unit tests and method visibility
Niels Pardon
mail at niels-pardon.de
Mon Jul 6 10:26:03 CEST 2009
Hi Francois!
Francois Suter schrieb:
> A question about the suggestion that the class extends the class to
> test: as far as I could see, current TYPO3 core test all extend
> tx_phpunit_testcase. Will my test still work if I extend some other
> class instead?
I think you got that wrong.
class tx_foo_Bar {
/**
* Roasts a duck.
*
* @return tx_foo_Duck a well-roasted duck
*/
protected function roastADuck() {
...
}
}
and then in tests/fixtures/:
class tx_foo_TestingBar extends tx_foo_Bar {
/**
* Roasts a duck.
*
* @return tx_foo_Duck a well-roasted duck
*/
public function roastADuck() {
return parent::roastADuck();
}
}
Then you create a testcase class in tests/ like this:
class tx_foo_TestingBar_testcase extends tx_phpunit_testcase {
/**
* @var tx_foo_TestingBar
*/
private $fixture;
public function setUp() {
$this->fixture = new tx_foo_TestingBar();
}
public function tearDown() {
unset($this->fixture);
}
/**
* @test
*/
public function roastADuckRoastsADuck() {
$this->assertEquals(
roastedDuck,
$this->fixture->roastADuck()
);
}
}
More information about the TYPO3-dev
mailing list