orchestral / testbench

Laravel Testing Helper for Packages Development
https://packages.tools/testbench
MIT License
2.1k stars 136 forks source link

Add `LARAVEL_START` #386

Closed bilogic closed 10 months ago

bilogic commented 10 months ago

Hi!

My commands rely on LARAVEL_START so that I can constantly keep an eye out for performance issues. Can also define it so that my code don't have to work around it? I can PR.

Thank you!

crynobone commented 10 months ago

what 's the use case?

bilogic commented 10 months ago
  1. My custom artisan commands always show the amount of time taken from LARAVEL_START until exit, so that all developers are exposed to this simple performance metric constantly.

  2. One of the command is a overridden version of migrate:fresh which is executed during our CI/CD and because it cannot find LARAVEL_START, the test fails.

  3. I suppose define('LARAVEL_START', microtime(true)); at the start of testbench's first PHP file would have minimal impact, right?

crynobone commented 10 months ago

Feel free to submit the PR to https://github.com/orchestral/testbench-core/blob/0b7de82296358c3013fe0a3d1128cbb6dc33f801/src/Console/Commander.php#L97 and target branch 6.x

bilogic commented 10 months ago

I added define('LARAVEL_START', microtime(true)); at your location, but it did not solve my problem.

Eventually, I fixed it by adding define('LARAVEL_START', microtime(true)); at these locations

For Laravel projects

https://github.com/laravel/framework/blob/c6aeffded35c10ac60b14d4cff4b6c45dc57e9ea/src/Illuminate/Foundation/Testing/TestCase.php#L85

For Laravel packages

The equivalent in testbench-core would be https://github.com/orchestral/testbench-core/blob/158e2f483bccab28f36d6170a551641534813886/src/TestCase.php#L48

Or is there a better place to define LARAVEL_START?