-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b193e4f
commit ebf9b0c
Showing
1 changed file
with
95 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Phalcon Framework. | ||
* | ||
* (c) Phalcon Team <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phalcon\Test\Database\Mvc\Model\Query; | ||
|
||
use DatabaseTester; | ||
use Phalcon\Mvc\Model\Query; | ||
use Phalcon\Storage\Exception; | ||
use Phalcon\Test\Fixtures\Migrations\InvoicesMigration; | ||
use Phalcon\Test\Fixtures\Traits\DiTrait; | ||
use Phalcon\Test\Fixtures\Traits\RecordsTrait; | ||
use Phalcon\Test\Models\Invoices; | ||
|
||
class GetSqlCest | ||
{ | ||
use DiTrait; | ||
use RecordsTrait; | ||
|
||
/** | ||
* @var InvoicesMigration | ||
*/ | ||
private $invoiceMigration; | ||
|
||
/** | ||
* Executed before each test | ||
* | ||
* @param DatabaseTester $I | ||
* @return void | ||
*/ | ||
public function _before(DatabaseTester $I): void | ||
{ | ||
try { | ||
$this->setNewFactoryDefault(); | ||
} catch (Exception $e) { | ||
$I->fail($e->getMessage()); | ||
} | ||
|
||
$this->setDatabase($I); | ||
|
||
$this->invoiceMigration = new InvoicesMigration($I->getConnection()); | ||
} | ||
|
||
/** | ||
* Tests Phalcon\Mvc\Model\Query :: getSql() - Issue 14657 | ||
* | ||
* @param DatabaseTester $I | ||
* | ||
* @author Phalcon Team <[email protected]> | ||
* @since 2020-05-06 | ||
* @issue 14657 | ||
* | ||
* @group mysql | ||
* @group pgsql | ||
* @group sqlite | ||
*/ | ||
public function mvcModelQueryGetSql(DatabaseTester $I) | ||
{ | ||
$I->wantToTest('Mvc\Model\Query :: getSql() - #14657'); | ||
|
||
$phql = sprintf('SELECT i.inv_id, i.inv_cst_id FROM [%s] AS i', Invoices::class); | ||
|
||
$query = new Query($phql, $this->container); | ||
|
||
if ('mysql' === $this->invoiceMigration->getDriverName()) { | ||
$sql = sprintf( | ||
'SELECT `i`.`inv_id` AS `inv_id`, `i`.`inv_cst_id` AS `inv_cst_id` FROM `%s` AS `i`', | ||
$this->invoiceMigration->getTable() | ||
); | ||
} else { | ||
$sql = sprintf( | ||
'SELECT "i"."inv_id" AS "inv_id", "i"."inv_cst_id" AS "inv_cst_id" FROM "%s" AS "i"', | ||
$this->invoiceMigration->getTable() | ||
); | ||
} | ||
|
||
$I->assertEquals( | ||
[ | ||
'sql' => $sql, | ||
'bind' => [], | ||
'bindTypes' => [], | ||
], | ||
$query->getSql() | ||
); | ||
} | ||
} |