laravel-paymongo icon indicating copy to clipboard operation
laravel-paymongo copied to clipboard

Laravel Testing Mocking

Open eskiesirius opened this issue 3 years ago • 0 comments

How to mock this function?

 Paymongo::source()->create([
            'type' => 'gcash',
            'amount' => 100,
            'currency' => 'PHP',
            'redirect' => [
                'success' => 'http://localhost/success',
                'failed' => 'http://localhost/failed'
            ]
        ])

in my test file

Paymongo::shouldReceive('source')
            ->shouldReceive('create')
            ->andReturn(json_decode('
            {
                "data": {
                    "id": "gg",
                    "type": "source",
                    "attributes": {
                        "amount": 10000,
                        "billing": null,
                        "currency": "PHP",
                        "description": null,
                        "livemode": false,
                        "redirect": {
                            "checkout_url": "https://test-sources.paymongo.com/sources?id=gg",
                            "failed": "http://localhost/failed",
                            "success": "http://localhost/success"
                            },
                        "statement_descriptor": null,
                        "status": "pending",
                        "type": "gcash",
                        "created_at": 1648140991,
                        "updated_at": 1648140991
                    }
                }
            }',true));

but i got this error Call to a member function create() on null

eskiesirius avatar Mar 24 '22 17:03 eskiesirius