Skip to content

Commit

Permalink
Merge branch 'iconnection'
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Dec 14, 2017
2 parents 90c6fa2 + 091d671 commit b9cbf31
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ parameters:
- '#Accessing property \$\w+ on possibly null value of type Nextras\\Orm\\Entity\\Reflection\\PropertyRelationshipMetadata\|null#'
# https://github.com/phpstan/phpstan/issues/587
- '#Constructor of class Nextras\\Orm\\Bridges\\NetteDI\\DIRepositoryFinder has an unused parameter \$modelClass\.#'
# we need a local mute
- '#Calling method \w+\(\) on possibly null value of type Nextras\\Dbal\\Result\\Result\|null\.#'
- '#Calling method \w+\(\) on possibly null value of type Nextras\\Dbal\\Result\\Row\|null\.#'
6 changes: 3 additions & 3 deletions src/Mapper/Dbal/DbalCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Nextras\Orm\Mapper\Dbal;

use Iterator;
use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Dbal\QueryBuilder\QueryBuilder;
use Nextras\Orm\Collection\EntityIterator;
use Nextras\Orm\Collection\Helpers\FetchPairsHelper;
Expand Down Expand Up @@ -37,7 +37,7 @@ class DbalCollection implements ICollection
/** @var DbalMapper */
protected $mapper;

/** @var Connection */
/** @var IConnection */
protected $connection;

/** @var QueryBuilder */
Expand All @@ -56,7 +56,7 @@ class DbalCollection implements ICollection
protected $entityFetchEventTriggered = false;


public function __construct(DbalMapper $mapper, Connection $connection, QueryBuilder $queryBuilder)
public function __construct(DbalMapper $mapper, IConnection $connection, QueryBuilder $queryBuilder)
{
$this->mapper = $mapper;
$this->connection = $connection;
Expand Down
6 changes: 3 additions & 3 deletions src/Mapper/Dbal/DbalMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Nextras\Orm\Mapper\Dbal;

use Nette\Caching\Cache;
use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Dbal\Platforms\IPlatform;
use Nextras\Dbal\Platforms\PostgreSqlPlatform;
use Nextras\Dbal\QueryBuilder\QueryBuilder;
Expand All @@ -31,7 +31,7 @@

class DbalMapper extends BaseMapper
{
/** @var Connection */
/** @var IConnection */
protected $connection;

/** @var Cache */
Expand All @@ -44,7 +44,7 @@ class DbalMapper extends BaseMapper
private $mapperCoordinator;


public function __construct(Connection $connection, DbalMapperCoordinator $mapperCoordinator, Cache $cache)
public function __construct(IConnection $connection, DbalMapperCoordinator $mapperCoordinator, Cache $cache)
{
$key = md5(json_encode($connection->getConfig()));
$this->connection = $connection;
Expand Down
6 changes: 3 additions & 3 deletions src/Mapper/Dbal/DbalMapperCoordinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@

namespace Nextras\Orm\Mapper\Dbal;

use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;


class DbalMapperCoordinator
{
/** @var Connection */
/** @var IConnection */
private $connection;

/** @var bool */
private $transactionActive = false;


public function __construct(Connection $connection)
public function __construct(IConnection $connection)
{
$this->connection = $connection;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Mapper/Dbal/RelationshipMapperManyHasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Nextras\Orm\Mapper\Dbal;

use Iterator;
use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Dbal\QueryBuilder\QueryBuilder;
use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Collection\MultiEntityIterator;
Expand All @@ -22,7 +22,7 @@

class RelationshipMapperManyHasMany implements IRelationshipMapperManyHasMany
{
/** @var Connection */
/** @var IConnection */
protected $connection;

/** @var PropertyMetadata */
Expand Down Expand Up @@ -50,7 +50,7 @@ class RelationshipMapperManyHasMany implements IRelationshipMapperManyHasMany
private $mapperCoordinator;


public function __construct(Connection $connection, DbalMapper $mapperOne, DbalMapper $mapperTwo, DbalMapperCoordinator $mapperCoordinator, PropertyMetadata $metadata)
public function __construct(IConnection $connection, DbalMapper $mapperOne, DbalMapper $mapperTwo, DbalMapperCoordinator $mapperCoordinator, PropertyMetadata $metadata)
{
assert($metadata->relationship !== null);
$this->connection = $connection;
Expand Down
6 changes: 3 additions & 3 deletions src/Mapper/Dbal/RelationshipMapperManyHasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use ArrayIterator;
use Iterator;
use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Dbal\QueryBuilder\QueryBuilder;
use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Collection\MultiEntityIterator;
Expand All @@ -23,7 +23,7 @@

class RelationshipMapperManyHasOne implements IRelationshipMapper
{
/** @var Connection */
/** @var IConnection */
protected $connection;

/** @var PropertyMetadata */
Expand All @@ -36,7 +36,7 @@ class RelationshipMapperManyHasOne implements IRelationshipMapper
private $targetMapper;


public function __construct(Connection $connection, DbalMapper $targetMapper, PropertyMetadata $metadata)
public function __construct(IConnection $connection, DbalMapper $targetMapper, PropertyMetadata $metadata)
{
$this->connection = $connection;
$this->metadata = $metadata;
Expand Down
6 changes: 3 additions & 3 deletions src/Mapper/Dbal/RelationshipMapperOneHasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Nextras\Orm\Mapper\Dbal;

use Iterator;
use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Dbal\QueryBuilder\QueryBuilder;
use Nextras\Orm\Collection\ICollection;
use Nextras\Orm\Collection\MultiEntityIterator;
Expand All @@ -21,7 +21,7 @@

class RelationshipMapperOneHasMany implements IRelationshipMapper
{
/** @var Connection */
/** @var IConnection */
protected $connection;

/** @var PropertyMetadata */
Expand All @@ -40,7 +40,7 @@ class RelationshipMapperOneHasMany implements IRelationshipMapper
protected $cacheCounts;


public function __construct(Connection $connection, DbalMapper $targetMapper, PropertyMetadata $metadata)
public function __construct(IConnection $connection, DbalMapper $targetMapper, PropertyMetadata $metadata)
{
assert($metadata->relationship !== null);
$this->connection = $connection;
Expand Down
4 changes: 2 additions & 2 deletions src/Mapper/Dbal/StorageReflection/StorageReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use Nette\Caching\Cache;
use Nette\SmartObject;
use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Dbal\Platforms\CachedPlatform;
use Nextras\Dbal\Platforms\IPlatform;
use Nextras\Orm;
Expand Down Expand Up @@ -50,7 +50,7 @@ abstract class StorageReflection implements IStorageReflection
protected $platform;


public function __construct(Connection $connection, $storageName, array $entityPrimaryKey, Cache $cache)
public function __construct(IConnection $connection, $storageName, array $entityPrimaryKey, Cache $cache)
{
$this->platform = new CachedPlatform($connection->getPlatform(), $cache->derive('db_reflection'));
$this->storageName = $storageName;
Expand Down
8 changes: 3 additions & 5 deletions tests/cases/integration/Entity/entity.insert.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace NextrasTests\Orm\Integration\Entity;

use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Orm\Mapper\Dbal\DbalMapper;
use NextrasTests\Orm\Author;
use NextrasTests\Orm\DataTestCase;
Expand All @@ -20,7 +20,6 @@ $dic = require_once __DIR__ . '/../../../bootstrap.php';

class NewEntityTest extends DataTestCase
{

public function testInsert()
{
$author = new Author();
Expand All @@ -42,7 +41,7 @@ class NewEntityTest extends DataTestCase
public function testInsertWithPrimaryKey()
{
if ($this->section === Helper::SECTION_MSSQL) {
$connection = $this->container->getByType(Connection::class);
$connection = $this->container->getByType(IConnection::class);
$connection->query('SET IDENTITY_INSERT authors ON;');
}

Expand All @@ -68,7 +67,7 @@ class NewEntityTest extends DataTestCase
public function testDuplicatePrimaryKey()
{
if ($this->section === Helper::SECTION_MSSQL) {
$connection = $this->container->getByType(Connection::class);
$connection = $this->container->getByType(IConnection::class);
$connection->query('SET IDENTITY_INSERT authors ON;');
}

Expand Down Expand Up @@ -104,7 +103,6 @@ class NewEntityTest extends DataTestCase
Assert::false($author2->isModified());
Assert::same(445, $author2->getPersistedId());
}

}


Expand Down
17 changes: 8 additions & 9 deletions tests/cases/integration/Model/model.refreshAll.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace NextrasTests\Orm\Integration\Model;

use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Orm\InvalidStateException;
use NextrasTests\Orm\DataTestCase;
use NextrasTests\Orm\Helper;
Expand Down Expand Up @@ -39,8 +39,8 @@ class ModelRefreshAllTest extends DataTestCase
Assert::same('Book 1', $book1->title);
$book2 = $this->orm->books->getById(2);
Assert::same('Book 2', $book2->title);
$this->container->getByType(Connection::class)->query('UPDATE %table SET %set WHERE id = %i', 'books', ['title' => 'foo'], 1);
$this->container->getByType(Connection::class)->query('UPDATE %table SET %set WHERE id = %i', 'books', ['title' => 'bar'], 2);
$this->container->getByType(IConnection::class)->query('UPDATE %table SET %set WHERE id = %i', 'books', ['title' => 'foo'], 1);
$this->container->getByType(IConnection::class)->query('UPDATE %table SET %set WHERE id = %i', 'books', ['title' => 'bar'], 2);

Assert::same('Book 1', $book1->title);
Assert::same('Book 2', $book2->title);
Expand All @@ -59,7 +59,7 @@ class ModelRefreshAllTest extends DataTestCase
$book2 = $this->orm->books->getById(2);
Assert::count(2, iterator_to_array($book2->tags));

$this->container->getByType(Connection::class)->query('DELETE FROM %table WHERE book_id = %i AND tag_id = %i', 'books_x_tags', 2, 3);
$this->container->getByType(IConnection::class)->query('DELETE FROM %table WHERE book_id = %i AND tag_id = %i', 'books_x_tags', 2, 3);

Assert::count(2, iterator_to_array($book2->tags));
$this->orm->refreshAll();
Expand All @@ -73,7 +73,7 @@ class ModelRefreshAllTest extends DataTestCase
$tag3 = $this->orm->tags->getById(3);

Assert::count(2, iterator_to_array($tag3->books));
$this->container->getByType(Connection::class)->query('DELETE FROM %table WHERE book_id = %i AND tag_id = %i', 'books_x_tags', 2, 3);
$this->container->getByType(IConnection::class)->query('DELETE FROM %table WHERE book_id = %i AND tag_id = %i', 'books_x_tags', 2, 3);

Assert::count(2, iterator_to_array($tag3->books));
$this->orm->refreshAll();
Expand All @@ -91,7 +91,7 @@ class ModelRefreshAllTest extends DataTestCase
Assert::count(2, $publisher1->books);
Assert::count(1, $publisher2->books);

$this->container->getByType(Connection::class)->query('UPDATE %table SET %set WHERE id = %i', 'books', ['publisher_id' => 2], 1);
$this->container->getByType(IConnection::class)->query('UPDATE %table SET %set WHERE id = %i', 'books', ['publisher_id' => 2], 1);

Assert::same($publisher1, $book1->publisher);
Assert::count(2, $publisher1->books);
Expand All @@ -110,12 +110,11 @@ class ModelRefreshAllTest extends DataTestCase

public function testOHORelations()
{
$connection = $this->container->getByType(IConnection::class);
if ($this->section === Helper::SECTION_MSSQL) {
$connection = $this->container->getByType(Connection::class);
$connection->query('SET IDENTITY_INSERT eans ON;');
}

$connection = $this->container->getByType(Connection::class);
$connection->query('INSERT INTO %table %values', 'eans', ['id' => 1, 'code' => '111']);
$connection->query('UPDATE %table SET %set WHERE id = %i', 'books', ['ean_id' => 1], 1);

Expand Down Expand Up @@ -148,7 +147,7 @@ class ModelRefreshAllTest extends DataTestCase
{
$book1 = $this->orm->books->getById(1);
Assert::same(1, $book1->getPersistedId());
$this->container->getByType(Connection::class)->query('DELETE FROM %table WHERE id = %i', 'books', 1);
$this->container->getByType(IConnection::class)->query('DELETE FROM %table WHERE id = %i', 'books', 1);
Assert::same(1, $book1->getPersistedId());

$this->orm->refreshAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace NextrasTests\Orm\Integration\Relationships;

use Mockery;
use Nextras\Dbal\Connection;
use Nextras\Dbal\IConnection;
use Nextras\Orm\Relationships\ManyHasMany;
use NextrasTests\Orm\Author;
use NextrasTests\Orm\Book;
Expand Down Expand Up @@ -94,7 +94,7 @@ class EntityRelationshipsTest extends DataTestCase
}

$queries = [];
$connection = $this->container->getByType(Connection::class);
$connection = $this->container->getByType(IConnection::class);
$connection->onQuery[] = function ($_, $query) use (& $queries) {
$queries[$query] = isset($queries[$query]) ? $queries[$query] : 1;
};
Expand Down
Loading

0 comments on commit b9cbf31

Please sign in to comment.