Skip to content

Commit

Permalink
tests: updated for MSSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
hrach committed Sep 2, 2017
1 parent 66c91db commit 9402336
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
8 changes: 4 additions & 4 deletions tests/cases/integration/Collection/collection.phpt
Expand Up @@ -46,15 +46,15 @@ class CollectionTest extends DataTestCase
public function testCountOnLimited()
{
$collection = $this->orm->books->findAll();
$collection = $collection->limitBy(1, 1);
$collection = $collection->orderBy('id')->limitBy(1, 1);
Assert::same(1, $collection->count());

$collection = $collection->limitBy(1, 10);
Assert::same(0, $collection->count());


$collection = $this->orm->books->findAll();
$collection = $collection->limitBy(1, 1);
$collection = $collection->orderBy('id')->limitBy(1, 1);
Assert::same(1, $collection->countStored());

$collection = $collection->limitBy(1, 10);
Expand All @@ -64,10 +64,10 @@ class CollectionTest extends DataTestCase

public function testCountOnLimitedWithJoin()
{
$collection = $this->orm->books->findBy(['this->author->name' => 'Writer 1'])->limitBy(5);
$collection = $this->orm->books->findBy(['this->author->name' => 'Writer 1'])->orderBy('id')->limitBy(5);
Assert::same(2, $collection->countStored());

$collection = $this->orm->tagFollowers->findBy(['this->tag->name' => 'Tag 1'])->limitBy(3);
$collection = $this->orm->tagFollowers->findBy(['this->tag->name' => 'Tag 1'])->orderBy('tag')->limitBy(3);
Assert::same(1, $collection->countStored());
}

Expand Down
10 changes: 10 additions & 0 deletions tests/cases/integration/Entity/entity.insert.phpt
Expand Up @@ -41,6 +41,11 @@ class NewEntityTest extends DataTestCase

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

$author = new Author();
$author->id = 555;
$author->name = 'Jon Snow';
Expand All @@ -62,6 +67,11 @@ class NewEntityTest extends DataTestCase

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

$author1 = new Author();
$author1->id = 444;
$author1->name = 'Jon Snow';
Expand Down
Expand Up @@ -11,6 +11,7 @@ use DateTime;
use DateTimeImmutable;
use NextrasTests\Orm\BookCollection;
use NextrasTests\Orm\DataTestCase;
use NextrasTests\Orm\Helper;
use Tester\Assert;
use Tester\Environment;

Expand All @@ -22,7 +23,7 @@ class DbalPersistAutoupdateMapperTest extends DataTestCase
public function setUp()
{
parent::setUp();
if ($this->section === 'array') {
if ($this->section === Helper::SECTION_ARRAY || $this->section === Helper::SECTION_MSSQL) {
Environment::skip('Test is only for Dbal mapper.');
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/cases/integration/Model/model.refreshAll.phpt
Expand Up @@ -10,6 +10,7 @@ namespace NextrasTests\Orm\Integration\Model;
use Nextras\Dbal\Connection;
use Nextras\Orm\InvalidStateException;
use NextrasTests\Orm\DataTestCase;
use NextrasTests\Orm\Helper;
use Tester\Assert;
use Tester\Environment;

Expand Down Expand Up @@ -109,6 +110,11 @@ class ModelRefreshAllTest extends DataTestCase

public function testOHORelations()
{
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 @@ -305,7 +305,7 @@ class RelationshipsManyHasManyCollectionTest extends DataTestCase
$queries = $this->getQueries(function () {
Assert::count(0, $this->tags->getEntitiesForPersistence());

$this->tags->get()->limitBy(1)->fetchAll(); // SELECT JOIN + SELECT TAG
$this->tags->get()->orderBy('id')->limitBy(1)->fetchAll(); // SELECT JOIN + SELECT TAG
// one book from releationship
Assert::count(1, $this->tags->getEntitiesForPersistence());
});
Expand Down
Expand Up @@ -102,7 +102,7 @@ class RelationshipManyHasManyTest extends DataTestCase
{
$book = $this->orm->books->getById(1);
$collection = $book->tags->get();
$collection = $collection->limitBy(1, 1);
$collection = $collection->orderBy('id')->limitBy(1, 1);
Assert::same(1, $collection->count());
}

Expand Down Expand Up @@ -185,6 +185,12 @@ class RelationshipManyHasManyTest extends DataTestCase

public function testSelfReferencing()
{
if ($this->section === Helper::SECTION_MSSQL) {
// An explicit value for the identity column in table 'users' can only be specified when a column list is used and IDENTITY_INSERT is ON.
// http://stackoverflow.com/questions/2148091/syntax-for-inserting-into-a-table-with-no-values
Environment::skip('Inserting dummy rows when no arguments are passed is not supported.');
}

$userA = new User();
$this->orm->persistAndFlush($userA);

Expand Down
Expand Up @@ -22,9 +22,9 @@ class RelationshipsOneHasManyPersistenceTest extends DataTestCase
public function testPersiting()
{
$author1 = $this->e(Author::class);
$this->e(Book::class, ['author' => $author1]);
$this->e(Book::class, ['author' => $author1, 'title' => 'Book XX']);
$author2 = $this->e(Author::class);
$this->e(Book::class, ['author' => $author2]);
$this->e(Book::class, ['author' => $author2, 'title' => 'Book YY']);
$this->orm->authors->persist($author1);
$this->orm->authors->persist($author2);
$this->orm->authors->flush();
Expand Down
Expand Up @@ -147,7 +147,7 @@ class RelationshipOneHasManyTest extends DataTestCase
$counts = [];
$countsStored = [];
foreach ($authors as $author) {
$booksLimited = $author->books->get()->limitBy(2)->orderBy('title', ICollection::DESC);
$booksLimited = $author->books->get()->limitBy(2)->resetOrderBy()->orderBy('title', ICollection::DESC);
foreach ($booksLimited as $book) {
$books[] = $book->id;
}
Expand Down

0 comments on commit 9402336

Please sign in to comment.