diff --git a/tests/Unit/Support/GitHubReleaseDataTest.php b/tests/Unit/Support/GitHubReleaseDataTest.php index 275479ed..3a24a857 100644 --- a/tests/Unit/Support/GitHubReleaseDataTest.php +++ b/tests/Unit/Support/GitHubReleaseDataTest.php @@ -1,26 +1,27 @@ toBeInstanceOf(GitHubReleaseData::class); }); it('creates a GitHubReleaseAsset object from JSON data', function () { - expect(new GitHubReleaseAsset(fixture('github-release-api-sample-response.json')['assets'][0])) + expect(new GitHubReleaseAsset(getFixture('assets.0'))) ->toBeInstanceOf(GitHubReleaseAsset::class); }); it('constructs semver tag', function () { - $release = new GitHubReleaseData(fixture('github-release-api-sample-response.json')); + $release = new GitHubReleaseData(getFixture()); expect($release->tag)->toBe('v1.0.0'); }); it('constructs assets', function () { - $release = new GitHubReleaseData(fixture('github-release-api-sample-response.json')); + $release = new GitHubReleaseData(getFixture()); expect($release->assets) ->toHaveCount(1) @@ -37,13 +38,22 @@ })->throws(InvalidArgumentException::class); test('data class throws an exception when required field is missing', function () { - $data = fixture('github-release-api-sample-response.json'); + $data = getFixture(); array_shift($data); new GitHubReleaseData($data); })->throws(InvalidArgumentException::class); test('asset class throws an exception when required field is missing', function () { - $data = fixture('github-release-api-sample-response.json')['assets'][0]; + $data = getFixture('assets.0'); array_shift($data); new GitHubReleaseAsset($data); })->throws(InvalidArgumentException::class); + +function getFixture(?string $selector = null): array +{ + if ($selector !== null) { + return Arr::get(getFixture(), $selector); + } + + return fixture('github-release-api-sample-response.json'); +}