Skip to content

Commit

Permalink
Extract better helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Apr 24, 2024
1 parent 5728b2b commit 7b9c9b9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tests/Unit/Support/GitHubReleaseDataTest.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
<?php

use Illuminate\Support\Arr;
use App\Commands\Internal\Support\GitHubReleaseData;
use App\Commands\Internal\Support\GitHubReleaseAsset;

it('creates a GitHubRelease object from JSON data', function () {
expect(new GitHubReleaseData(fixture('github-release-api-sample-response.json')))
expect(new GitHubReleaseData(getFixture()))
->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)
Expand All @@ -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');
}

0 comments on commit 7b9c9b9

Please sign in to comment.