Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #317 from tighten/v8.83.17-changes
Browse files Browse the repository at this point in the history
v8.83.17 changes
  • Loading branch information
jamisonvalenta authored Aug 22, 2022
2 parents 7275c1b + 3dae9ae commit 68d2d38
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Collect/Support/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\VarDumper\VarDumper;
use Traversable;
use UnexpectedValueException;
use UnitEnum;

/**
* @property-read HigherOrderCollectionProxy $average
Expand Down Expand Up @@ -991,6 +992,8 @@ protected function getArrayableItems($items)
return (array) $items->jsonSerialize();
} elseif ($items instanceof Traversable) {
return iterator_to_array($items);
} elseif ($items instanceof UnitEnum) {
return [$items];
}

return (array) $items;
Expand Down
13 changes: 13 additions & 0 deletions tests/Support/Enums.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Tightenco\Collect\Tests\Support;

enum TestEnum
{
case A;
}

enum TestBackedEnum: int
{
case A = 1;
}
24 changes: 24 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
use Symfony\Component\VarDumper\VarDumper;
use UnexpectedValueException;

if (PHP_VERSION_ID >= 80100) {
include_once 'Enums.php';
}

class SupportCollectionTest extends TestCase
{
/**
Expand Down Expand Up @@ -4254,6 +4258,26 @@ public function testCollectionFromTraversableWithKeys($collection)
$this->assertEquals(['foo' => 1, 'bar' => 2, 'baz' => 3], $data->toArray());
}

/**
* @dataProvider collectionClassProvider
* @requires PHP >= 8.1
*/
public function testCollectionFromEnum($collection)
{
$data = new $collection(TestEnum::A);
$this->assertEquals([TestEnum::A], $data->toArray());
}

/**
* @dataProvider collectionClassProvider
* @requires PHP >= 8.1
*/
public function testCollectionFromBackedEnum($collection)
{
$data = new $collection(TestBackedEnum::A);
$this->assertEquals([TestBackedEnum::A], $data->toArray());
}

/**
* @dataProvider collectionClassProvider
*/
Expand Down
3 changes: 2 additions & 1 deletion upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ carriageReturn="
)

tests=(
'Support/Enums.php'
'Support/SupportCollectionTest.php'
'Support/SupportArrTest.php'
'Support/SupportMacroableTest.php'
Expand Down Expand Up @@ -366,7 +367,7 @@ function getCurrentVersionFromGitHub()
echo Getting current version from $repository...

if [ -z "$requestedVersion" ]; then
collectionVersion=$(git ls-remote $repository --tags v8\* | grep tags/ | grep -v {} | cut -d \/ -f 3 | cut -d v -f 2 | grep -v RC | grep -vi beta | sort -t. -k 1,1n -k 2,2n -k 3,3n| tail -1)
collectionVersion=$(git ls-remote $repository --tags v8.83.17\* | grep tags/ | grep -v {} | cut -d \/ -f 3 | cut -d v -f 2 | grep -v RC | grep -vi beta | sort -t. -k 1,1n -k 2,2n -k 3,3n| tail -1)
else
collectionVersion=$requestedVersion
fi
Expand Down

0 comments on commit 68d2d38

Please sign in to comment.