Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Telescope does not record requests coming from TestCase

For debugging purpose, I would like to have Telescope record any requests coming from Testing suite. Telescope does not at the moment and I have no ideas why.

I enabled telescope in phpunit.xml

<env name="TELESCOPE_ENABLED" value="true"/>

This is my Feature Test

$this->getJson('/api/vehicle')->assertStatus(401);

When I opened the Telescope, there is no entry for /api/vehicle saved.

like image 266
Michael Nguyen Avatar asked Oct 15 '25 02:10

Michael Nguyen


1 Answers

I need to always force Telescope to record in TelescopeServiceProvider

class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        // Telescope::night();

        Telescope::filter(function (IncomingEntry $entry) {
            if ($this->app->environment('local')) {
                return true;
            }

            if ($this->app->environment('testing')) {
                return true;
            }

            return $entry->isReportableException() ||
                   $entry->isFailedJob() ||
                   $entry->isScheduledTask() ||
                   $entry->hasMonitoredTag();
        });
    }

And since the telescope frontend is linked to development-database, the telescope entries recorded during testing are saved in testing-database, that explain when I refresh the Telescope front-end (which use development-database), nothing was shown.

like image 116
Michael Nguyen Avatar answered Oct 17 '25 12:10

Michael Nguyen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!