#Mocking is Down for Maintenance

4 messages · Page 1 of 1 (latest)

vital furnace
#

Hello Guys!

I'm trying to to simulate (on my tests) the application in production as follows and it's working perfectly:

// it works
$this->app->detectEnvironment(function () {
         return 'staging';
});

In another scenario, you would need to test the application under maintenance. I used the same strategy but it doesn't work.

// does not work
$this->app->isDownForMaintenance(function () {
         return true;
});

Could someone give me a light?

still hawk
#

Sounds like kind of an XY problem, why are you retesting features that are already covered by Laravel's own tests? Then you're retesting the framework.

Either way, I don't think there's any mocking capabilities built-in, so you'd probably want to make it use the cache driver in tests, along with a cache driver that wouldn't be shared (such as the array driver, so it'll be gone after tests). Then you could use something like $this->app->make(MaintenanceMode::class)->activate()

vital furnace
#

It is to test the message displayed on the screen when the application is not in production and when it is in maintenance (in this case, if the user accesses the application via the endpoint that allows access, even when in maintenance).

still hawk
#

Yeah, but like I mentioned, those tests are already performed by the framework. Maybe just test if the middleware is present