Codeception / Codeception/module-rest

Is it possible to type-check the root?

Aperta
#14 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
PHP
Stelle
60
Fork
30
Merge medio
22h 37m
PR unite (30g)
1

Descrizione

My main intent is to make sure the response contains the number of elements I expect.

My current flow is to grab the json_decoded response and use PHPUnit asserts for that... but it seems suboptimal.
Then I decided to see the JsonType checker, but even by adding a custom filter (for array/string length) it doesn't really help as I can't type-check the actual root as an array - just its entries.

Unfortunately, the API I'm testing doesn't have a root key (i.e. `$.data`), the list is directly returned (e.g. `[ { user_id: x }, { user_id: y } ]`).

I see I can't use the JsonType matcher by design, and changing that could be a breaking change, or an extra argument... Doesn't seem the best?
I wonder if this is such an edge case that I should only care to write something on my own, or if I could submit a PR of something like `seeJsonResponseLengthIs(int $number)`. It would check the response is an indexed array, and then count it.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia leggendo il verificatore JsonType e le asserzioni esistenti per le risposte REST. Definisci l’entry point proposto seeJsonResponseLengthIs(int $number) attorno a una risposta con un array indicizzato alla radice, quindi aggiungi la coverage che dimostri che valida il numero di elementi della risposta e rifiuta le radici che non sono array indicizzati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
php
Ambito
api, testing-qa
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.