json-parser/tests/Feature/SourcesTest.php
2023-02-25 20:46:41 +10:00

19 lines
780 B
PHP

<?php
use Cerbero\JsonParser\Dataset;
use Cerbero\JsonParser\Exceptions\GuzzleRequiredException;
use Cerbero\JsonParser\Exceptions\UnsupportedSourceException;
use Cerbero\JsonParser\JsonParser;
use Cerbero\JsonParser\Sources\Source;
it('throws an exception when a JSON source is not supported', function () {
expect(fn () => JsonParser::parse(123)->traverse())
->toThrow(UnsupportedSourceException::class, 'Unable to load JSON from the provided source');
});
it('throws an exception when Guzzle is required but not installed', function (Source $source) {
expect(fn () => JsonParser::parse($source)->traverse())
->toThrow(GuzzleRequiredException::class, 'Guzzle is required to load JSON from endpoints');
})->with(Dataset::forSourcesRequiringGuzzle());