Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
3.4.6
=====

* (deprecation) Deprecate `DoctrineChangeChecker`.


3.4.5
=====

* (internal) Add tests for `AbilitiesVoter`.


3.4.4
=====

Expand Down
1 change: 1 addition & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

* Passing a `bool` to the constructor of `ApiResponse` was removed, pass a status code instead.
* The method `ApiResponse::withStatusCode()` was removed. Pass the status code in the constructor instead.
* `DoctrineChangeChecker` was removed. There is no direct replacement.


2.x to 3.0
Expand Down
14 changes: 13 additions & 1 deletion src/Doctrine/DoctrineChangeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
use Doctrine\Persistence\ManagerRegistry;
use Torr\Rad\Exception\Doctrine\InvalidDoctrineChangeCheckException;

/**
* @deprecated this class is deprecated and will be removed in v4
*/
final readonly class DoctrineChangeChecker
{
// TODO remove in v4
/**
*/
public function __construct (
private ManagerRegistry $managerRegistry,
) {}
)
{
trigger_deprecation(
"21torr/rad",
"3.4.6",
"Using %s is deprecated and will be removed in v4.",
self::class,
);
}

/**
* Determines whether any content globally in any of the entities (or the entities themselves)
Expand Down
13 changes: 13 additions & 0 deletions tests/Doctrine/DoctrineChangeCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
use Doctrine\ORM\UnitOfWork;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Torr\Rad\Doctrine\DoctrineChangeChecker;

/**
* @internal
*/
final class DoctrineChangeCheckerTest extends TestCase
{
use ExpectDeprecationTrait;

/**
*
*/
Expand Down Expand Up @@ -51,6 +54,8 @@ public static function provideLargeEntityChanges () : iterable

/**
* @dataProvider provideLargeEntityChanges
*
* @group legacy
*/
public function testLargeEntityChanges (
bool $expected,
Expand Down Expand Up @@ -92,7 +97,10 @@ public function testLargeEntityChanges (
->method("getManager")
->willReturn($entityManager);

$this->expectDeprecation("Since 21torr/rad 3.4.6: Using Torr\\Rad\\Doctrine\\DoctrineChangeChecker is deprecated and will be removed in v4.");
// @phpstan-ignore-next-line
$checker = new DoctrineChangeChecker($registry);
// @phpstan-ignore-next-line
self::assertSame($expected, $checker->hasContentChanged());
}

Expand All @@ -114,6 +122,8 @@ public static function provideChangesets () : iterable

/**
* @dataProvider provideChangesets
*
* @group legacy
*/
public function testChangesets (
bool $expected,
Expand Down Expand Up @@ -158,7 +168,10 @@ public function testChangesets (
->method("getManager")
->willReturn($entityManager);

$this->expectDeprecation("Since 21torr/rad 3.4.6: Using Torr\\Rad\\Doctrine\\DoctrineChangeChecker is deprecated and will be removed in v4.");
// @phpstan-ignore-next-line
$checker = new DoctrineChangeChecker($registry);
// @phpstan-ignore-next-line
self::assertSame($expected, $checker->hasContentChanged());
}
}
73 changes: 73 additions & 0 deletions tests/Security/AbilitiesVoterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php declare(strict_types=1);

namespace Tests\Torr\Rad\Security;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Torr\Rad\Security\AbilitiesVoter;

/**
* @internal
*/
final class AbilitiesVoterTest extends TestCase
{
/**
*
*/
public function testVoteGrantedForReachableAbility () : void
{
$token = $this->createToken(["ROLE_ADMIN"]);
$roleHierarchy = new RoleHierarchy(["ROLE_ADMIN" => ["CAN_VIEW_DASHBOARD"]]);
$voter = new AbilitiesVoter($roleHierarchy);

self::assertSame(
VoterInterface::ACCESS_GRANTED,
$voter->vote($token, null, ["CAN_VIEW_DASHBOARD"]),
);
}

/**
*
*/
public function testVoteDeniedForMissingAbility () : void
{
$token = $this->createToken(["ROLE_USER"]);
$roleHierarchy = new RoleHierarchy([]);
$voter = new AbilitiesVoter($roleHierarchy);

self::assertSame(
VoterInterface::ACCESS_DENIED,
$voter->vote($token, null, ["CAN_EDIT_USERS"]),
);
}

/**
*
*/
public function testVoteAbstainsForNonCanAttribute () : void
{
$token = $this->createToken(["ROLE_USER"]);
$roleHierarchy = new RoleHierarchy([]);
$voter = new AbilitiesVoter($roleHierarchy);

self::assertSame(
VoterInterface::ACCESS_ABSTAIN,
$voter->vote($token, null, ["ROLE_USER"]),
);
}

/**
*
*/
private function createToken (array $roles) : UsernamePasswordToken
{
return new UsernamePasswordToken(
new InMemoryUser("test", null, $roles),
"main",
$roles,
);
}
}
Loading