Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compatibility #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
PavelJurasek marked this conversation as resolved.
Show resolved Hide resolved
"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": {
Expand Down
5 changes: 3 additions & 2 deletions src/DI/SortableExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Librette\Doctrine\Sortable\DI;

use Kdyby\Events\DI\EventsExtension;
use Librette\Doctrine\Sortable\SortableListener;
use Nette\DI\CompilerExtension;

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

}
6 changes: 3 additions & 3 deletions src/SortableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 5 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@

function run(Tester\TestCase $testCase)
{
$testCase->run(isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : NULL);
PavelJurasek marked this conversation as resolved.
Show resolved Hide resolved
if (isset($_SERVER['argv'][2])) {
$testCase->runTest($_SERVER['argv'][2]);
} else {
$testCase->run();
}
}
15 changes: 7 additions & 8 deletions tests/src/EMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
19 changes: 15 additions & 4 deletions tests/src/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -35,6 +39,13 @@ public function __construct($name)
$this->name = $name;
}

/**
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* @return array
Expand Down
11 changes: 8 additions & 3 deletions tests/src/Model/DescribedCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/src/SortableTestCase.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace LibretteTests\Doctrine\Sortable;

use Kdyby\Doctrine\EntityManager;
use Doctrine\ORM\EntityManager;
use LibretteTests\Doctrine\Sortable\Model\Category;
use LibretteTests\Doctrine\Sortable\Model\DescribedCategory;
use Tester\Assert;
Expand Down