Skip to content

Commit

Permalink
Merge pull request #3 from ipublikuj/dropnette2
Browse files Browse the repository at this point in the history
Drop Nette 2 support
  • Loading branch information
akadlec authored Feb 13, 2020
2 parents ed1ebcd + 747b9a2 commit d59b04d
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 91 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
vendor
tests/temp
.idea
/vendor
/composer.lock
tests/*/output
6 changes: 2 additions & 4 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ checks:
build:
environment:
php:
version: 7.2
variables:
NETTE: default
version: 7.3

dependencies:
before:
Expand All @@ -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
Expand Down
21 changes: 0 additions & 21 deletions .travis.composer.php

This file was deleted.

14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
language: php

env:
- NETTE=default
- NETTE=~2.4.0

php:
- 7.2
- 7.3

before_install:
# turn off XDebug
- phpenv config-rm xdebug.ini || return 0
- composer self-update

before_script:
- php .travis.composer.php
- composer install --no-interaction --prefer-source --dev
- travis_retry composer install --no-progress --prefer-dist

script:
- vendor/bin/tester -s -p php -c ./tests/php.ini-unix tests

after_failure:
- 'for i in $(find ./tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done'
# Print *.actual content
- for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,35 @@
"extra" : {
"ipub" : {
"configuration" : {
"extensions" : {
"doctrineConsistence" : "IPub\\DoctrineConsistence\\DI\\DoctrineConsistenceExtension"
}
"extension" : "IPub\\DoctrineConsistence\\DI\\DoctrineConsistenceExtension"
}
}
},

"require" : {
"php" : ">=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",

"tracy/tracy" : "~2.4",

"pds/skeleton" : "~1.0",

"nettrine/orm" : "~0.3"
"nettrine/orm" : "~0.3",
"contributte/console" : "~0.7"
},

"autoload" : {
Expand Down
89 changes: 60 additions & 29 deletions src/IPub/DoctrineConsistence/DI/DoctrineConsistenceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand All @@ -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);
}

/**
Expand All @@ -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,
]
);
}
}

Expand All @@ -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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* @license https://www.ipublikuj.eu
* @author Adam Kadlec <adam.kadlec@ipublikuj.eu>
* @package iPublikuj:DoctrineConsistence!
* @subpackage Subscribers
* @subpackage Events
* @since 1.0.0
*
* @date 11.11.19
*/

declare(strict_types = 1);

namespace IPub\DoctrineConsistence;
namespace IPub\DoctrineConsistence\Events;

use Consistence\Doctrine\Enum;

Expand All @@ -27,11 +27,9 @@
* Enum types subscriber
*
* @package iPublikuj:DoctrineConsistence!
* @subpackage Subscribers
* @subpackage Events
*
* @author Adam Kadlec <adam.kadlec@ipublikuj.eu>
*
* @module ipub/users-module
*/
final class EnumSubscriber extends Enum\EnumPostLoadEntityListener implements Common\EventSubscriber
{
Expand Down
8 changes: 5 additions & 3 deletions tests/IPubTests/DoctrineConsistence/ExtensionTest.phpt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* Test: IPub\DoctrineConsistence\Extension
*
* @testCase
*
* @copyright More in license.md
Expand All @@ -26,7 +27,8 @@ use Consistence\Doctrine\Enum\Type;
use Tester;
use Tester\Assert;

use IPub\DoctrineConsistence;
use IPub\DoctrineConsistence\DI;
use IPub\DoctrineConsistence\Events;

require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'bootstrap.php';

Expand All @@ -49,7 +51,7 @@ class ExtensionTest extends Tester\TestCase
Assert::true(Doctrine\DBAL\Types\Type::hasType(Type\IntegerEnumType::NAME));
Assert::true(Doctrine\DBAL\Types\Type::hasType(Type\StringEnumType::NAME));

Assert::true($dic->getService('doctrineConsistence.subscriber') instanceof DoctrineConsistence\EnumSubscriber);
Assert::true($dic->getService('doctrineConsistence.subscriber') instanceof Events\EnumSubscriber);
}

/**
Expand All @@ -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();
}
Expand Down
33 changes: 24 additions & 9 deletions tests/IPubTests/DoctrineConsistence/files/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d59b04d

Please sign in to comment.