dimanche 10 février 2019

Feature testing Laravel Cashier w/stripe scoping issue?

At the beginning of my test I instantiate a factory user, and run various tests with it. At the end of the test I run my assertions which fail. However, if I reload the User and run the same assertions they pass.

Apologies for the rather crude example of this issue. For the purpose of illustrating the issue I've have added some debug to my test:

dump(get_class($this->user) . ' : ' . $this->user->currentPlan());
$reloadUser = \App\User::find($this->user->id);
dump(get_class($reloadUser) . ' : ' . $reloadUser->currentPlan());

the two dumps should be the same, but output is:

"App\User : "
"App\User : Professional Annual"

the method currentPlan():

    public function currentPlan()
    {
        if ($this->subscription('plan')) {
            $plan = Plan::where('stripe_id', $this->subscription('plan')->stripe_plan)->first();

            return $plan->nickname;
        }

        return false;
    }

I'm hoping that shows the problem, but please ask if anything isn't clear.

TIA

Aucun commentaire:

Enregistrer un commentaire