Mocking Models OutSide of Laravel

Posted: 2017-08-24 00:43:39

This all comes down to me using

With this in place I can work on an external library as if it is in Laravel.

The one place I ran into trouble on though was mocking model related methods like all for example a model Foo being called as \App\Foo::all() was hard to mock cause all is stacic:

    public static function all($columns = ['*'])
        return (new static)->newQuery()->get(
            is_array($columns) ? $columns : func_get_args()

But once I did this to my test:

    public function testGetWithNoResults()
        $mock = \Mockery::mock("alias:AlfredNutileInc\LaravelFeatureFlags\FeatureFlag");

        App::instance(FeatureFlag::class, $mock);

        $fjs = new FeatureFlagsForJavascript();


It was mocked!