Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Jun 25, 2024
1 parent 0e1ebb4 commit 907ae27
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
php: '7.4'
- laravel: '9.*'
php: '7.4'
- laravel: '9.*'
dependency-version: 'prefer-lowest'
- laravel: '8.*'
dependency-version: 'prefer-lowest'

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
},
"require-dev": {
"gajus/dindent": "^2.0",
"laravel/pint": "^1.16",
"orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^9.3 || ^10"
"phpunit/phpunit": "^9.3 || ^10.0"
},
"autoload": {
"psr-4": {
Expand All @@ -57,6 +58,7 @@
}
},
"scripts": {
"fix": "@php vendor/bin/pint",
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
}
Expand Down
2 changes: 1 addition & 1 deletion src/Unavatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use JsonSerializable;
use Symfony\Component\HttpFoundation\Response;

class Unavatar extends BaseUnavatar implements Renderable, Responsable, Htmlable, Jsonable, JsonSerializable, Arrayable
class Unavatar extends BaseUnavatar implements Arrayable, Htmlable, Jsonable, JsonSerializable, Renderable, Responsable
{
public static function make(string $identifier, ?string $provider = null): self
{
Expand Down
2 changes: 2 additions & 0 deletions src/View/Components/Img.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
class Img extends Component
{
public string $identifier;

protected ?string $provider = null;

protected ?string $fallback = null;

public function __construct(
Expand Down
42 changes: 21 additions & 21 deletions tests/UnavatarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,84 @@ public function it_is_renderable(): void
{
$unavatar = Unavatar::github('Gummibeer');

static::assertArrayHasKey(Renderable::class, class_implements($unavatar));
static::assertSame('<img alt="Gummibeer&#039;s github avatar" src="https://unavatar.io/github/Gummibeer" />', $unavatar->render());
self::assertArrayHasKey(Renderable::class, class_implements($unavatar));
self::assertSame('<img alt="'.htmlspecialchars('Gummibeer\'s github avatar').'" src="https://unavatar.io/github/Gummibeer" />', $unavatar->render());
}

/** @test */
public function it_is_htmlable(): void
{
$unavatar = Unavatar::github('Gummibeer');

static::assertArrayHasKey(Htmlable::class, class_implements($unavatar));
static::assertSame('<img alt="Gummibeer&#039;s github avatar" src="https://unavatar.io/github/Gummibeer" />', $unavatar->toHtml());
self::assertArrayHasKey(Htmlable::class, class_implements($unavatar));
self::assertSame('<img alt="'.htmlspecialchars('Gummibeer\'s github avatar').'" src="https://unavatar.io/github/Gummibeer" />', $unavatar->toHtml());
}

/** @test */
public function it_is_responsable_redirect(): void
{
$unavatar = Unavatar::github('Gummibeer');

static::assertArrayHasKey(Responsable::class, class_implements($unavatar));
self::assertArrayHasKey(Responsable::class, class_implements($unavatar));

$redirect = $unavatar->toResponse(Request::createFromGlobals());

static::assertInstanceOf(RedirectResponse::class, $redirect);
static::assertSame('https://unavatar.io/github/Gummibeer', $redirect->getTargetUrl());
self::assertInstanceOf(RedirectResponse::class, $redirect);
self::assertSame('https://unavatar.io/github/Gummibeer', $redirect->getTargetUrl());
}

/** @test */
public function it_is_responsable_json(): void
{
$unavatar = Unavatar::github('Gummibeer');

static::assertArrayHasKey(Responsable::class, class_implements($unavatar));
self::assertArrayHasKey(Responsable::class, class_implements($unavatar));

$request = Request::createFromGlobals();
$request->headers->set('X-Requested-With', 'XMLHttpRequest');
$response = $unavatar->toResponse($request);

static::assertInstanceOf(JsonResponse::class, $response);
self::assertInstanceOf(JsonResponse::class, $response);
$data = $response->getData(true);
static::assertIsArray($data);
static::assertArrayHasKey('url', $data);
self::assertIsArray($data);
self::assertArrayHasKey('url', $data);
}

/** @test */
public function it_is_jsonable(): void
{
$unavatar = Unavatar::github('Gummibeer');

static::assertArrayHasKey(Jsonable::class, class_implements($unavatar));
self::assertArrayHasKey(Jsonable::class, class_implements($unavatar));

$data = $unavatar->toJson();
static::assertJson($data);
self::assertJson($data);
$data = json_decode($data, true);
static::assertIsArray($data);
static::assertArrayHasKey('url', $data);
self::assertIsArray($data);
self::assertArrayHasKey('url', $data);
}

/** @test */
public function it_is_arrayable(): void
{
$unavatar = Unavatar::github('Gummibeer');

static::assertArrayHasKey(Arrayable::class, class_implements($unavatar));
self::assertArrayHasKey(Arrayable::class, class_implements($unavatar));

$data = $unavatar->toArray();
static::assertIsArray($data);
static::assertArrayHasKey('url', $data);
self::assertIsArray($data);
self::assertArrayHasKey('url', $data);
}

/** @test */
public function it_is_arrayable_with_fallback(): void
{
$unavatar = Unavatar::github('Gummibeer')->fallback('https://example.com/avatar.jpg');

static::assertArrayHasKey(Arrayable::class, class_implements($unavatar));
self::assertArrayHasKey(Arrayable::class, class_implements($unavatar));

$data = $unavatar->toArray();
static::assertIsArray($data);
static::assertArrayHasKey('url', $data);
self::assertIsArray($data);
self::assertArrayHasKey('url', $data);
}
}

0 comments on commit 907ae27

Please sign in to comment.