Integrated icon indicating copy to clipboard operation
Integrated copied to clipboard

using POST or PUT, is the data json_encoded and what headers are sent?

Open ryanwinchester opened this issue 10 years ago • 1 comments

My api accepts json and returns json...

When I was just using phpunit and Laravel's TestCase I would include the headers and json encoded data with $this->call().

Before Integrated (passing):

    protected $headers = [
        'CONTENT_TYPE' => 'application/json',
        'HTTP_ACCEPT'  => 'application/json',
    ];


    /** @test */
    public function it_adds_a_contact()
    {
        $data = [
            'email'  => '[email protected]',
            'attach' => [
                'tags'  => [1, 2, 3],
                'forms' => [2],
            ],
        ];
        $response = $this->call('POST', 'api/contacts', [], [], [], $this->headers, json_encode($data));
        $content = json_decode($response->getContent());
        $addedContact = SevenShores\Kraken\Contact::where('email', $data['email'])->first();
        $this->assertEquals(200, $response->getStatusCode());
        $this->assertEquals($data['email'], $content->email);
        $this->assertEquals(3, $addedContact->tags->count());
        $this->assertEquals(2, $addedContact->forms->first()->id);

Now with Integrated (failing):

    /** @test */
    public function it_adds_a_contact()
    {
        $data = [
            'email'  => '[email protected]',
            'attach' => [
                'tags'  => [1, 2, 3],
                'forms' => [2],
            ],
        ];

        $this->post('/api/contacts', $data)
             ->seeStatusCodeIs(200)
             ->seeJsonContains(['email' => '[email protected]'])
             ->seeInDatabase('contacts', $data);
    }

I am failing all my POST and PUT tests now, that I switched to laracasts/Integrated and just trying to figure out why.

ryanwinchester avatar Apr 21 '15 05:04 ryanwinchester

What error is coming back? No headers are sent by default.

Flambe avatar Apr 28 '15 14:04 Flambe