diff --git a/.gitignore b/.gitignore index 80a69e0..c0684bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -composer.lock -vendor -tests/temp +.idea +/vendor +/composer.lock +tests/*/output \ No newline at end of file diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d712254..e5389ea 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -4,9 +4,7 @@ checks: build: environment: php: - version: 7.2 - variables: - NETTE: default + version: 7.3 dependencies: before: @@ -16,7 +14,7 @@ build: tests: override: - - command: 'vendor/bin/tester tests -p php -c ./tests/php.ini-unix --coverage build/logs/clover.xml --coverage-src src' + command: 'vendor/bin/tester -s -p php -c ./tests/php.ini-unix tests --coverage build/logs/clover.xml --coverage-src src' coverage: file: build/logs/clover.xml format: php-clover diff --git a/.travis.composer.php b/.travis.composer.php deleted file mode 100644 index 764c713..0000000 --- a/.travis.composer.php +++ /dev/null @@ -1,21 +0,0 @@ -=7.3.0", + "doctrine/orm" : "~2.5", "consistence/consistence-doctrine" : "~2.0", - "nette/di" : "~2.4 || ~3.0" + "nette/di" : "~3.0" }, "require-dev" : { - "nette/bootstrap" : "~2.4 || ~3.0", - "nette/http" : "~2.4 || ~3.0", - "nette/mail" : "~2.4 || ~3.0", - "nette/robot-loader" : "~2.4 || ~3.0", + "nette/bootstrap" : "~3.0", + "nette/http" : "~3.0", + "nette/mail" : "~3.0", + "nette/robot-loader" : "~3.0", "nette/safe-stream" : "~2.3", "nette/tester" : "~2.3", @@ -61,7 +61,8 @@ "pds/skeleton" : "~1.0", - "nettrine/orm" : "~0.3" + "nettrine/orm" : "~0.3", + "contributte/console" : "~0.7" }, "autoload" : { diff --git a/src/IPub/DoctrineConsistence/DI/DoctrineConsistenceExtension.php b/src/IPub/DoctrineConsistence/DI/DoctrineConsistenceExtension.php index edeec3d..4b78f1e 100644 --- a/src/IPub/DoctrineConsistence/DI/DoctrineConsistenceExtension.php +++ b/src/IPub/DoctrineConsistence/DI/DoctrineConsistenceExtension.php @@ -18,10 +18,11 @@ use Nette; use Nette\DI; +use Nette\Schema; use Consistence\Doctrine\Enum\Type; -use IPub\DoctrineConsistence; +use IPub\DoctrineConsistence\Events; /** * Doctrine consistence extension container @@ -33,6 +34,21 @@ */ final class DoctrineConsistenceExtension extends DI\CompilerExtension { + /** + * {@inheritdoc} + */ + public function getConfigSchema() : Schema\Schema + { + return Schema\Expect::structure([ + 'types' => Schema\Expect::structure([ + 'boolean' => Schema\Expect::bool(TRUE), + 'float' => Schema\Expect::bool(TRUE), + 'integer' => Schema\Expect::bool(TRUE), + 'string' => Schema\Expect::bool(TRUE), + ]), + ]); + } + /** * @var array */ @@ -54,20 +70,10 @@ final class DoctrineConsistenceExtension extends DI\CompilerExtension */ public function loadConfiguration() : void { - // Get container builder $builder = $this->getContainerBuilder(); - /** @var array $configuration */ - if (method_exists($this, 'validateConfig')) { - $configuration = $this->validateConfig($this->defaults); - } else { - $configuration = $this->getConfig($this->defaults); - } - if ($configuration['subscriber']['tag']) { - $builder->addDefinition($this->prefix('subscriber')) - ->setType(DoctrineConsistence\EnumSubscriber::class) - ->addTag($configuration['subscriber']['tag']); - } + $builder->addDefinition($this->prefix('subscriber')) + ->setType(Events\EnumSubscriber::class); } /** @@ -77,30 +83,53 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) : void { parent::afterCompile($class); - /** @var array $configuration */ - if (method_exists($this, 'validateConfig')) { - $configuration = $this->validateConfig($this->defaults); - } else { - $configuration = $this->getConfig($this->defaults); - } + $configuration = $this->getConfig(); /** @var Nette\PhpGenerator\Method $initialize */ $initialize = $class->getMethods()['initialize']; - if ($configuration['types']['boolean']) { - $initialize->addBody('if (!Doctrine\DBAL\Types\Type::hasType(\'' . Type\BooleanEnumType::NAME . '\')) { Doctrine\DBAL\Types\Type::addType(\'' . Type\BooleanEnumType::NAME . '\', \'' . Type\BooleanEnumType::class . '\'); }'); + if ($configuration->types->boolean) { + $initialize->addBody( + 'if (!Doctrine\DBAL\Types\Type::hasType(?)) { Doctrine\DBAL\Types\Type::addType(?, ?); }', + [ + Type\BooleanEnumType::NAME, + Type\BooleanEnumType::NAME, + Type\BooleanEnumType::class, + ] + ); } - if ($configuration['types']['float']) { - $initialize->addBody('if (!Doctrine\DBAL\Types\Type::hasType(\'' . Type\FloatEnumType::NAME . '\')) { Doctrine\DBAL\Types\Type::addType(\'' . Type\FloatEnumType::NAME . '\', \'' . Type\FloatEnumType::class . '\'); }'); + if ($configuration->types->float) { + $initialize->addBody( + 'if (!Doctrine\DBAL\Types\Type::hasType(?)) { Doctrine\DBAL\Types\Type::addType(?, ?); }', + [ + Type\FloatEnumType::NAME, + Type\FloatEnumType::NAME, + Type\FloatEnumType::class, + ] + ); } - if ($configuration['types']['integer']) { - $initialize->addBody('if (!Doctrine\DBAL\Types\Type::hasType(\'' . Type\IntegerEnumType::NAME . '\')) { Doctrine\DBAL\Types\Type::addType(\'' . Type\IntegerEnumType::NAME . '\', \'' . Type\IntegerEnumType::class . '\'); }'); + if ($configuration->types->integer) { + $initialize->addBody( + 'if (!Doctrine\DBAL\Types\Type::hasType(?)) { Doctrine\DBAL\Types\Type::addType(?, ?); }', + [ + Type\IntegerEnumType::NAME, + Type\IntegerEnumType::NAME, + Type\IntegerEnumType::class, + ] + ); } - if ($configuration['types']['string']) { - $initialize->addBody('if (!Doctrine\DBAL\Types\Type::hasType(\'' . Type\StringEnumType::NAME . '\')) { Doctrine\DBAL\Types\Type::addType(\'' . Type\StringEnumType::NAME . '\', \'' . Type\StringEnumType::class . '\'); }'); + if ($configuration->types->string) { + $initialize->addBody( + 'if (!Doctrine\DBAL\Types\Type::hasType(?)) { Doctrine\DBAL\Types\Type::addType(?, ?); }', + [ + Type\StringEnumType::NAME, + Type\StringEnumType::NAME, + Type\StringEnumType::class, + ] + ); } } @@ -110,8 +139,10 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class) : void * * @return void */ - public static function register(Nette\Configurator $config, string $extensionName = 'doctrineConsistence') : void - { + public static function register( + Nette\Configurator $config, + string $extensionName = 'doctrineConsistence' + ) : void { $config->onCompile[] = function (Nette\Configurator $config, Nette\DI\Compiler $compiler) use ($extensionName) { $compiler->addExtension($extensionName, new DoctrineConsistenceExtension); }; diff --git a/src/IPub/DoctrineConsistence/EnumSubscriber.php b/src/IPub/DoctrineConsistence/Events/EnumSubscriber.php similarity index 87% rename from src/IPub/DoctrineConsistence/EnumSubscriber.php rename to src/IPub/DoctrineConsistence/Events/EnumSubscriber.php index 435237a..73e6b1d 100644 --- a/src/IPub/DoctrineConsistence/EnumSubscriber.php +++ b/src/IPub/DoctrineConsistence/Events/EnumSubscriber.php @@ -6,7 +6,7 @@ * @license https://www.ipublikuj.eu * @author Adam Kadlec * @package iPublikuj:DoctrineConsistence! - * @subpackage Subscribers + * @subpackage Events * @since 1.0.0 * * @date 11.11.19 @@ -14,7 +14,7 @@ declare(strict_types = 1); -namespace IPub\DoctrineConsistence; +namespace IPub\DoctrineConsistence\Events; use Consistence\Doctrine\Enum; @@ -27,11 +27,9 @@ * Enum types subscriber * * @package iPublikuj:DoctrineConsistence! - * @subpackage Subscribers + * @subpackage Events * * @author Adam Kadlec - * - * @module ipub/users-module */ final class EnumSubscriber extends Enum\EnumPostLoadEntityListener implements Common\EventSubscriber { diff --git a/tests/IPubTests/DoctrineConsistence/ExtensionTest.phpt b/tests/IPubTests/DoctrineConsistence/ExtensionTest.phpt index f091672..45c573a 100644 --- a/tests/IPubTests/DoctrineConsistence/ExtensionTest.phpt +++ b/tests/IPubTests/DoctrineConsistence/ExtensionTest.phpt @@ -1,6 +1,7 @@ getService('doctrineConsistence.subscriber') instanceof DoctrineConsistence\EnumSubscriber); + Assert::true($dic->getService('doctrineConsistence.subscriber') instanceof Events\EnumSubscriber); } /** @@ -67,7 +69,7 @@ class ExtensionTest extends Tester\TestCase $config->addConfig(__DIR__ . DS . 'files' . DS . 'config.neon'); - DoctrineConsistence\DI\DoctrineConsistenceExtension::register($config); + DI\DoctrineConsistenceExtension::register($config); return $config->createContainer(); } diff --git a/tests/IPubTests/DoctrineConsistence/files/config.neon b/tests/IPubTests/DoctrineConsistence/files/config.neon index 967606e..9158e3b 100644 --- a/tests/IPubTests/DoctrineConsistence/files/config.neon +++ b/tests/IPubTests/DoctrineConsistence/files/config.neon @@ -2,19 +2,34 @@ php: date.timezone: Europe/Prague extensions: - dbal: Nettrine\DBAL\DI\DbalExtension - orm: Nettrine\ORM\DI\OrmExtension - orm.annotations: Nettrine\ORM\DI\OrmAnnotationsExtension - orm.cache: Nettrine\ORM\DI\OrmCacheExtension + contributteConsole : Contributte\Console\DI\ConsoleExtension(%consoleMode%) + nettrineAnnotations : Nettrine\Annotations\DI\AnnotationsExtension + nettrineCache : Nettrine\Cache\DI\CacheExtension + nettrineDbal : Nettrine\DBAL\DI\DbalExtension + nettrineOrm : Nettrine\ORM\DI\OrmExtension + nettrineOrmAnnotations : Nettrine\ORM\DI\OrmAnnotationsExtension + nettrineOrmConsole : Nettrine\ORM\DI\OrmConsoleExtension + nettrineOrmCache : Nettrine\ORM\DI\OrmCacheExtension -dbal: +contributteConsole: + name: iPublikuj:Packages! + version: '1.0' + catchExceptions: true + autoExit: true + url: http://example.com + lazy: false + helperSet: \Symfony\Component\Console\Helper\HelperSet + helpers: [] + +nettrineDbal: connection: host: 127.0.0.1 driver: pdo_sqlite memory: true -orm.annotations: - defaultCache: array +nettrineAnnotations: + debug: %debugMode% -orm.cache: - defaultDriver: array +nettrineOrm: + configuration: + proxyDir : %tempDir%/cache/doctrine.proxies