Skip to content

Commit

Permalink
Added a test for #14657
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay authored and niden committed May 31, 2020
1 parent b193e4f commit ebf9b0c
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions tests/database/Mvc/Model/Query/GetSqlCest.php
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()
);
}
}

0 comments on commit ebf9b0c

Please sign in to comment.