fromYaml($yaml)->getServerRequestValidator(); $psrRequest = (new ServerRequest('post', 'http://localhost:8000/api/v1/products.create')) ->withHeader('Content-Type', 'application/json') ->withBody( stream_for( json_encode( [ 'body' => [ 'username' => 'scaytrase', 'notEmail' => 'notEmail', ], ] ) ) ); try { $validator->validate($psrRequest); self::fail('Should throw an exception'); } catch (InvalidBody $exception) { /** @var KeywordMismatch $previous */ $previous = $exception->getPrevious(); self::assertInstanceOf(KeywordMismatch::class, $previous); self::assertEquals(['body', 'email'], $previous->dataBreadCrumb()->buildChain()); } } }