Remove comments when pasting then modifying code

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the workflows category.

Last Updated: 2024-04-24

I had the following test

<?php
public function testWhenSomeLocationsHaveSlotsAndSomeDont() {
    $user = factory(User::class)->create();
    // We create one in Hamburg but not in Berlin, the city where the search
    // query will target. The reason we add an extra city is to test for accidental false positives.
    $stationLocation = factory(StationLocation::class)
        ->states("hamburg", "with_slots_next_hour")
        ->create();
    $endpointForBerlinQuery = "/api/v1/slots/covid19-test/germany/10967?maxDistanceKm=50";
    $response =
        $this->withApiToken($user)
             ->getJson($endpointForBerlinQuery);

    $response
        ->assertStatus(200)
        ->assertExactJson([]);

The comment under $user made sense in this initial testing context.

Later I wanted to re-use the setup lines of this test so I copied and pasted the lot. I included the comment without thinking about it. But it turns out, the comment was confusing and unnecessary in this new context:

<?php
    public function testNonGeocodableAddress()
    {
        $user = factory(User::class)->create();
        // We create one in Hamburg but not in Berlin, the city where the search
        // query will target. The reason we add an extra city is to test for accidental false positives.
        $stationLocation = factory(StationLocation::class)
            ->states("berlin-charite")->create();
        $slot = factory(Slot::class)->create([
            "start_time" => now()->subtract("1 month"),
            "station_location_id" => $stationLocation
        ]);
        $bogusPostcode = "a7asd98uASD";
        $endpointForBerlinQuery = "/api/v1/slots/covid19-test/germany/" . $bogusPostcode . "?maxDistanceKm=50";

        $response =
            $this->withApiToken($user)
                 ->getJson($endpointForBerlinQuery);

        $response
            ->assertStatus(200)
            ->assertExactJson([]);
    }
}

Lesson

When copying and pasting code, you probably want to remove the comments, or at least review them.