Codeception / Codeception/module-rest
Is it possible to type-check the root?
- Vorherrschende Sprache
- PHP
- Sterne
- 60
- Forks
- 30
- Ø Merge
- 22 Std. 37 Min.
- Gemergte PRs (30 T.)
- 1
Beschreibung
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.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginnen Sie mit dem Lesen des JsonType-Prüfers und der vorhandenen Assertions für REST-Antworten. Definieren Sie den vorgeschlagenen Einstiegspunkt seeJsonResponseLengthIs(int $number) für eine Antwort mit einem indizierten Array als Wurzel und fügen Sie Abdeckung hinzu, die zeigt, dass er die Anzahl der Antwort-Elemente validiert und Wurzeln ablehnt, die keine indizierten Arrays sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- php
- Bereich
- api, testing-qa
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100