【问题标题】:Laravel Telescope does not record requests coming from TestCaseLaravel Telescope 不记录来自 TestCase 的请求
【发布时间】:2019-10-03 04:03:30
【问题描述】:

出于调试目的,我想让 Telescope 记录来自测试套件的任何请求。望远镜目前没有,我不知道为什么。

我在phpunit.xml启用了望远镜

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

这是我的功能测试

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

当我打开望远镜时,没有保存/api/vehicle 的条目。

【问题讨论】:

  • dyrynda.com.au/blog/… 也许这就是你要找的?
  • 该链接告诉我如何在构建和测试环境中不包含 Telescope。默认情况下,望远镜应该可以在任何环境中工作,这就是我现在所处的位置。

标签: laravel laravel-testing


【解决方案1】:

我需要始终强制 Telescope 在 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();
        });
    }

由于望远镜前端链接到development-database,在testing期间记录的望远镜条目保存在testing-database中,这解释了当我刷新望远镜前端(使用development-database)时,什么都没有显示。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 2012-07-05
  • 1970-01-01
  • 2016-08-29
  • 1970-01-01
  • 2021-02-13
相关资源
最近更新 更多