Skip to content

Commit

Permalink
Merge pull request mazedlx#61 from Treggats/feature/60-add-interest_c…
Browse files Browse the repository at this point in the history
…ohort-feature
  • Loading branch information
mazedlx authored Oct 27, 2024
2 parents 02112c0 + fd67e5e commit 6c1f94b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
11 changes: 3 additions & 8 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector;
use Rector\Php80\Rector\ClassMethod\FinalPrivateToPrivateVisibilityRector;
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector;
use RectorLaravel\Set\LaravelLevelSetList;

/**
* @see https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md
Expand All @@ -33,10 +30,8 @@
// register a single rule
$rectorConfig->rules([
InlineConstructorDefaultToPropertyRector::class,
ChangeAndIfToEarlyReturnRector::class,
ChangeIfElseValueAssignToEarlyReturnRector::class,
RemoveUnusedVariableInCatchRector::class,
FinalizeClassesWithoutChildrenRector::class,
AddParamTypeDeclarationRector::class,
TypedPropertyFromStrictSetUpRector::class,
ReadOnlyPropertyRector::class,
ChangeSwitchToMatchRector::class,
Expand All @@ -46,7 +41,7 @@
// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
// LaravelLevelSetList::UP_TO_LARAVEL_100,
// \RectorLaravel\Set\LaravelLevelSetList::UP_TO_LARAVEL_100,
]);

$rectorConfig->skip([
Expand Down
33 changes: 30 additions & 3 deletions tests/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@

namespace Mazedlx\FeaturePolicy\Tests;

use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Mazedlx\FeaturePolicy\Directive;
use Mazedlx\FeaturePolicy\Exceptions\UnsupportedPermissionException;
use Mazedlx\FeaturePolicy\Value;
use ReflectionClass;

final class DirectiveTest extends TestCase
{
#[Test]
public function it_can_make_an_directive_from_name(): void
#[DataProvider('provide_directives')]
public function it_can_make_an_directive_from_name(string $constant, string $value): void
{
$directive = Directive::make(Directive::GEOLOCATION);
$directive = Directive::make($value);

$this->assertSame(Directive::GEOLOCATION, $directive->name());
$this->assertSame(constant(Directive::class . '::' . $constant), $directive->name());
$this->assertSame($value, $directive->name());
$this->assertIsArray($directive->rules());

Check failure on line 23 in tests/DirectiveTest.php

View workflow job for this annotation

GitHub Actions / analysis (ubuntu-latest, 8.1)

Call to method PHPUnit\Framework\Assert::assertIsArray() with array will always evaluate to true.

Check failure on line 23 in tests/DirectiveTest.php

View workflow job for this annotation

GitHub Actions / analysis (ubuntu-latest, 8.2)

Call to method PHPUnit\Framework\Assert::assertIsArray() with array will always evaluate to true.
$this->assertEmpty($directive->rules());
}
Expand Down Expand Up @@ -44,6 +49,28 @@ public function xr_spatial_tracking_adds_the_correct_header_directive_instead_of
$this->assertSame(Directive::XR_SPATIAL_TRACKING, $directive->name());
}

public static function provide_directives(): Generator
{
$directiveClass = new ReflectionClass(Directive::class);
$constants = array_filter($directiveClass->getConstants(), static function ($constant) {
$skippableDirectives = [
Directive::VR,
Directive::XR,
Directive::XR_SPATIAL_TRACKING,
Directive::FLOC,
];

return ! in_array($constant, $skippableDirectives, strict: true);
});

foreach ($constants as $const => $constantValue) {
yield $const => [
$const,
$constantValue,
];
}
}

#[Test]
public function floc_is_disabled_by_default()
{
Expand Down
8 changes: 3 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Mazedlx\FeaturePolicy\Tests;

use Illuminate\Contracts\Http\Kernel;
use Illuminate\Support\Facades\Route;
use Mazedlx\FeaturePolicy\AddFeaturePolicyHeaders;
use Orchestra\Testbench\TestCase as Orchestra;
Expand All @@ -14,12 +13,11 @@ protected function setUp(): void
{
parent::setUp();

app(Kernel::class)->pushMiddleware(AddFeaturePolicyHeaders::class);

Route::get('test-route', static fn () => 'ok');
Route::middleware(AddFeaturePolicyHeaders::class)
->get('test-route', static fn () => 'ok');
}

protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
FeaturePolicyServiceProvider::class,
Expand Down

0 comments on commit 6c1f94b

Please sign in to comment.