-
Notifications
You must be signed in to change notification settings - Fork 2
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 #6 from odandb/feature/tests-perfs
Add tests & enhance perfs while performing encryption/decryption
- Loading branch information
Showing
24 changed files
with
524 additions
and
15 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
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Odandb\DoctrineCiphersweetEncryptionBundle\Tests\App; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\Config\Resource\FileResource; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\HttpKernel\Kernel as BaseKernel; | ||
|
||
class Kernel extends BaseKernel | ||
{ | ||
use MicroKernelTrait; | ||
|
||
private const CONFIG_EXTS = '.{php,xml,yaml,yml}'; | ||
|
||
public function registerBundles(): iterable | ||
{ | ||
$contents = require $this->getProjectDir().'/config/bundles.php'; | ||
foreach ($contents as $class => $envs) { | ||
if ($envs[$this->environment] ?? $envs['all'] ?? false) { | ||
yield new $class(); | ||
} | ||
} | ||
} | ||
|
||
public function getProjectDir(): string | ||
{ | ||
return \dirname(__DIR__).'/App'; | ||
} | ||
|
||
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void | ||
{ | ||
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php')); | ||
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug); | ||
$container->setParameter('container.dumper.inline_factories', true); | ||
|
||
$loader->load($this->getProjectDir().'/config/services'.self::CONFIG_EXTS, 'glob'); | ||
$loader->load($this->getProjectDir().'/config/{packages}/*'.self::CONFIG_EXTS, 'glob'); | ||
|
||
$confDir = $this->getProjectDir().'/../../src/Resources/config'; | ||
$loader->load($confDir.'/encryption-services'.self::CONFIG_EXTS, 'glob'); | ||
} | ||
} |
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,42 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
use Odandb\DoctrineCiphersweetEncryptionBundle\Tests\App\Kernel; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Input\ArgvInput; | ||
use Symfony\Component\ErrorHandler\Debug; | ||
|
||
if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { | ||
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; | ||
} | ||
|
||
set_time_limit(0); | ||
|
||
require dirname(__DIR__) . '/../../vendor/autoload.php'; | ||
|
||
if (!class_exists(Application::class)) { | ||
throw new LogicException('You need to add "symfony/framework-bundle" as a Composer dependency.'); | ||
} | ||
|
||
$input = new ArgvInput(); | ||
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) { | ||
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); | ||
} | ||
|
||
if ($input->hasParameterOption('--no-debug', true)) { | ||
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); | ||
} | ||
|
||
require dirname(__DIR__) . '/config/bootstrap.php'; | ||
|
||
if ($_SERVER['APP_DEBUG']) { | ||
umask(0000); | ||
|
||
if (class_exists(Debug::class)) { | ||
Debug::enable(); | ||
} | ||
} | ||
|
||
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); | ||
$application = new Application($kernel); | ||
$application->run($input); |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\Dotenv\Dotenv; | ||
|
||
require dirname(__DIR__).'/../../vendor/autoload.php'; | ||
|
||
// // Load cached env vars if the .env.local.php file exists | ||
// // Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) | ||
// if (is_array($env = @include dirname(__DIR__).'/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) { | ||
// foreach ($env as $k => $v) { | ||
// $_ENV[$k] = $_ENV[$k] ?? (isset($_SERVER[$k]) && 0 !== strpos($k, 'HTTP_') ? $_SERVER[$k] : $v); | ||
// } | ||
// } elseif (!class_exists(Dotenv::class)) { | ||
// throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); | ||
// } else { | ||
// // load all the .env files | ||
// (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env'); | ||
// } | ||
|
||
$_SERVER += $_ENV; | ||
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; | ||
$_SERVER['APP_DEBUG'] ??= $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; | ||
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; |
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,7 @@ | ||
<?php | ||
|
||
return [ | ||
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], | ||
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], | ||
Odandb\DoctrineCiphersweetEncryptionBundle\OdandbDoctrineCiphersweetEncryptionBundle::class => ['all' => true], | ||
]; |
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,27 @@ | ||
doctrine: | ||
dbal: | ||
default_connection: default | ||
connections: | ||
default: | ||
# configure these for your database server | ||
driver: 'pdo_sqlite' | ||
charset: utf8mb4 | ||
default_table_options: | ||
charset: utf8mb4 | ||
collate: utf8mb4_unicode_ci | ||
url: 'sqlite:///%kernel.project_dir%/var/data.db' | ||
orm: | ||
default_entity_manager: default | ||
auto_generate_proxy_classes: true | ||
entity_managers: | ||
default: | ||
connection: default | ||
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware | ||
auto_mapping: true | ||
mappings: | ||
App: | ||
is_bundle: false | ||
type: annotation | ||
dir: '%kernel.project_dir%/../Model' | ||
prefix: 'Odandb\DoctrineCiphersweetEncryptionBundle\Tests\Model\MyEntity' | ||
alias: App |
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,2 @@ | ||
framework: | ||
test: true |
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,3 @@ | ||
framework: | ||
router: | ||
utf8: true |
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,4 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Odandb\DoctrineCiphersweetEncryptionBundle\Tests\Encryptors; | ||
|
||
|
||
use Odandb\DoctrineCiphersweetEncryptionBundle\Encryptors\CiphersweetEncryptor; | ||
|
||
class CiphersweetEncryptorObservable extends CiphersweetEncryptor | ||
{ | ||
public array $callsCount = [ | ||
'encrypt' => 0, | ||
'decrypt' => 0, | ||
]; | ||
|
||
protected function doEncrypt(string $entitClassName, string $fieldName, string $string, bool $index = true, int $filterBits = self::DEFAULT_FILTER_BITS, bool $fastIndexing = self::DEFAULT_FAST_INDEXING): array | ||
{ | ||
$this->callsCount['encrypt']++; | ||
return parent::doEncrypt($entitClassName, $fieldName, $string, $index, $filterBits, $fastIndexing); | ||
} | ||
|
||
protected function doDecrypt(string $entity_classname, string $fieldName, string $string): string | ||
{ | ||
$this->callsCount['decrypt']++; | ||
return parent::doDecrypt($entity_classname, $fieldName, $string); | ||
} | ||
} |
Oops, something went wrong.