Skip to content

The Issue with Null $wrap Property in resource API Calls #49

@daalvand

Description

@daalvand

I have two APIs that when I call the first one, it returns a specific resource as shown below:

class FirstResource extends JsonResource
{
    public function toArray($request)
    {
        self::withoutWrapping();
        return [
            ....
        ];
    }
}

And the second API returns a resource as shown below:

class SecondResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            ....
        ];
    }
}

JsonResource code (Laravel source code):

class JsonResource implements ArrayAccess, JsonSerializable, Responsable, UrlRoutable
{
    /**
     * The "data" wrapper that should be applied.
     *
     * @var string|null
     */
    public static $wrap = 'data';
    //...
}

The problem is that when these calls are made, the $wrap property in the second resource becomes null, even though its value should be equal to 'data', causing the test to fail.

Actually, the first resource affects the second resource on separate APIs!!!

Why it happens ?

I think Laravel-module makes just one instance of the app for all tests, so this conflict happens, am I right?

It can be fixed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy