Skip to content

Commit

Permalink
Move tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed Jan 8, 2025
1 parent 1f9ba77 commit 42a31c9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion tests/BackedEnum.php → tests/Enums/BackedEnum.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Cerbero\Enum;
namespace Cerbero\Enum\Enums;

use Cerbero\Enum\Attributes\Meta;
use Cerbero\Enum\Concerns\Enumerates;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Cerbero\Enum;
namespace Cerbero\Enum\Enums;

use Cerbero\Enum\Attributes\Meta;
use Cerbero\Enum\Concerns\Enumerates;
Expand Down
2 changes: 1 addition & 1 deletion tests/PureEnum.php → tests/Enums/PureEnum.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Cerbero\Enum;
namespace Cerbero\Enum\Enums;

use Cerbero\Enum\Attributes\Meta;
use Cerbero\Enum\Concerns\Enumerates;
Expand Down
18 changes: 9 additions & 9 deletions tests/BackedEnumTest.php → tests/Unit/BackedEnumTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Cerbero\Enum\CasesCollection;
use Cerbero\Enum\BackedEnum;
use Cerbero\Enum\Enums\BackedEnum;
use Cerbero\Enum\Enums;
use Cerbero\Enum\PureEnum;
use Cerbero\Enum\Enums\PureEnum;
use Pest\Expectation;

it('determines whether the enum is pure')
Expand Down Expand Up @@ -299,8 +299,8 @@
]);

it('throws a value error when hydrating backed cases with a missing value', fn() => BackedEnum::from(4))
->throwsIf(version_compare(PHP_VERSION, '8.2') == -1, ValueError::class, '4 is not a valid backing value for enum "Cerbero\Enum\BackedEnum"')
->throwsIf(version_compare(PHP_VERSION, '8.2') >= 0, ValueError::class, '4 is not a valid backing value for enum Cerbero\Enum\BackedEnum');
->throwsIf(version_compare(PHP_VERSION, '8.2') == -1, ValueError::class, '4 is not a valid backing value for enum "Cerbero\Enum\Enums\BackedEnum"')
->throwsIf(version_compare(PHP_VERSION, '8.2') >= 0, ValueError::class, '4 is not a valid backing value for enum Cerbero\Enum\Enums\BackedEnum');

it('retrieves the case hydrated from a value or returns null')
->expect(fn(int $value, ?BackedEnum $case) => BackedEnum::tryFrom($value) === $case)
Expand All @@ -323,7 +323,7 @@
]);

it('throws a value error when hydrating backed cases with a missing name', fn() => BackedEnum::fromName('four'))
->throws(ValueError::class, '"four" is not a valid name for enum "Cerbero\Enum\BackedEnum"');
->throws(ValueError::class, '"four" is not a valid name for enum "Cerbero\Enum\Enums\BackedEnum"');

it('retrieves the case hydrated from a name or returns null')
->expect(fn(string $name, ?BackedEnum $case) => BackedEnum::tryFromName($name) === $case)
Expand Down Expand Up @@ -352,7 +352,7 @@
->toBe([BackedEnum::two]);

it('throws a value error when hydrating cases with an invalid meta', fn() => BackedEnum::fromMeta('color', 'orange'))
->throws(ValueError::class, 'Invalid value for the meta "color" for enum "Cerbero\Enum\BackedEnum"');
->throws(ValueError::class, 'Invalid value for the meta "color" for enum "Cerbero\Enum\Enums\BackedEnum"');

it('retrieves the case hydrated from a meta or returns null')
->expect(fn(string $meta, mixed $value, ?array $cases) => BackedEnum::tryFromMeta($meta, $value)?->all() === $cases)
Expand All @@ -375,7 +375,7 @@
->toBe(1);

it('fails handling the call to an invalid enum method', fn() => BackedEnum::four())
->throws(ValueError::class, '"four" is not a valid name for enum "Cerbero\Enum\BackedEnum"');
->throws(ValueError::class, '"four" is not a valid name for enum "Cerbero\Enum\Enums\BackedEnum"');

it('runs custom logic when calling an inaccessible enum method', function() {
Enums::onStaticCall(function(string $enum, string $name, array $arguments) {
Expand All @@ -392,7 +392,7 @@
});

it('handles the call to an inaccessible case method', fn() => BackedEnum::one->unknownMethod())
->throws(Error::class, 'The case Cerbero\Enum\BackedEnum::one has no "unknownMethod" meta set');
->throws(Error::class, 'The case Cerbero\Enum\Enums\BackedEnum::one has no "unknownMethod" meta set');

it('runs custom logic when calling an inaccessible case method', function() {
Enums::onCall(function(object $case, string $name, array $arguments) {
Expand Down Expand Up @@ -448,7 +448,7 @@
->toBe('red');

it('throws a value error when attempting to retrieve an invalid item', fn() => BackedEnum::one->resolveItem('invalid'))
->throws(ValueError::class, 'The case Cerbero\Enum\BackedEnum::one has no "invalid" meta set');
->throws(ValueError::class, 'The case Cerbero\Enum\Enums\BackedEnum::one has no "invalid" meta set');

it('retrieves the value of a backed case or the name of a pure case', function() {
expect(BackedEnum::one->value())->toBe(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Cerbero\Enum\BackedEnum;
use Cerbero\Enum\Enums\BackedEnum;
use Cerbero\Enum\CasesCollection;
use Cerbero\Enum\PureEnum;
use Cerbero\Enum\Enums\PureEnum;
use Pest\Expectation;

it('turns into a JSON with pure cases', function() {
Expand Down
16 changes: 8 additions & 8 deletions tests/PureEnumTest.php → tests/Unit/PureEnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use Cerbero\Enum\CasesCollection;
use Cerbero\Enum\Enums;
use Cerbero\Enum\InvalidMetaAttribute;
use Cerbero\Enum\PureEnum;
use Cerbero\Enum\Enums\InvalidMetaAttribute;
use Cerbero\Enum\Enums\PureEnum;
use Pest\Expectation;

it('determines whether the enum is pure')
Expand Down Expand Up @@ -309,7 +309,7 @@
]);

it('throws a value error when hydrating cases with an invalid value', fn() => PureEnum::from('1'))
->throws(ValueError::class, '"1" is not a valid name for enum "Cerbero\Enum\PureEnum"');
->throws(ValueError::class, '"1" is not a valid name for enum "Cerbero\Enum\Enums\PureEnum"');

it('retrieves the case hydrated from a value or returns null')
->expect(fn(string $value, ?PureEnum $case) => PureEnum::tryFrom($value) === $case)
Expand All @@ -332,7 +332,7 @@
]);

it('throws a value error when hydrating cases with an invalid name', fn() => PureEnum::fromName('1'))
->throws(ValueError::class, '"1" is not a valid name for enum "Cerbero\Enum\PureEnum"');
->throws(ValueError::class, '"1" is not a valid name for enum "Cerbero\Enum\Enums\PureEnum"');

it('retrieves the case hydrated from a name or returns null')
->expect(fn(string $name, ?PureEnum $case) => PureEnum::tryFromName($name) === $case)
Expand Down Expand Up @@ -361,7 +361,7 @@
->toBe([PureEnum::two]);

it('throws a value error when hydrating cases with an invalid meta', fn() => PureEnum::fromMeta('color', 'orange'))
->throws(ValueError::class, 'Invalid value for the meta "color" for enum "Cerbero\Enum\PureEnum"');
->throws(ValueError::class, 'Invalid value for the meta "color" for enum "Cerbero\Enum\Enums\PureEnum"');

it('retrieves the case hydrated from a meta or returns null')
->expect(fn(string $meta, mixed $value, ?array $cases) => PureEnum::tryFromMeta($meta, $value)?->all() === $cases)
Expand All @@ -384,7 +384,7 @@
->toBe('one');

it('fails handling the call to an invalid enum method', fn() => PureEnum::four())
->throws(ValueError::class, '"four" is not a valid name for enum "Cerbero\Enum\PureEnum"');
->throws(ValueError::class, '"four" is not a valid name for enum "Cerbero\Enum\Enums\PureEnum"');

it('runs custom logic when calling an inaccessible enum method', function() {
Enums::onStaticCall(function(string $enum, string $name, array $arguments) {
Expand All @@ -401,7 +401,7 @@
});

it('handles the call to an inaccessible case method', fn() => PureEnum::one->unknownMethod())
->throws(Error::class, 'The case Cerbero\Enum\PureEnum::one has no "unknownMethod" meta set');
->throws(Error::class, 'The case Cerbero\Enum\Enums\PureEnum::one has no "unknownMethod" meta set');

it('runs custom logic when calling an inaccessible case method', function() {
Enums::onCall(function(object $case, string $name, array $arguments) {
Expand Down Expand Up @@ -456,7 +456,7 @@
->toBe('red');

it('throws a value error when attempting to retrieve an invalid item', fn() => PureEnum::one->resolveItem('invalid'))
->throws(ValueError::class, 'The case Cerbero\Enum\PureEnum::one has no "invalid" meta set');
->throws(ValueError::class, 'The case Cerbero\Enum\Enums\PureEnum::one has no "invalid" meta set');

it('retrieves the value of a backed case or the name of a pure case', function() {
expect(PureEnum::one->value())->toBe('one');
Expand Down

0 comments on commit 42a31c9

Please sign in to comment.