-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #447: fix wrong adding table prefix on join
- Loading branch information
Showing
9 changed files
with
282 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
tests/ORM/Functional/Driver/Common/Integration/Case398/CaseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398; | ||
|
||
use Cycle\Database\Injection\Fragment; | ||
use Cycle\ORM\Select; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\BaseTest; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\Entity\Product; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\IntegrationTestTrait; | ||
use Cycle\ORM\Tests\Traits\TableTrait; | ||
|
||
abstract class CaseTest extends BaseTest | ||
{ | ||
use IntegrationTestTrait; | ||
use TableTrait; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->makeTables(); | ||
$this->fillData(); | ||
|
||
$this->loadSchema(__DIR__ . '/schema.php'); | ||
} | ||
|
||
public function testSelectWithJoin(): void | ||
{ | ||
$select = new Select($this->orm, Product::class); | ||
$product = $select | ||
->join('inner', 'filter_products', 'fp')->on('id', 'fp.product_id') | ||
->where(new Fragment('fp.filter_id = ?', 5)) | ||
->fetchOne(); | ||
|
||
$this->assertSame('Product-2', $product->title); | ||
} | ||
|
||
public function testSelectWithInnerJoin(): void | ||
{ | ||
$select = new Select($this->orm, Product::class); | ||
$product = $select | ||
->innerJoin('filter_products', 'fp')->on('id', 'fp.product_id') | ||
->where(new Fragment('fp.filter_id = ?', 5)) | ||
->fetchOne(); | ||
|
||
$this->assertSame('Product-2', $product->title); | ||
} | ||
|
||
public function testSelectWithRightJoin(): void | ||
{ | ||
$select = new Select($this->orm, Product::class); | ||
$product = $select | ||
->rightJoin('filter_products', 'fp')->on('id', 'fp.product_id') | ||
->where(new Fragment('fp.filter_id = ?', 5)) | ||
->fetchOne(); | ||
|
||
$this->assertSame('Product-2', $product->title); | ||
} | ||
|
||
public function testSelectWithLeftJoin(): void | ||
{ | ||
$select = new Select($this->orm, Product::class); | ||
$product = $select | ||
->leftJoin('filter_products', 'fp')->on('id', 'fp.product_id') | ||
->where(new Fragment('fp.filter_id = ?', 5)) | ||
->fetchOne(); | ||
|
||
$this->assertSame('Product-2', $product->title); | ||
} | ||
|
||
public function testSelectWithFullJoin(): void | ||
{ | ||
$select = new Select($this->orm, Product::class); | ||
$product = $select | ||
->fullJoin('filter_products', 'fp')->on('id', 'fp.product_id') | ||
->where(new Fragment('fp.filter_id = ?', 5)) | ||
->fetchOne(); | ||
|
||
$this->assertSame('Product-2', $product->title); | ||
} | ||
|
||
private function makeTables(): void | ||
{ | ||
$this->makeTable('products', [ | ||
'id' => 'primary', | ||
'title' => 'string', | ||
]); | ||
|
||
$this->makeTable('filter_products', [ | ||
'filter_id' => 'int', | ||
'product_id' => 'int', | ||
], pk: ['filter_id', 'product_id']); | ||
} | ||
|
||
private function fillData(): void | ||
{ | ||
$this->getDatabase()->table('products')->insertMultiple( | ||
['title'], | ||
[['Product-1'], ['Product-2'], ['Product-3']], | ||
); | ||
|
||
$this->getDatabase()->table('filter_products')->insertMultiple( | ||
['filter_id', 'product_id'], | ||
[[1, 1], [5, 2], [6, 3]], | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ORM/Functional/Driver/Common/Integration/Case398/Entity/FilterProduct.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\Entity; | ||
|
||
class FilterProduct | ||
{ | ||
public const ROLE = 'filter_product'; | ||
|
||
public function __construct( | ||
public int $productId, | ||
public int $filterId, | ||
) { | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Functional/Driver/Common/Integration/Case398/Entity/Product.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\Entity; | ||
|
||
class Product | ||
{ | ||
public const ROLE = 'product'; | ||
|
||
public int $id; | ||
|
||
public function __construct( | ||
public string $title, | ||
) { | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/ORM/Functional/Driver/Common/Integration/Case398/schema.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Cycle\ORM\Mapper\Mapper; | ||
use Cycle\ORM\SchemaInterface as Schema; | ||
use Cycle\ORM\Select\Source; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\Entity\FilterProduct; | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\Entity\Product; | ||
|
||
return [ | ||
Product::ROLE => [ | ||
Schema::ENTITY => Product::class, | ||
Schema::SOURCE => Source::class, | ||
Schema::DATABASE => 'default', | ||
Schema::TABLE => 'products', | ||
Schema::PRIMARY_KEY => ['id'], | ||
Schema::COLUMNS => [ | ||
'id' => 'id', | ||
'title' => 'title', | ||
], | ||
Schema::RELATIONS => [], | ||
Schema::TYPECAST => [ | ||
'id' => 'int', | ||
], | ||
Schema::SCHEMA => [], | ||
], | ||
FilterProduct::ROLE => [ | ||
Schema::ENTITY => FilterProduct::class, | ||
Schema::SOURCE => Source::class, | ||
Schema::DATABASE => 'default', | ||
Schema::MAPPER => Mapper::class, | ||
Schema::TABLE => 'filter_products_table', | ||
Schema::PRIMARY_KEY => ['product_id', 'filter_id'], | ||
Schema::COLUMNS => [ | ||
'id' => 'id', | ||
'filterId' => 'filter_id', | ||
'productId' => 'product_id', | ||
], | ||
Schema::RELATIONS => [ | ||
], | ||
Schema::TYPECAST => [ | ||
'productId' => 'int', | ||
'filterId' => 'int', | ||
], | ||
Schema::SCHEMA => [], | ||
], | ||
]; |
22 changes: 22 additions & 0 deletions
22
tests/ORM/Functional/Driver/MySQL/Integration/Case398/CaseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\MySQL\Integration\Case398; | ||
|
||
// phpcs:ignore | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\CaseTest as CommonClass; | ||
|
||
/** | ||
* @group driver | ||
* @group driver-mysql | ||
*/ | ||
class CaseTest extends CommonClass | ||
{ | ||
public const DRIVER = 'mysql'; | ||
|
||
public function testSelectWithFullJoin(): void | ||
{ | ||
$this->markTestSkipped('MySQL does not support FULL JOIN'); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Functional/Driver/Postgres/Integration/Case398/CaseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\Postgres\Integration\Case398; | ||
|
||
// phpcs:ignore | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\CaseTest as CommonClass; | ||
|
||
/** | ||
* @group driver | ||
* @group driver-postgres | ||
*/ | ||
class CaseTest extends CommonClass | ||
{ | ||
public const DRIVER = 'postgres'; | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/ORM/Functional/Driver/SQLServer/Integration/Case398/CaseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\SQLServer\Integration\Case398; | ||
|
||
// phpcs:ignore | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\CaseTest as CommonClass; | ||
|
||
/** | ||
* @group driver | ||
* @group driver-sqlserver | ||
*/ | ||
class CaseTest extends CommonClass | ||
{ | ||
public const DRIVER = 'sqlserver'; | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/ORM/Functional/Driver/SQLite/Integration/Case398/CaseTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cycle\ORM\Tests\Functional\Driver\SQLite\Integration\Case398; | ||
|
||
// phpcs:ignore | ||
use Cycle\ORM\Tests\Functional\Driver\Common\Integration\Case398\CaseTest as CommonClass; | ||
|
||
/** | ||
* @group driver | ||
* @group driver-sqlite | ||
*/ | ||
class CaseTest extends CommonClass | ||
{ | ||
public const DRIVER = 'sqlite'; | ||
|
||
public function testSelectWithFullJoin(): void | ||
{ | ||
$this->markTestSkipped('SQLite does not support FULL JOIN'); | ||
} | ||
|
||
public function testSelectWithRightJoin(): void | ||
{ | ||
$this->markTestSkipped('SQLite does not support RIGHT JOIN'); | ||
} | ||
} |