Codeception / Codeception/module-laravel
The Issue with Null $wrap Property in resource API Calls
- Vorherrschende Sprache
- PHP
- Sterne
- 6
- Forks
- 13
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I have two APIs that when I call the first one, it returns a specific resource as shown below:
```php
class FirstResource extends JsonResource
{
public function toArray($request)
{
self::withoutWrapping();
return [
....
];
}
}
```
And the second API returns a resource as shown below:
```php
class SecondResource extends JsonResource
{
public function toArray($request)
{
return [
....
];
}
}
```
JsonResource code (Laravel source code):
```php
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?
Beitragsleitfaden
Rechercherichtung
Beginne damit, die Interaktion zwischen FirstResource und SecondResource nachzustellen, wobei der Fokus auf JsonResource::$wrap und dem Aufruf von withoutWrapping() in FirstResource::toArray() liegt. Untersuche den Lebenszyklus des Laravel-Moduls und führe den fehlschlagenden Test aus; die Arbeit ist abgeschlossen, wenn das erwartete Wrapper-Verhalten über separate API-Aufrufe hinweg konsistent ist oder die Einschränkung des Lebenszyklus klar dokumentiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- laravel, php
- Bereich
- backend, testing
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 30/100