Remember to submit save or generally finalize data entry

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

Last Updated: 2024-11-21

This is a (perhaps idiosyncratic) mistake that's tripped me up on late nights - I would sometimes fill out fields/data objects then go onwards without properly submitting or saving.

E.g. in an integration test for registration, this failed

<? php
$browser->visit("register")
  ->type("email", $test_email)
  ->type("password", $test_password)
  ->type("password_confirmation", $test_password)
  ->assertAuthenticated()

Why? Because I never clicked the submit button at the bottom of the login form. Duh!

<? php
  ..
  ->type("password_confirmation", $test_password)
  ->click("Submit")
  ->assertAuthenticated()
  // Now it passes

Or in a controller, you might assign all the relevant data:

<? php
  $advisor->fill(data);
  redirectTo("/overview")

But then not see the saved record on the next page - because you did not save. The fix:

<? php
  $advisor->fill(data);
  // This call to `save` is needed
  $advisor->save(data);
  redirectTo("/overview")
// Now it works

Third instance: In another integration test, with Google Maps autocomplete, I told the test to type in the first few characters and press the DOWN key to select the right one. But I never told it to press "enter" to actually submit that entry.

Lesson

Think about finalization steps when working with browser tests or data.