Create Testcoverage and upgrade Symfomy and PHP
Some checks failed
CI / Tests (push) Failing after 1m8s
CI / Build and deploy to ${{ startsWith(github.ref, 'refs/tags/') && 'production' || (github.ref == 'refs/heads/main' && 'acceptance' || '') }} (push) Has been skipped

* Some tests

* More tests!

* Tests 3

* Move getScores from Candidate to Quiz

* Add some suggestions for future refactoring

* - **Add Gedmo doctrine-extensions and Stof bundle integration**
  - Added `stof/doctrine-extensions-bundle` and `gedmo/doctrine-extensions` dependencies.
  - Integrated `Timestampable` behavior for `Created` fields in entities.
  - Updated `bundles.php` to register StofDoctrineExtensionsBundle.
  - Added configuration for the Stof bundle.
  - Simplified `SeasonVoter` with `match` expression and added new tests.
  - Minor fixes and adjustments across various files.

* WIP

* All the tests

* Base64 tests

* Symfomny 7.4.0

* Update

* Update recipe

* PHP 8.5

* Rector changes

* More 8.5

* Things
This commit is contained in:
2025-11-28 22:56:09 +01:00
committed by GitHub
parent fc273638ad
commit bcd6a157a8
56 changed files with 4324 additions and 1424 deletions

View File

@@ -4,11 +4,13 @@ declare(strict_types=1);
namespace Tvdt\Tests\Security\Voter;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\Stub;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Tvdt\Entity\Answer;
use Tvdt\Entity\Candidate;
use Tvdt\Entity\Elimination;
@@ -18,6 +20,7 @@ use Tvdt\Entity\Season;
use Tvdt\Entity\User;
use Tvdt\Security\Voter\SeasonVoter;
#[CoversClass(SeasonVoter::class)]
final class SeasonVoterTest extends TestCase
{
private SeasonVoter $seasonVoter;
@@ -51,27 +54,58 @@ final class SeasonVoterTest extends TestCase
{
$season = self::createStub(Season::class);
$season->method('isOwner')->willReturn(true);
$quiz = self::createStub(Quiz::class);
$quiz->season = $season;
$elimination = self::createStub(Elimination::class);
$elimination->quiz = $quiz;
yield 'Season' => [$season];
$candidate = self::createStub(Candidate::class);
$candidate->season = $season;
yield 'Candidate' => [$candidate];
$quiz = self::createStub(Quiz::class);
$quiz->season = $season;
yield 'Quiz' => [$quiz];
$elimination = self::createStub(Elimination::class);
$elimination->quiz = $quiz;
yield 'Elimination' => [$elimination];
$question = self::createStub(Question::class);
$question->quiz = $quiz;
yield 'Question' => [$question];
$answer = self::createStub(Answer::class);
$answer->question = $question;
yield 'Season' => [$season];
yield 'Elimination' => [$elimination];
yield 'Quiz' => [$quiz];
yield 'Candidate' => [$candidate];
yield 'Question' => [$question];
yield 'Answer' => [$answer];
}
public function testWrongUserTypeReturnFalse(): void
{
$user = self::createStub(UserInterface::class);
$token = $this->createStub(TokenInterface::class);
$token->method('getUser')->willReturn($user);
$this->assertSame(VoterInterface::ACCESS_DENIED, $this->seasonVoter->vote($token, new Season(), ['SEASON_EDIT']));
}
public function testAdminCanDoAnything(): void
{
$user = new User();
$user->roles = ['ROLE_ADMIN'];
$token = $this->createStub(TokenInterface::class);
$token->method('getUser')->willReturn($user);
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->seasonVoter->vote($token, new Season(), ['SEASON_EDIT']));
}
public function testRandomClassWillAbstain(): void
{
$subject = new \stdClass();
$this->assertSame(VoterInterface::ACCESS_ABSTAIN, $this->seasonVoter->vote($this->token, $subject, ['SEASON_EDIT']));
}
public function testRandomSunjectWillAbstain(): void
{
$subject = new Season();
$this->assertSame(VoterInterface::ACCESS_ABSTAIN, $this->seasonVoter->vote($this->token, $subject, ['DO_NOTHING']));
}
}