Skip to content

Commit

Permalink
Merge pull request #1 from ipublikuj/drop-kdyby
Browse files Browse the repository at this point in the history
Feature: Dropping kdyby/doctrine
  • Loading branch information
akadlec authored Nov 10, 2019
2 parents 3683f31 + cafdad2 commit e4537ae
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 34 deletions.
21 changes: 21 additions & 0 deletions .travis.composer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

$version = getenv('NETTE');

if (!$version || $version == 'default') {
exit;
}

echo "Nette version " . $version . PHP_EOL;

$file = __DIR__ . '/composer.json';

$content = file_get_contents($file);

$composer = json_decode($content, TRUE);

$composer['require']['nette/di'] = $version;

$content = json_encode($composer);

file_put_contents($file, $content);
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ before_install:
- composer self-update

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

script:
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"ipub",
"ipublikuj"
],

"homepage" : "https://github.com/iPublikuj/doctrine-timestampable",

"license" : [
"GPL-2.0",
"GPL-3.0"
Expand Down Expand Up @@ -56,13 +58,11 @@
"nette/safe-stream" : "~2.3",
"nette/tester" : "~2.3",

"nette/http" : "~2.4",

"tracy/tracy" : "~2.4",

"pds/skeleton" : "~1.0",

"kdyby/doctrine" : "^3.3"
"nettrine/orm" : "~0.3"
},

"autoload" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,25 @@ final class DoctrineTimestampableExtension extends DI\CompilerExtension
*/
public function loadConfiguration() : void
{
$config = $this->getConfig($this->defaults);
// Get container builder
$builder = $this->getContainerBuilder();

Utils\Validators::assert($config['lazyAssociation'], 'bool', 'lazyAssociation');
Utils\Validators::assert($config['autoMapField'], 'bool', 'autoMapField');
Utils\Validators::assert($config['dbFieldType'], 'string', 'dbFieldType');
// Merge extension default config
$this->setConfig(DI\Config\Helpers::merge($this->config, DI\Helpers::expand($this->defaults, $builder->parameters)));

// Get extension configuration
$configuration = $this->getConfig();

Utils\Validators::assert($configuration['lazyAssociation'], 'bool', 'lazyAssociation');
Utils\Validators::assert($configuration['autoMapField'], 'bool', 'autoMapField');
Utils\Validators::assert($configuration['dbFieldType'], 'string', 'dbFieldType');

$builder->addDefinition($this->prefix('configuration'))
->setType(DoctrineTimestampable\Configuration::class)
->setArguments([
$config['lazyAssociation'],
$config['autoMapField'],
$config['dbFieldType'],
$configuration['lazyAssociation'],
$configuration['autoMapField'],
$configuration['dbFieldType'],
]);

$builder->addDefinition($this->prefix('driver'))
Expand All @@ -83,7 +89,7 @@ public function beforeCompile() : void

$builder = $this->getContainerBuilder();

$builder->getDefinition($builder->getByType('Doctrine\ORM\EntityManagerInterface') ?: 'doctrine.default.entityManager')
$builder->getDefinition($builder->getByType('Doctrine\ORM\EntityManagerInterface', TRUE))
->addSetup('?->getEventManager()->addEventSubscriber(?)', ['@self', $builder->getDefinition($this->prefix('subscriber'))]);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/IPubTests/DoctrineTimestampable/TimestampableTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use Tester\Assert;

use Doctrine\ORM;

use Nettrine;

use IPub\DoctrineTimestampable;
use IPub\DoctrineTimestampable\Mapping;

Expand Down Expand Up @@ -60,7 +62,7 @@ class TimestampableTest extends Tester\TestCase
parent::setUp();

$this->container = $this->createContainer();
$this->em = $this->container->getByType('Kdyby\Doctrine\EntityManager');
$this->em = $this->container->getByType(Nettrine\ORM\EntityManagerDecorator::class);
}

public function testCreate() : void
Expand Down
32 changes: 13 additions & 19 deletions tests/IPubTests/DoctrineTimestampable/files/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@ php:
date.timezone: Europe/Prague

extensions:
annotations: Kdyby\Annotations\DI\AnnotationsExtension
doctrine: Kdyby\Doctrine\DI\OrmExtension
console: Kdyby\Console\DI\ConsoleExtension
events: Kdyby\Events\DI\EventsExtension
dbal: Nettrine\DBAL\DI\DbalExtension
orm: Nettrine\ORM\DI\OrmExtension
orm.annotations: Nettrine\ORM\DI\OrmAnnotationsExtension
orm.cache: Nettrine\ORM\DI\OrmCacheExtension

services:
cacheStorage:
class: Nette\Caching\Storages\MemoryStorage
dbal:
connection:
host: 127.0.0.1
driver: pdo_sqlite
memory: true

annotations:
cache: array
orm.annotations:
defaultCache: array

console:
url: http://example.com

doctrine:
metadataCache: array
queryCache: array
resultCache: array
hydrationCache: array
driver: pdo_sqlite
memory: true
orm.cache:
defaultDriver: array
6 changes: 3 additions & 3 deletions tests/IPubTests/DoctrineTimestampable/files/entities.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
doctrine:
metadata:
IPubTests\DoctrineTimestampable: %appDir%IPubTests/DoctrineTimestampable/models
orm.annotations:
paths:
- %appDir%IPubTests/DoctrineTimestampable/models

0 comments on commit e4537ae

Please sign in to comment.