Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add encoder aware interface #3

Merged
merged 4 commits into from
Jun 9, 2022
Merged
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
14 changes: 12 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />

<file name="src/Core/User/AdvancedUserInterface.php" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<UndefinedClass>
<errorLevel type="suppress">
<file name="src/Core/Encoder/EncoderAwareInterface.php" />
<file name="src/Core/User/AdvancedUserInterface.php" />
</errorLevel>
</UndefinedClass>
<UnrecognizedStatement>
<errorLevel type="suppress">
<file name="src/Core/Encoder/EncoderAwareInterface.php" />
<file name="src/Core/User/AdvancedUserInterface.php" />
</errorLevel>
</UnrecognizedStatement>
<DuplicateClass>
<errorLevel type="suppress">
<file name="src/Core/User/UserInterface.php" />
Expand Down
29 changes: 29 additions & 0 deletions src/Core/Encoder/EncoderAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace SyliusLabs\Polyfill\Symfony\Security\Core\Encoder;

use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface as SymfonyEncoderAwareInterface;

if (\interface_exists(SymfonyEncoderAwareInterface::class)) {
interface EncoderAwareInterface extends SymfonyEncoderAwareInterface
{
}
} else {
/**
* @link https://github.com/symfony/symfony/blob/5.4/src/Symfony/Component/Security/Core/Encoder/EncoderAwareInterface.php
*/
interface EncoderAwareInterface
{
/**
* Gets the name of the encoder used to encode the password.
*
* If the method returns null, the standard way to retrieve the encoder
* will be used instead.
*
* @return string|null
*/
public function getEncoderName();
}
}
48 changes: 48 additions & 0 deletions tests/Core/Encoder/EncoderAwareInterfaceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Tests\SyliusLabs\Polyfill\Symfony\Security\Core\Encoder;

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use SyliusLabs\Polyfill\Symfony\Security\Core\Encoder\EncoderAwareInterface;
use Symfony\Component\Security\Core\Encoder\EncoderAwareInterface as SymfonyEncoderAwareInterface;
use Symfony\Component\Security\Core\User\UserInterface;

final class EncoderAwareInterfaceTest extends TestCase
{
/** @test */
public function it_extends_symfonys_encoder_aware_interface_if_available(): void
{
if (!\interface_exists(SymfonyEncoderAwareInterface::class)) {
self::markTestSkipped('Symfony EncoderAwareInterface does not exist.');
}

Assert::assertContains(SymfonyEncoderAwareInterface::class, \class_implements(EncoderAwareInterface::class));
}

/** @test */
public function it_does_not_extend_symfonys_encoder_aware_interface_if_not_available(): void
{
if (\interface_exists(SymfonyEncoderAwareInterface::class)) {
self::markTestSkipped('Symfony EncoderAwareInterface exists.');
}

Assert::assertNotContains(SymfonyEncoderAwareInterface::class, \class_implements(EncoderAwareInterface::class));
}

/** @test */
public function it_contains_expected_methods(): void
{
$reflectionClass = new \ReflectionClass(EncoderAwareInterface::class);
$declaredMethods = array_map(
static function (\ReflectionMethod $reflectionMethod): string {
return $reflectionMethod->getName();
},
$reflectionClass->getMethods()
);

Assert::assertContains('getEncoderName', $declaredMethods);
}
}