setUp and tearDown the Repository Test

The Repository Test needs some specific settings (like the configuration and some test fixtures). They are setup by the – wow – setUp() method (nomen est omen) and all settings are taken back by the tearDown() method. If you overwrite these methods, don’t forget to call the parent’s methods as well in case that the parent class wants to setup and restore some test stuff as well.

I start with the phpunit test framework to setup test data in the database. Afterwards I set the extension’s configuration like described before. In the end I retrieve an instance of the repository class that is to be tested. In the tearDown() method I just do all of this in the opposite way:

protected function setUp() {
    $this->testingFramework = new Tx_Phpunit_Framework('tx_csevents');
    $this->appointmentRepository = $this->objectManager->get(Tx_Csevents_Domain_Repository_AppointmentRepository);

protected function tearDown() {

Now everything is ready to create test data in the database, run tests on the repository and check, if all configuration mappings work properly.

Leave a Reply