Giter Club home page Giter Club logo

Comments (8)

rpungello avatar rpungello commented on June 4, 2024 1

@driesvints noted, thanks for the info. I'll settle for just mocking the call to driver() that Horizon ends up calling, as so far that doesn't seem to have any negative repercussions.

from horizon.

driesvints avatar driesvints commented on June 4, 2024

You're doing cache faking here: https://github.com/rpungello/laravel-test/blob/master/tests/Feature/ExampleTest.php#L16-L19

This doesn't work when installing Horizon because it needs to resolve the cache driver upon initialisation through its service provider. Since you only added one expectation to the cache faking, this fails.

from horizon.

rpungello avatar rpungello commented on June 4, 2024

@driesvints is this documented somewhere? I followed the official Laravel docs for mocking facades, which explicitly show the method for mocking the Cache facade I used: https://laravel.com/docs/11.x/mocking#mocking-facades

from horizon.

driesvints avatar driesvints commented on June 4, 2024

@rpungello I want to check something real quickly with you. Does it work if you replace:

            $this->app->bind(Console\WorkCommand::class, function ($app) {
                return new Console\WorkCommand($app['queue.worker'], $app['cache.store']);
            });

With

        if ($this->app->runningInConsole()) {
            $this->app->bind(Console\WorkCommand::class, function ($app) {
                return new Console\WorkCommand($app['queue.worker'], $app['cache.store']);
            });
        }

In the HorizonServiceProvider?

from horizon.

rpungello avatar rpungello commented on June 4, 2024

@driesvints it doesn't, though that at least gives me some info on where to look. Commenting out that section and preventing registerCommands() from running during boot() does solve the issue, but obviously that can't be done unilaterally without breaking Horizon.

Your suggestion of using runningInConsole() lead me to the runningUnitTests() function of $this->app, but regrettably that returns false during the initialization of Horizon (despite returning true while actually running the example test).

It does seem possible to work around the issue by adding an expectation that driver() be called on the cache facade, but it's unclear if that could result in other issues if there's a scenario where Horizon doesn't end up calling that function.

from horizon.

rpungello avatar rpungello commented on June 4, 2024

Looking at this a little closer, within HorizonServiceProvider::registerCommands(), changing
if ($this->app->runningInConsole()) {
to
if ($this->app->runningInConsole() && !$this->app->runningUnitTests()) {
Does resolve the issue. I was mistaken previously that runningUnitTests() returned false, that was for the standard ExampleTest Laravel ships with, but for my test feature test it does return true.

What I don't know is whether this could realistically be modified without breaking something else.

from horizon.

driesvints avatar driesvints commented on June 4, 2024

@rpungello let's try it: #1410

from horizon.

driesvints avatar driesvints commented on June 4, 2024

Unfortunately it doesn't seems possible since we need some of these commands themselves in our own test suite. I'm sorry @rpungello but it seems these two just aren't compatible right now.

from horizon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.