Closed Noogic closed 6 years ago
Update for those still experiencing this issue, if you commonly run
config:cache
while developing, the suggested solution of addingTELESCOPE_ENABLED=false
tophpunit.xml
will only actually work if you runoptimize:clear
.I commonly run
config:cache
during dev, should cached config take precedence overphpunit.xml
? Is this something that can be checked when running tests? Not sure if this the intended behavior @taylorotwell @themsaid ?
this fixed it for me
Update for those still experiencing this issue, if you commonly run
config:cache
while developing, the suggested solution of addingTELESCOPE_ENABLED=false
tophpunit.xml
will only actually work if you runoptimize:clear
. I commonly runconfig:cache
during dev, should cached config take precedence overphpunit.xml
? Is this something that can be checked when running tests? Not sure if this the intended behavior @taylorotwell @themsaid ?this fixed it for me
+1
People have suggested disabling Telescope in testing environments to resolve this issue, but that was not really an answer for me since I like to use Telescope to debug my failing tests.
I found out that commenting out the default Telescope::filter
function in the TelescopeServiceProvider
resolved the issue, but not being able to use the filter is not ideal either. I decided to grab the environment earlier on and pass it through to the callback.
// Disable the filter while in local or testing environment.
$disableFilter = $this->app->environment(['local', 'testing']);
Telescope::filter(function (IncomingEntry $entry) use ($disableFilter) {
if ($disableFilter) {
return true;
}
return $entry->isReportableException() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
Same case with @DiederikvandenB , I would like to use Telescope in the test and found same root cause. The different is, I use App
Facades to determinate the environment because that use $this->app()
trigger same error: ReflectionException: Class env does not exist
.
if ($this->app->isLocal() || $this->app->runningUnitTests())
if ($this->app->environment(['local', 'testing']))
It may caused by the $this['env']
is not defined when the environment is testing \Illuminate\Foundation\Application::isLocal
:
public function isLocal()
{
return $this['env'] === 'local';
}
In short, the \App\Providers\TelescopeServiceProvider::register
as changed below:
public function register()
{
// Telescope::night();
$this->hideSensitiveRequestDetails();
Telescope::filter(function (IncomingEntry $entry) {
if (App::environment(['local', 'testing'])) {
return true;
}
return $entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
}
To add to @gordonhung 's workaround:
You need to add the Use for the facade, which is this: (it always takes me a bit of time to find these):
use Illuminate\Support\Facades\App
And I also needed to add it to the hideSensitiveRequestDetails
method:
\App\Providers\TelescopeServiceProvider::hideSensitiveRequestDetails
I'm not sure why this is closed. This issue is still present.
@gordonhung's workaround works for great for me:
if (App::environment(['local', 'testing'])) {
Or as I like to do, replace the two instances in app/Providers/TelescopeServiceProvider.php
:
if ($this->app->isLocal()
to:
if (app()->environment(['local', 'testing'])) {
Why this issue is closed? That error still exists.
I confirm, still have the issue
Open a new issue. Likely not seeing it.
Open a new issue. Likely not seeing it.
If possible, it's better to reopen this one.
@Noogic could you reopen this issue?
I add TELESCOPE_ENABLED=false to my testing environment file and it's work fine. Thanks
I did the same and It worked like charm!
We are seeing this when using Dusk and Telescope, but only when a Dusk test utilizes the setUp()
method.
Disabling Telescope in phpunit.xml
didn't seem to work.
Removing App\Providers\TelescopeServiceProvider.php
from config/app.php
worked.
Still seeing this issue on Laravel 7.20.0
, Telescope 3.5.0
and Dusk v6.4.1
.
I can run each test separately just fine, but php artisan dusk
fails with Class env does not exist
.
I have added <server name="TELESCOPE_ENABLED" value="false"/>
in the correct place in the phpunit.xml
file, run optimize:clear
and config:cache
, and I'm still getting this issue.
@christopherarter did you try running config:clear
?
It sounds like you ran optimize:clear
and then config:cache
which would negate the effect of running optimize:clear
?
Hope this helps 🙂
@WyattCast44 unfortunately not. Still having this issue.
It's basically not recognizing the values in the phpunit.xml
file for any tests beyond the first one.
However, if anyone is still having this problem after trying the answers above, though this is not a fix, I ended up just putting TELESCOPE_ENABLED=false
in my .env.dusk.local
file and it's working.
Not using dusk, added <env name="TELESCOPE_ENABLED" value="false"/>
to phpunit.xml
and everything seems to be working fine for me.
You can change the default to false for telescope by updating your config/telescope.php
file.
/*
|--------------------------------------------------------------------------
| Telescope Master Switch
|--------------------------------------------------------------------------
|
| This option may be used to disable all Telescope watchers regardless
| of their individual configuration, which simply provides a single
| and convenient way to enable or disable Telescope data storage.
|
*/
'enabled' => env('TELESCOPE_ENABLED', false), // Change from true to false here.
You will then have to set: TELESCOPE_ENABLED=true
in your .env file. This will ensure that you don't have it accidentally turned on in environments you don't want such as production and unit testing.
Recently upgraded to Laravel 8 from Laravel 7, I just started experiencing this issue. I am running PHP 7.4.
After some debugging, I found that PHPUnit will ignore false
as a value, but if you type any other value it picks it up, there seems to be something odd with how the config loads the false
value. Not sure if this is an issue with PHP Unit or if it's an issue with Laravel. it also only happens with <server
but if you use <env
per @shanerbaner82 it will work fine as well.
Editing file phpunit.xml
This will not work
<server name="TELESCOPE_ENABLED" value="false"/>
But if you update it to this, it will work
<server name="TELESCOPE_ENABLED" value="0"/>
Recently upgraded to Laravel 8 from Laravel 7, I just started experiencing this issue. I am running PHP 7.4.
After some debugging, I found that PHPUnit will ignore
false
as a value, but if you type any other value it picks it up, there seems to be something odd with how the config loads thefalse
value. Not sure if this is an issue with PHP Unit or if it's an issue with Laravel. it also only happens with<server
but if you use<env
per @shanerbaner82 it will work fine as well.Editing file
phpunit.xml
This will not work
<server name="TELESCOPE_ENABLED" value="false"/>
But if you update it to this, it will work
<server name="TELESCOPE_ENABLED" value="0"/>
You saved my day! Same problem on Laravel 8. After this change I've also had to clear config cache using php artisan config:clear
Recently upgraded to Laravel 8 from Laravel 7, I just started experiencing this issue. I am running PHP 7.4.
After some debugging, I found that PHPUnit will ignore
false
as a value, but if you type any other value it picks it up, there seems to be something odd with how the config loads thefalse
value. Not sure if this is an issue with PHP Unit or if it's an issue with Laravel. it also only happens with<server
but if you use<env
per @shanerbaner82 it will work fine as well.Editing file
phpunit.xml
This will not work
<server name="TELESCOPE_ENABLED" value="false"/>
But if you update it to this, it will work
<server name="TELESCOPE_ENABLED" value="0"/>
I was just having the same issue after upgrading to Laravel 8 and this is the only thing that fixed it. Thank you.
Sometimes, you might need to run composer dump-autoload
.
This error still actual.
after TELESCOPE_ENABLED=false
the php artisan test
command is worked, but it's not the way to handle this issue.
I need a real solution to work at the same time with each functionality. Because after TELESCOPE_ENABLED = false
command telescope does not work. And it's too much time every time turn on / turn off.
Also, as an alternative, just changing this
'enabled' => env('TELESCOPE_ENABLED', true),
to
'enabled' => env('TELESCOPE_ENABLED', config('app.env')!=='testing'),
in your telescope config file solves it too. As telescope will only be activated when the env is changed to testing by phpunitxml.
Same here. It'd really be nice to see telescope entries for my dusk testcases. +1
Just ran into this issue. Wanted to use telescope with dusk as well. Fix for me was to use config()->get('app.env')
instead of $this->app->environment()
in the TelescopeServiceProvider.php filter.
Telescope::filter(function (IncomingEntry $entry) {
if (in_array(config()->get('app.env'), ['local', 'testing'])) {
return true;
}
return $entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag() ||
$entry->isSlowQuery();
});
After installing Telescope, all my Dusk tests are throwing this error:
The only "test" that is passing is the login test.
I'm using laravel version v5.7.12 and phpunit tests are working well, only dusk is failing.