Mockery executing original method

Posted 1 month ago by bwrigley

I'm struggling to understand why this isn't working as I'm sure I've had it working before.

In my feature test:

$product =  factory(Product::class)->create(['name' => 'Test', 'stripe_id' => 'Test']);
$plan =  factory(Plan::class)->create(['stripe_id' => 'Test', 'product_id' => $product->id]);

$mockPlan = Mockery::mock(Plan::class);
$this->app->instance(Plan::class, $mockPlan);
$mockPlan->shouldReceive('testMethod')
    ->andReturn('mock executed');

$subscriptionDetails = [
    'plan' => $plan->nickname,
    'stripeToken' => 'randomTokenString',
];

$this->fromUrl('/dashboard')
    ->post('/subscription/create', $subscriptionDetails)
    ->assertRedirect('/dashboard');

in my Plan class:

public function testMethod()
{
    return 'original method executed';
}

in a class that is executed during the test:

    $plan = Plan::whereNickname($request->plan)->first();

    dump($plan->testMethod());

the output is always: "original method executed"

I'm sure I'm missing something obvious, but can't see anything in the Laravel or Mockery docs that show to do anything different.

Thanks for your help in advance!

Please sign in or create an account to participate in this conversation.