nothingworksinc / ticketbeast

Back to the lesson videos:
https://course.testdrivenlaravel.com/lessons
552 stars 11 forks source link

When i call payment gateway charge method, it always returns null when calling assert on Charge class methods #76

Closed 4mation closed 6 years ago

4mation commented 6 years ago

Hi There

I was currently doing lesson 83 - Promoting Charges to Objects (https://github.com/nothingworksinc/ticketbeast/commit/6e983c593c9d698544f21e359ec32863d546526b)

I was testing this test in PaymentGatewayContractTests

    /** @test */
    public function can_get_details_about_a_successful_charge()
    {

        $paymentGateway = $this->getPaymentGateway();

        $charge = $paymentGateway->charge(2500, $paymentGateway->getValidTestToken('0000000000004242'));
        //dd($charge);
        //$this->assertInstanceOf('App\Billing\Charge', $charge);
        $this->assertEquals('4242', $charge->cardLastFour());
        $this->assertEquals(2500, $charge->amount());
    }

However when I test, I get

There was 1 error:

1) StripePaymentGatewayTest::can_get_details_about_a_successful_charge
Error: Call to a member function cardLastFour() on null

The weird thing is before or after this test, if I do

dd($charge->cardLastFour())

It prints out 4242 which is correct.

Does anyone know why this issue is happening for me?

adamwathan commented 6 years ago

Can you push your repo up to GitHub so I can check it out? Happy to try and help troubleshoot!

kskrlin commented 6 years ago

Have you tried with $charge->fresh() ...?

4mation commented 6 years ago

My repo for the code is up here https://github.com/andytan2624/ticketbeast

Thanks for helping btw 👍

liefie commented 6 years ago

@4mation the dd() call is dumping the output from the FakePaymentGateway version of the test, not the failing test.

Adam's codebase doesn't test the StripeGateway on that commit. You'll notice the charge method isn't returning anything (hence the null)

look at the phpunit.xml file. You're missing this section:

    <groups>
        <exclude>
          <group>integration</group>
        </exclude>
    </groups>
4mation commented 6 years ago

Thank you @liefie that was the issue. Problem fixed now, thanks everyone for helping out