Codeception / Codeception/module-laravel
The Issue with Null $wrap Property in resource API Calls
- Lingua principale
- PHP
- Stelle
- 6
- Fork
- 13
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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?
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia riproducendo l’interazione tra FirstResource e SecondResource, concentrandoti su JsonResource::$wrap e sulla chiamata a withoutWrapping() in FirstResource::toArray(). Ispeziona il ciclo di vita del modulo Laravel ed esegui il test fallito; il lavoro è completato quando il comportamento previsto del wrapper è coerente tra chiamate API separate oppure quando la limitazione del ciclo di vita è documentata chiaramente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- laravel, php
- Ambito
- backend, testing
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 30/100