Skip to content

Commit

Permalink
Merge pull request #13 from worksome/feature/graphql-convertable-tests
Browse files Browse the repository at this point in the history
tests: add tests for GraphQLConvertable concern
  • Loading branch information
owenvoke authored Oct 22, 2024
2 parents da4dae2 + c826ca8 commit 1bf52cf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/Definition/Concerns/GraphQLConvertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Jawira\CaseConverter\Convert;
use UnitEnum;

/**
* @mixin UnitEnum
*/
/** @mixin UnitEnum */
trait GraphQLConvertable
{
public function toGraphQLValue(): string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Worksome\GraphQLHelpers\Tests\Unit\Definition\Concerns\GraphQLConvertable;

use GraphQL\Type\Definition\Description;
use Worksome\GraphQLHelpers\Definition\Concerns\GraphQLConvertable;

#[Description('Dummy enum description')]
enum DummyEnum
{
use GraphQLConvertable;

#[Description('PascalCase description')]
case PascalCase;
#[Description('SCREAMING_SNAKE_CASE description')]
case SCREAMING_SNAKE_CASE; // phpcs:ignore
#[Description('snake_case description')]
case snake_case; // phpcs:ignore
}

it('can convert an enum to the correct case for GraphQL', function (DummyEnum $enum, string $graphQLValue) {
expect($enum->toGraphQLValue())->toBe($graphQLValue);
})->with([
[DummyEnum::PascalCase, 'PASCAL_CASE'],
[DummyEnum::SCREAMING_SNAKE_CASE, 'SCREAMING_SNAKE_CASE'],
[DummyEnum::snake_case, 'SNAKE_CASE'],
]);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Worksome\GraphQLHelpers\Tests;
namespace Worksome\GraphQLHelpers\Tests\Unit\Definition;

use GraphQL\Type\Definition\Description;
use GraphQL\Type\Definition\EnumValueDefinition;
Expand Down

0 comments on commit 1bf52cf

Please sign in to comment.