From ddee0d193463221217eaedfa82f6042845bc8953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Tue, 2 Apr 2019 11:01:42 +0200 Subject: [PATCH 1/4] Update compatibility --- composer.json | 19 +++++++++++++------ src/DI/SortableExtension.php | 5 +++-- src/SortableListener.php | 6 +++--- tests/bootstrap.php | 6 +++++- tests/src/EMTest.php | 15 +++++++-------- tests/src/Model/Category.php | 19 +++++++++++++++---- tests/src/Model/DescribedCategory.php | 11 ++++++++--- tests/src/SortableTestCase.phpt | 2 +- 8 files changed, 55 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index 8aaec10..0f64858 100644 --- a/composer.json +++ b/composer.json @@ -10,15 +10,22 @@ "homepage": "http://www.matej21.cz" } ], + "repositories": [ + { + "type": "git", + "url": "https://github.com/paveljurasek/events" + } + ], "require": { - "nette/utils": "~2.4", - "nette/di": "~2.4", - "kdyby/doctrine": "@dev", - "kdyby/events": "@dev" + "php": "^7.1", + "nette/utils": "^3.0", + "nette/di": "^3.0-RC3", + "doctrine/orm": "^2.6", + "kdyby/events": "^4.0" }, "require-dev": { - "nette/tester": "@dev", - "tracy/tracy": "@dev" + "nette/tester": "^2.2", + "tracy/tracy": "^2.6" }, "autoload": { "psr-4": { diff --git a/src/DI/SortableExtension.php b/src/DI/SortableExtension.php index 6f6a235..bb3678e 100644 --- a/src/DI/SortableExtension.php +++ b/src/DI/SortableExtension.php @@ -2,6 +2,7 @@ namespace Librette\Doctrine\Sortable\DI; use Kdyby\Events\DI\EventsExtension; +use Librette\Doctrine\Sortable\SortableListener; use Nette\DI\CompilerExtension; /** @@ -14,8 +15,8 @@ public function loadConfiguration() { $builder = $this->getContainerBuilder(); $builder->addDefinition($this->prefix('sortableListener')) - ->setClass('Librette\Doctrine\Sortable\SortableListener') - ->addTag(EventsExtension::TAG_SUBSCRIBER); + ->setType(SortableListener::class) + ->addTag(EventsExtension::TAG_SUBSCRIBER); } } diff --git a/src/SortableListener.php b/src/SortableListener.php index b4b2001..92e79cc 100644 --- a/src/SortableListener.php +++ b/src/SortableListener.php @@ -5,8 +5,8 @@ use Doctrine\ORM\Event\PreUpdateEventArgs; use Doctrine\ORM\Events; use Doctrine\ORM\NoResultException; -use Kdyby\Doctrine\EntityManager; -use Kdyby\Doctrine\QueryBuilder; +use Doctrine\ORM\EntityManager; +use Doctrine\ORM\QueryBuilder; use Kdyby\Events\Subscriber; use Nette\SmartObject; @@ -124,7 +124,7 @@ public function postPersist(LifecycleEventArgs $args) ->andWhere('e.position >= :from') ->setParameter('from', $pos) ->andWhere('e.id <> :id') - ->setParameter('id', $entity->id) + ->setParameter('id', $entity->getId()) ->set('e.position', 'e.position + 1') ->getQuery()->getResult(); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 80852e3..a8efb99 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -19,5 +19,9 @@ function run(Tester\TestCase $testCase) { - $testCase->run(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : NULL); + if (isset($_SERVER['argv'][2])) { + $testCase->runTest($_SERVER['argv'][2]); + } else { + $testCase->run(); + } } diff --git a/tests/src/EMTest.php b/tests/src/EMTest.php index 11cbdc3..5c383cc 100644 --- a/tests/src/EMTest.php +++ b/tests/src/EMTest.php @@ -2,7 +2,10 @@ namespace LibretteTests\Doctrine\Sortable; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\PDOSqlite\Driver; +use Doctrine\ORM\Configuration; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\SchemaTool; use Kdyby; use Librette\Doctrine\Sortable\SortableListener; @@ -15,25 +18,21 @@ trait EMTest { - /** - * @return Kdyby\Doctrine\EntityManager - */ - protected function createMemoryManager($classNames = NULL, $createSchema = TRUE) + protected function createMemoryManager($classNames = NULL, $createSchema = TRUE): EntityManager { $conf = [ 'driver' => 'pdo_sqlite', 'memory' => TRUE, ]; - $connection = new Kdyby\Doctrine\Connection($conf, new Driver()); - $config = new Kdyby\Doctrine\Configuration(); + $connection = new Connection($conf, new Driver()); + $config = new Configuration(); $cache = new ArrayCache(); $config->setMetadataCacheImpl($cache); $config->setQueryCacheImpl($cache); $config->setProxyDir(TEMP_DIR); $config->setProxyNamespace('TestProxy'); - $config->setDefaultRepositoryClassName('Kdyby\Doctrine\EntityRepository'); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([__DIR__ . '/Model/', VENDOR_DIR], FALSE)); - $em = Kdyby\Doctrine\EntityManager::create($connection, $config); + $em = EntityManager::create($connection, $config); $em->getEventManager()->addEventSubscriber(new SortableListener()); if ($createSchema === FALSE) { return $em; diff --git a/tests/src/Model/Category.php b/tests/src/Model/Category.php index 65e864e..0328eff 100644 --- a/tests/src/Model/Category.php +++ b/tests/src/Model/Category.php @@ -2,8 +2,6 @@ namespace LibretteTests\Doctrine\Sortable\Model; use Doctrine\ORM\Mapping as ORM; -use Kdyby\Doctrine\Entities\Attributes\Identifier; -use Kdyby\Doctrine\Entities\BaseEntity; use Librette\Doctrine\Sortable\ISortable; use Librette\Doctrine\Sortable\ISortableScope; use Librette\Doctrine\Sortable\TSortable; @@ -14,12 +12,18 @@ * @ORM\DiscriminatorMap({"category": "Category", "described": "DescribedCategory"}) * @ORM\DiscriminatorColumn(name="type") */ -class Category extends BaseEntity implements ISortable, ISortableScope +class Category implements ISortable, ISortableScope { - use Identifier; use TSortable; + /** + * @ORM\Id() + * @ORM\GeneratedValue() + * @ORM\Column(type="integer") + * @var int + */ + protected $id; /** * @var string @@ -35,6 +39,13 @@ public function __construct($name) $this->name = $name; } + /** + * @return int + */ + public function getId() + { + return $this->id; + } /** * @return array diff --git a/tests/src/Model/DescribedCategory.php b/tests/src/Model/DescribedCategory.php index 3060843..58e3881 100644 --- a/tests/src/Model/DescribedCategory.php +++ b/tests/src/Model/DescribedCategory.php @@ -2,15 +2,20 @@ namespace LibretteTests\Doctrine\Sortable\Model; use Doctrine\ORM\Mapping as ORM; -use Kdyby\Doctrine\Entities\Attributes\Identifier; -use Kdyby\Doctrine\Entities\BaseEntity; /** * @ORM\Entity */ class DescribedCategory extends Category { - use Identifier; + + /** + * @ORM\Id() + * @ORM\GeneratedValue() + * @ORM\Column(type="integer") + * @var int + */ + protected $id; /** * @var string diff --git a/tests/src/SortableTestCase.phpt b/tests/src/SortableTestCase.phpt index e72891c..9c7a7a4 100644 --- a/tests/src/SortableTestCase.phpt +++ b/tests/src/SortableTestCase.phpt @@ -1,7 +1,7 @@ Date: Fri, 5 Apr 2019 14:55:21 +0200 Subject: [PATCH 2/4] Update dependencies to newly released Nette version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0f64858..70a555b 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ ], "require": { "php": "^7.1", + "nette/di": "^3.0", "nette/utils": "^3.0", - "nette/di": "^3.0-RC3", "doctrine/orm": "^2.6", "kdyby/events": "^4.0" }, From 7c3964105228f7908cdee9e26d2666ed73b54a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Sat, 19 Feb 2022 13:04:32 +0100 Subject: [PATCH 3/4] update php version dep --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 70a555b..a2368cb 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.1", + "php": "^8.0", "nette/di": "^3.0", "nette/utils": "^3.0", "doctrine/orm": "^2.6", From e81ae95368d362de6a2fb0155a8d03d5e1de631b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Sat, 19 Feb 2022 18:29:48 +0100 Subject: [PATCH 4/4] drop dependency on kdyby/events --- composer.json | 5 +++-- src/DI/SortableExtension.php | 10 ++++++---- src/SortableListener.php | 4 ++-- tests/src/EMTest.php | 13 ++++--------- tests/src/SortableTestCase.phpt | 1 + 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index a2368cb..45c3b11 100644 --- a/composer.json +++ b/composer.json @@ -21,11 +21,12 @@ "nette/di": "^3.0", "nette/utils": "^3.0", "doctrine/orm": "^2.6", - "kdyby/events": "^4.0" + "doctrine/annotations": "^1.13" }, "require-dev": { "nette/tester": "^2.2", - "tracy/tracy": "^2.6" + "tracy/tracy": "^2.6", + "symfony/cache": "^6.0" }, "autoload": { "psr-4": { diff --git a/src/DI/SortableExtension.php b/src/DI/SortableExtension.php index bb3678e..0c68677 100644 --- a/src/DI/SortableExtension.php +++ b/src/DI/SortableExtension.php @@ -1,7 +1,6 @@ getContainerBuilder(); - $builder->addDefinition($this->prefix('sortableListener')) - ->setType(SortableListener::class) - ->addTag(EventsExtension::TAG_SUBSCRIBER); + $listener = $builder->addDefinition($this->prefix('sortableListener')) + ->setType(SortableListener::class); + + /** @var \Nette\DI\Definitions\ServiceDefinition $manager */ + $manager = $builder->getByType(\Doctrine\Common\EventManager::class); + $manager->addSetup('addEventSubscriber', [$listener]); } } diff --git a/src/SortableListener.php b/src/SortableListener.php index 92e79cc..224340f 100644 --- a/src/SortableListener.php +++ b/src/SortableListener.php @@ -1,19 +1,19 @@ 'pdo_sqlite', 'memory' => TRUE, ]; - $connection = new Connection($conf, new Driver()); + $connection = new Connection($conf, new \Doctrine\DBAL\Driver\PDO\SQLite\Driver()); $config = new Configuration(); - $cache = new ArrayCache(); - $config->setMetadataCacheImpl($cache); - $config->setQueryCacheImpl($cache); + $cache = new \Symfony\Component\Cache\Adapter\ArrayAdapter(); + $config->setMetadataCache($cache); + $config->setQueryCache($cache); $config->setProxyDir(TEMP_DIR); $config->setProxyNamespace('TestProxy'); $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([__DIR__ . '/Model/', VENDOR_DIR], FALSE)); diff --git a/tests/src/SortableTestCase.phpt b/tests/src/SortableTestCase.phpt index 9c7a7a4..ea6f232 100644 --- a/tests/src/SortableTestCase.phpt +++ b/tests/src/SortableTestCase.phpt @@ -81,6 +81,7 @@ class SortableTestCase extends TestCase $categories[] = $cat2 = new Category('New category 2'); $cat2->setPosition(3); $this->em->persist($cat); + $this->em->flush(); $this->em->persist($cat2); $this->em->flush(); $this->refresh($categories); //todo: update entities without refresh