Skip to content

Commit

Permalink
Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
henzeb committed Mar 10, 2024
1 parent c067903 commit cbf1230
Show file tree
Hide file tree
Showing 21 changed files with 107 additions and 127 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.php_cs
.php_cs.cache
.phpunit.result.cache
.phpunit.cache/
phpunit.xml.bak
build
coverage
coverage.xml
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
"infection/infection": "^0.27.0",
"mockery/mockery": "^1.5",
"nunomaduro/larastan": "^2.3",
"orchestra/testbench": "^v7.18|^8.0",
"orchestra/testbench": "^v7.18|^8.0|^9",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5.27"
"phpunit/phpunit": "^9.5.27|^10"
},
"autoload": {
"files": [
Expand Down
48 changes: 22 additions & 26 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<!-- <server name="DB_CONNECTION" value="sqlite"/> -->
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<!-- <server name="DB_CONNECTION" value="sqlite"/> -->
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
</php>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
3 changes: 2 additions & 1 deletion src/Laravel/Concerns/CastsBasicEnumerations.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ private function shouldUseBasicEnumWorkaround(string $enumClass): bool
&& 'toArray' === (debug_backtrace(2)[5]['function'] ?? null);
}

protected function getStorableEnumValue($value)
protected function getStorableEnumValue($expectedEnumValue, $value = null)
{
$value ??= $expectedEnumValue;
if ($value instanceof UnitEnum) {
$keepEnumCase = property_exists($this, 'keepEnumCase') ? $this->keepEnumCase : true;

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Concerns/DefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class DefaultsTest extends TestCase
{
public function providesCases(): array
public static function providesCases(): array
{
return [
[DefaultsEnum::class, DefaultsEnum::Default],
Expand All @@ -45,7 +45,7 @@ public function providesCases(): array
];
}

public function providesAssertionTestcases(): array
public static function providesAssertionTestcases(): array
{
return [
[DefaultsEnum::Default, true],
Expand Down
7 changes: 1 addition & 6 deletions tests/Unit/Concerns/DropdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class DropdownTest extends TestCase
{
public static function dropdownTestcases(): array
public static function providesDropdownTestcases(): array
{
return [
[
Expand Down Expand Up @@ -58,11 +58,6 @@ public static function dropdownTestcases(): array
];
}

public function providesDropdownTestcases(): array
{
return self::dropdownTestcases();
}

/**
* @param string $enum
* @param array $expected
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Concerns/MappersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\Mappers\ConstantMapperClassFlippedEnum;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use stdClass;
use ValueError;


Expand Down Expand Up @@ -62,7 +63,7 @@ public function testGetShouldMapWithStringMap()
public function testGetShouldThrowExceptionForNonMap()
{
$this->expectException(RuntimeException::class);
EnhancedBackedEnum::get('mappedEnum', self::class);
EnhancedBackedEnum::get('mappedEnum', stdClass::class);
}

public function testGetShouldNotMapWhenNull()
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Concerns/ReportersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedBackedEnum;
use Henzeb\Enumhancer\Tests\Fixtures\NotReportingEnum;
use Henzeb\Enumhancer\Tests\Fixtures\ReporterTestEnum;

use Mockery;
use PHPUnit\Framework\TestCase;

class ReportersTest extends TestCase
{
public function providesEnumsToTestWith(): array
public static function providesEnumsToTestWith(): array
{
return [
'just-reporters' => [ReporterTestEnum::class],
Expand Down
20 changes: 10 additions & 10 deletions tests/Unit/Concerns/StateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace Henzeb\Enumhancer\Tests\Unit\Concerns;

use Mockery;
use UnitEnum;
use Mockery\Mock;
use PHPUnit\Framework\TestCase;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Henzeb\Enumhancer\Contracts\TransitionHook;
use Henzeb\Enumhancer\Exceptions\IllegalEnumTransitionException;
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\State\StateElevatorEnum;
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\State\StateElevatorComplexEnum;
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\State\StateElevatorDisableTransitionEnum;
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\State\StateElevatorEnum;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\Mock;
use UnitEnum;

class StateTest extends MockeryTestCase
{
Expand Down Expand Up @@ -53,7 +52,7 @@ public function testComplexTransition(): void
);
}

public function providesNotAllowedTransitionTestcases(): array
public static function providesNotAllowedTransitionTestcases(): array
{
return [
'basic-open-move' => [StateElevatorEnum::Open, 'Move'],
Expand Down Expand Up @@ -133,12 +132,13 @@ public function testCloseToMoveStillWorksWhenCustomTransitions(): void
$this->assertTrue(StateElevatorDisableTransitionEnum::Close->isTransitionAllowed('move'));
}

public function testTransitionsShouldBeFullyPropagatedWhenUsingCustomTransitions() {
public function testTransitionsShouldBeFullyPropagatedWhenUsingCustomTransitions()
{

$this->assertEquals(
[
'Open'=> null,
'Close'=> StateElevatorDisableTransitionEnum::Move,
'Open' => null,
'Close' => StateElevatorDisableTransitionEnum::Move,
'Move' => StateElevatorDisableTransitionEnum::Stop,
],
StateElevatorDisableTransitionEnum::transitions()
Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Concerns/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Henzeb\Enumhancer\Tests\Unit\Concerns;

use Henzeb\Enumhancer\Tests\Fixtures\BackedEnums\Value\ValueIntBackedEnum;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedBackedEnum;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedUnitEnum;
use Henzeb\Enumhancer\Tests\Fixtures\UnitEnums\Value\ValueStrictEnum;
use PHPUnit\Framework\TestCase;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedUnitEnum;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedBackedEnum;
use Henzeb\Enumhancer\Tests\Fixtures\BackedEnums\Value\ValueIntBackedEnum;


class ValueTest extends TestCase
{
public function providesEnumsForValue()
public static function providesEnumsForValue(): array
{
return [
'backed-1' => [EnhancedBackedEnum::ENUM, EnhancedBackedEnum::ENUM->value],
Expand All @@ -22,7 +22,7 @@ public function providesEnumsForValue()
];
}

public function providesEnumsForKey()
public static function providesEnumsForKey(): array
{
return [
'string-backed-1' => [EnhancedBackedEnum::ENUM, 0],
Expand Down Expand Up @@ -52,7 +52,7 @@ public function testEnumShouldReturnValue($enum, string $expected): void

/**
* @param $enum
* @param string $expected
* @param int $expected
* @return void
*
* @dataProvider providesEnumsForKey
Expand Down
30 changes: 17 additions & 13 deletions tests/Unit/Functions/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

namespace Henzeb\Enumhancer\Tests\Unit\Functions;

use UnitEnum;
use PHPUnit\Framework\TestCase;
use Henzeb\Enumhancer\Helpers\EnumProxy;
use Henzeb\Enumhancer\Helpers\EnumValue;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedUnitEnum;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedBackedEnum;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedUnitEnum;
use PHPUnit\Framework\TestCase;
use UnitEnum;
use function Henzeb\Enumhancer\Functions\b;
use function Henzeb\Enumhancer\Functions\n;
use function Henzeb\Enumhancer\Functions\v;
use function Henzeb\Enumhancer\Functions\backing;
use function Henzeb\Enumhancer\Functions\backingLowercase;
use function Henzeb\Enumhancer\Functions\bl;
use function Henzeb\Enumhancer\Functions\vl;
use function Henzeb\Enumhancer\Functions\n;
use function Henzeb\Enumhancer\Functions\name;
use function Henzeb\Enumhancer\Functions\valueLowercase;
use function Henzeb\Enumhancer\Functions\backingLowercase;
use function Henzeb\Enumhancer\Functions\backing;
use function Henzeb\Enumhancer\Functions\v;
use function Henzeb\Enumhancer\Functions\value as EnumValue;
use function Henzeb\Enumhancer\Functions\valueLowercase;
use function Henzeb\Enumhancer\Functions\vl;


class FunctionsTest extends TestCase
{
function providesBackedFunctionTestcases(): array
public static function providesBackedFunctionTestcases(): array
{
return [
'b-unit' => ['Henzeb\Enumhancer\Functions\b', EnhancedUnitEnum::THIRD_ENUM],
Expand All @@ -31,7 +31,11 @@ function providesBackedFunctionTestcases(): array
'backing-backed' => ['Henzeb\Enumhancer\Functions\backing', EnhancedBackedEnum::ENUM],
'bl-unit' => ['Henzeb\Enumhancer\Functions\bl', EnhancedUnitEnum::THIRD_ENUM, false],
'bl-backed' => ['Henzeb\Enumhancer\Functions\bl', EnhancedBackedEnum::ENUM],
'backing-lower-unit' => ['Henzeb\Enumhancer\Functions\backingLowercase', EnhancedUnitEnum::THIRD_ENUM, false],
'backing-lower-unit' => [
'Henzeb\Enumhancer\Functions\backingLowercase',
EnhancedUnitEnum::THIRD_ENUM,
false
],
'backing-lower-backed' => ['Henzeb\Enumhancer\Functions\backingLowercase', EnhancedBackedEnum::ENUM],
];
}
Expand Down Expand Up @@ -71,7 +75,7 @@ public function testBackingShouldAllowNull()
}


function providesNameFunctionTestcases(): array
public static function providesNameFunctionTestcases(): array
{
return [
'n-unit' => ['Henzeb\Enumhancer\Functions\n', EnhancedUnitEnum::THIRD_ENUM],
Expand Down Expand Up @@ -107,7 +111,7 @@ public function testNameShouldAllowNull()
);
}

function providesValueFunctionTestcases(): array
public static function providesValueFunctionTestcases(): array
{
return [
'v-unit' => ['Henzeb\Enumhancer\Functions\v', EnhancedUnitEnum::THIRD_ENUM],
Expand Down
17 changes: 8 additions & 9 deletions tests/Unit/Helpers/EnumBladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@

namespace Henzeb\Enumhancer\Tests\Unit\Helpers;

use UnitEnum;
use RuntimeException;
use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\Blade;
use Henzeb\Enumhancer\Helpers\EnumBlade;
use Henzeb\Enumhancer\Tests\Fixtures\IntBackedEnum;
use Henzeb\Enumhancer\Exceptions\NotAnEnumException;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedUnitEnum;
use Henzeb\Enumhancer\Helpers\EnumBlade;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedBackedEnum;
use Henzeb\Enumhancer\Tests\Fixtures\EnhancedUnitEnum;
use Henzeb\Enumhancer\Tests\Fixtures\IntBackedEnum;
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use Orchestra\Testbench\TestCase;
use UnitEnum;
use function Henzeb\Enumhancer\Functions\backing;
use function Henzeb\Enumhancer\Functions\name;
use function Henzeb\Enumhancer\Functions\value;
use function Henzeb\Enumhancer\Functions\backing;

class EnumBladeTest extends TestCase
{
use InteractsWithViews;
public function providesTestcases(): array

public static function providesTestcases(): array
{
return [
'int-backed' => [IntBackedEnum::TEST],
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Helpers/EnumPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EnumPropertiesTest extends TestCase
{
use ClearsEnumProperties;

public function providesTestcasesForStoreProperty(): array
public static function providesTestcasesForStoreProperty(): array
{
return [
'boolean' => ['property', true, true, ConstructableUnitEnum::class],
Expand Down Expand Up @@ -63,7 +63,7 @@ public function testClearShouldNotAcceptNonEnums()
EnumProperties::clear(stdClass::class);
}

public function providesTestcasesForStorePropertyGlobally(): array
public static function providesTestcasesForStorePropertyGlobally(): array
{
return [
'boolean' => ['property', true, true],
Expand Down Expand Up @@ -230,7 +230,7 @@ public function testStoreOnceOverridesStore()
$this->assertEquals('something else', EnumProperties::get(ConstructableUnitEnum::class, 'test'));
}

public function providesReservedWords(): array
public static function providesReservedWords(): array
{
return [
['@default_configure', 'defaults'],
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Helpers/EnumSubsetMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function (EnhancedUnitEnum $enum) use (&$enums) {
$this->assertEquals(EnhancedUnitEnum::cases(), $enums);
}

public function providesTestCasesForReturningSubsetOfCases(): array
public static function providesTestCasesForReturningSubsetOfCases(): array
{
return [
[[EnhancedUnitEnum::ENUM]],
Expand All @@ -140,9 +140,9 @@ public function testCasesShouldReturnSubsetOfCases(array $cases)
);
}

public function providesDropdownTestcases(): array
public static function providesDropdownTestcases(): array
{
return DropdownTest::dropdownTestcases();
return DropdownTest::providesDropdownTestcases();
}

/**
Expand Down
Loading

0 comments on commit cbf1230

Please sign in to comment.