-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from nayzo/refactor
Code refactoring + make doctrine/annotations dependency optional
- Loading branch information
Showing
17 changed files
with
271 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
/composer.lock | ||
/vendor | ||
/.idea | ||
/docker-compose.yml | ||
/Makefile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__) | ||
->exclude([ | ||
'.github/', | ||
'vendor/', | ||
]) | ||
; | ||
|
||
$config = (new PhpCsFixer\Config()) | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@PSR12' => true, | ||
'@Symfony' => true, | ||
'array_syntax' => ['syntax' => 'short'], | ||
'combine_consecutive_unsets' => true, | ||
'heredoc_to_nowdoc' => true, | ||
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']], | ||
'no_unreachable_default_argument_value' => true, | ||
'no_useless_else' => true, | ||
'no_useless_return' => true, | ||
'ordered_class_elements' => true, | ||
'ordered_imports' => true, | ||
'php_unit_strict' => true, | ||
'phpdoc_order' => true, | ||
'strict_comparison' => true, | ||
'strict_param' => true, | ||
'concat_space' => ['spacing' => 'one'], | ||
]) | ||
->setFinder($finder); | ||
|
||
return $config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Nzo\UrlEncryptorBundle\Tests\Annotation; | ||
|
||
use Doctrine\Common\Annotations\AnnotationReader; | ||
use Nzo\UrlEncryptorBundle\Annotations\AnnotationResolver; | ||
use Nzo\UrlEncryptorBundle\Encryptor\Encryptor; | ||
use Nzo\UrlEncryptorBundle\Tests\Annotation\Fixtures\DummyController; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Event\ControllerEvent; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
class AnnotationResolverTest extends TestCase | ||
{ | ||
public function provideDecryptOnKernelController(): \Iterator | ||
{ | ||
yield ['decryptWithAttribute', true]; | ||
yield ['decryptWithAnnotation', false]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideDecryptOnKernelController | ||
*/ | ||
public function testDecryptOnKernelController(string $action, bool $needsPhp8): void | ||
{ | ||
if ($needsPhp8 && PHP_VERSION_ID < 80000) { | ||
$this->markTestSkipped('At least PHP 8 is needed for this test'); | ||
} | ||
|
||
$encryptor = new Encryptor('foo', 'aes-256-ctr', true, true, true); | ||
$encryptor->setSecretIv('secret'); | ||
|
||
$request = Request::create('/'); | ||
$request->attributes->set('id', $encryptor->encrypt('some_data')); | ||
|
||
$controllerEvent = new ControllerEvent( | ||
$this->createMock(HttpKernelInterface::class), | ||
[new DummyController(), $action], | ||
$request, | ||
1 | ||
); | ||
|
||
$sut = new AnnotationResolver($encryptor, new AnnotationReader()); | ||
$sut->onKernelController($controllerEvent); | ||
|
||
$this->assertSame('some_data', $request->attributes->get('id')); | ||
} | ||
|
||
public function provideEncryptOnKernelController(): \Iterator | ||
{ | ||
yield ['encryptWithAttribute', true]; | ||
yield ['encryptWithAnnotation', false]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideEncryptOnKernelController | ||
*/ | ||
public function testEncryptOnKernelController(string $action, bool $needsPhp8): void | ||
{ | ||
if ($needsPhp8 && PHP_VERSION_ID < 80000) { | ||
$this->markTestSkipped('At least PHP 8 is needed for this test'); | ||
} | ||
|
||
$encryptor = new Encryptor('foo', 'aes-256-ctr', true, true, true); | ||
$encryptor->setSecretIv('secret'); | ||
|
||
$request = Request::create('/'); | ||
$request->attributes->set('id', 'some_data'); | ||
|
||
$controllerEvent = new ControllerEvent( | ||
$this->createMock(HttpKernelInterface::class), | ||
[new DummyController(), $action], | ||
$request, | ||
1 | ||
); | ||
|
||
$sut = new AnnotationResolver($encryptor, new AnnotationReader()); | ||
$sut->onKernelController($controllerEvent); | ||
|
||
$this->assertSame($encryptor->encrypt('some_data'), $request->attributes->get('id')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Nzo\UrlEncryptorBundle\Tests\Annotation\Fixtures; | ||
|
||
use Nzo\UrlEncryptorBundle\Annotations\ParamDecryptor; | ||
use Nzo\UrlEncryptorBundle\Annotations\ParamEncryptor; | ||
|
||
class DummyController | ||
{ | ||
#[ParamDecryptor(['id'])] | ||
public function decryptWithAttribute() | ||
{ | ||
} | ||
|
||
/** | ||
* @ParamDecryptor({"id"}) | ||
*/ | ||
public function decryptWithAnnotation() | ||
{ | ||
} | ||
|
||
#[ParamEncryptor(['id'])] | ||
public function encryptWithAttribute() | ||
{ | ||
} | ||
|
||
/** | ||
* @ParamEncryptor({"id"}) | ||
*/ | ||
public function encryptWithAnnotation() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.