Change the Entity and Write it back to the Repository

When the read test was done successfully, doing the change/write test is simple:

public function canWriteChangedAppointmentToRepository() {
    $testId = 1511;
    $uid = $this->setupTestData($testId);
    $appointment = $this->appointmentRepository->findByUid($uid);
    $appointment->setInternalId('Changed internal id #' . $testId);
    $appointment = $this->appointmentRepository->findByUid($uid);
    $this->assertNotNull($appointment, 'Wasn\'t able to get back the changed data from the DB at all');
    $this->assertEquals('Changed internal id #' . $testId, $appointment->getInternalId(), 'Retrieved not the expected (changed) internal id from the DB.');

    $this->markTestIncomplete('Change more data?!');

Please note that in this case I don’t check, if the data is physically changed in the database. I just rely on the repository. If you want to test the database directly, just read on with the next post, which describes how to do this (using data deletion as an example).

Please also note line 12 where I mark the test as being “incomplete”. I was just struggling, if I should change more data of the entity object. This is (clearly on tests only) another way to mark some “to do-s” like I described in the “Refacoring – Avoiding the Frustration” post.

I read somewhere else in a testing blog that they use assertSame over assertEquals, because this checks the type to be the same as well. I’ll follow this recommendation and change my tests later on in this way.

Leave a Reply