Skip to content

Commit

Permalink
Fixes duplicate entries and adds a test (#249)
Browse files Browse the repository at this point in the history
* Fixes duplicate entries and adds a test

* CS Fixes
  • Loading branch information
peterfox authored Sep 12, 2024
1 parent a7306b9 commit 321a7f8
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/Set/LaravelSetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace RectorLaravel\Set;

use Rector\Set\Contract\SetInterface;
use Rector\Set\Contract\SetProviderInterface;
use Rector\Set\ValueObject\Set;
use RectorLaravel\Set\Packages\Livewire\LivewireSetList;
Expand Down Expand Up @@ -37,6 +38,9 @@ final class LaravelSetProvider implements SetProviderInterface
LaravelSetList::LARAVEL_110,
];

/**
* @return SetInterface[]
*/
public function provide(): array
{
return [
Expand All @@ -45,28 +49,16 @@ public function provide(): array
'array/str func to static calls',
LaravelSetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL
),
new Set(self::GROUP_NAME, 'Code quality', LaravelSetList::LARAVEL_CODE_QUALITY),
new Set(
self::GROUP_NAME,
'Container strings to FQN types',
LaravelSetList::LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME,
),
new Set(
'Laravel Code Quality',
'array/str functions to static calls',
LaravelSetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL
'Code quality',
LaravelSetList::LARAVEL_CODE_QUALITY
),
new Set(self::GROUP_NAME, 'Code quality', LaravelSetList::LARAVEL_CODE_QUALITY),
new Set(
self::GROUP_NAME,
'Container strings to FQN types',
LaravelSetList::LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME,
),
new Set(
self::GROUP_NAME,
'Code Quality for Laravel',
LaravelSetList::LARAVEL_CODE_QUALITY,
),
new Set(
self::GROUP_NAME,
'Replaces If statements with helpers',
Expand Down
68 changes: 68 additions & 0 deletions tests/Sets/LaravelSetProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace RectorLaravel\Tests\Sets;

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Rector\Set\Contract\SetInterface;
use RectorLaravel\Set\LaravelSetList;
use RectorLaravel\Set\LaravelSetProvider;

final class LaravelSetProviderTest extends TestCase
{
private const LARAVEL_VERSION_SETS = [
LaravelSetList::LARAVEL_50,
LaravelSetList::LARAVEL_51,
LaravelSetList::LARAVEL_52,
LaravelSetList::LARAVEL_53,
LaravelSetList::LARAVEL_54,
LaravelSetList::LARAVEL_55,
LaravelSetList::LARAVEL_56,
LaravelSetList::LARAVEL_57,
LaravelSetList::LARAVEL_58,
LaravelSetList::LARAVEL_60,
LaravelSetList::LARAVEL_70,
LaravelSetList::LARAVEL_80,
LaravelSetList::LARAVEL_90,
LaravelSetList::LARAVEL_100,
LaravelSetList::LARAVEL_110,
];

public function testItProvidesSets(): void
{
$laravelSetProvider = new LaravelSetProvider();

Assert::assertContainsOnlyInstancesOf(
SetInterface::class,
$laravelSetProvider->provide()
);
}

public function testItReturnsUniqueSets(): void
{
$laravelSetProvider = new LaravelSetProvider();

$sets = $laravelSetProvider->provide();

$uniqueSets = array_unique(array_map(fn (SetInterface $set) => $set->getSetFilePath(), $sets));

Assert::assertCount(count($sets), $uniqueSets);
}

public function testItProvidesAllLaravelVersions(): void
{
$laravelSetProvider = new LaravelSetProvider();

$sets = $laravelSetProvider->provide();

$sets = array_filter(
array_map(
fn (SetInterface $set) => $set->getSetFilePath(),
$sets
),
fn (string $filePath) => in_array($filePath, self::LARAVEL_VERSION_SETS, true),
);

Assert::assertCount(count(self::LARAVEL_VERSION_SETS), $sets);
}
}

0 comments on commit 321a7f8

Please sign in to comment.