Skip to content

feat(laravel): update the Laravel tooling with an updated Tinker command that...

Rick Hambrook requested to merge feat/enhanced-tinker into main

Updated the lando tinker command so that when you run it with files specified (lando tinker replay-file1.php replay-file2.php`) then it will list those files and provide a summary of any newly declared variables.

Useful during development to load back up a "state" after restarting Tinker.

Screenshot_2024-04-02_at_4.07.30_PM

I have used this extensively with projects that require loading various pieces of information during testing. Declaring closures is also very useful to trigger specific actions or test different logic.

I have grown to call these "replay files". But that's just me.

If desired, we could add especially useful files to the repos.

Notes

  • The --execute flag will prevent any files from being included at all, this is a Tinker thing
  • Is designed to not be installed into each project, but it's available in any Laravel project if needed
  • It will not detect or hide secrets if you define them

Future

It would be nice to be able to trigger the summary list again from within Tinker, but every attempt at this has been messy and requires basically running dump_summary(get_defined_vars()) as I cannot find a way to access get_defined_vars() out of context if run from a small helper function.

Testing

  • Select a project with a database and records
  • Update your lando cdplugins repo
  • Rebuild your web project
  • Create some test files in your project root, eg as per the example files below
  • Feel free to add different kinds of variables and let me know any that fail
  • Load tinker using lando tinker <yourFile>, specifying as many files as you want
  • Expect to:
    • see a list of the files you specified, in order, and de-duplicated (Tinker only includes each file ones)
    • see a list of variables you defined in your files, along with a semi-useful type, and more useful summary
    • get placed into the interactive shell of Tinker, with access to your variables

Sample test files

replay-test1.php

<?php
$numberic1 = 1;
$numeric2 = 0.1;
$model = \App\Models\User::first();
$object1 = (object) ['name' => 'value', 'property' => 'value2'];
$collection = collect([1, 2, 3, 4, 5]);
$funcA = fn()=>true;
$funcB = fn()=>true;

replay-test2.php

<?php
$foo = 'bar';
$long = 'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong';
$bin = ['name' => 'value', 'property' => 'value2'];
Edited by Rick Hambrook

Merge request reports