Skip to content

Commit

Permalink
refactor(builder): refactor from zephir.
Browse files Browse the repository at this point in the history
  • Loading branch information
noone-silent committed Jul 30, 2024
1 parent fd23ec3 commit 54a3b21
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 68 deletions.
4 changes: 2 additions & 2 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Path to sources
#sonar.sources=.
sonar.exclusions=./tests/*
sonar.sources=src/
#sonar.exclusions=./tests/*,**tests/**,tests/*,tests/**
#sonar.inclusions=

# Path to tests
Expand Down
91 changes: 45 additions & 46 deletions tests/_data/assets/schemas/mysql.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


drop table if exists `album`;

CREATE TABLE `album` (
`id` int(11) UNSIGNED not null AUTO_INCREMENT,
`name` varchar(100) not null collate 'utf8mb4_unicode_520_ci',
Expand All @@ -13,11 +13,11 @@ CREATE TABLE `album` (
constraint `album_ibfk_1` foreign key (`album_id`) references `album` (`id`) on update cascade on delete cascade,
constraint `album_ibfk_2` foreign key (`photo_id`) references `photo` (`id`) on update cascade on delete set null
) collate='utf8mb4_unicode_520_ci';



drop table if exists `album_photo`;

CREATE TABLE `album_photo` (
`id` int(11) unsigned not null AUTO_INCREMENT,
`photo_id` int(11) unsigned null default null,
Expand All @@ -30,65 +30,65 @@ CREATE TABLE `album_photo` (
constraint `c_fk_album_photo_album_id` foreign key (`album_id`) references `album` (`id`) on update cascade on delete cascade,
constraint `c_fk_album_photo_photo_id` foreign key (`photo_id`) references `photo` (`id`) on update cascade on delete cascade
) collate='utf8mb4_unicode_520_ci';



drop table if exists `complex_default`;

create table complex_default
(
`id` int(10) auto_increment primary key,
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`updated` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated_null` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
);



drop table if exists `co_customers_defaults`;

create table co_customers_defaults
(
`cst_id` int(10) auto_increment primary key,
`cst_status_flag` tinyint(1) not null DEFAULT 1,
`cst_name_last` varchar(100) not null DEFAULT 'cst_default_lastName',
`cst_name_first` varchar(50) not null DEFAULT 'cst_default_firstName'
);

create index co_customers_defaults_cst_status_flag_index
on `co_customers_defaults` (`cst_status_flag`);

create index co_customers_defaults_cst_name_last_index
on `co_customers_defaults` (`cst_name_last`);

create index co_customers_defaults_cst_name_first_index
on `co_customers_defaults` (`cst_name_first`);



drop table if exists `co_customers`;

create table co_customers
(
`cst_id` int(10) auto_increment primary key,
`cst_status_flag` tinyint(1) null,
`cst_name_last` varchar(100) null,
`cst_name_first` varchar(50) null
);

create index co_customers_cst_status_flag_index
on `co_customers` (`cst_status_flag`);

create index co_customers_cst_name_last_index
on `co_customers` (`cst_name_last`);

create index co_customers_cst_name_first_index
on `co_customers` (`cst_name_first`);



drop table if exists `co_dialect`;

create table co_dialect
(
field_primary int auto_increment primary key,
Expand Down Expand Up @@ -135,23 +135,23 @@ create table co_dialect
key dialect_table_index (field_bigint),
key dialect_table_two_fields (field_char, field_char_default)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



drop table if exists `fractal_dates`;

create table fractal_dates
(
`id` int(10) auto_increment primary key,
`ftime` time(2) null,
`fdatetime` datetime(2) null,
`ftimestamp` timestamp(2) null
);



drop table if exists `co_invoices`;

create table co_invoices
(
`inv_id` int(10) auto_increment primary key,
Expand All @@ -161,52 +161,52 @@ create table co_invoices
`inv_total` float(10, 2) null,
`inv_created_at` datetime null
);

create index co_invoices_inv_cst_id_index
on `co_invoices` (`inv_cst_id`);

create index co_invoices_inv_status_flag_index
on `co_invoices` (`inv_status_flag`);

create index co_invoices_inv_created_at_index
on `co_invoices` (`inv_created_at`);



drop table if exists objects;

create table objects
(
`obj_id` int(10) auto_increment primary key,
`obj_name` varchar(100) not null,
`obj_type` tinyint(3) unsigned not null
);



drop table if exists `co_orders`;

CREATE TABLE `co_orders` (
`ord_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ord_name` VARCHAR(70) NULL,
PRIMARY KEY (`ord_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



drop table if exists private.`co_orders_x_products`;

CREATE TABLE private.`co_orders_x_products` (

drop table if exists `co_orders_x_products`;

CREATE TABLE `co_orders_x_products` (
`oxp_ord_id` int(10) unsigned NOT NULL,
`oxp_prd_id` int(10) unsigned NOT NULL,
`oxp_quantity` int(10) unsigned NOT NULL,
PRIMARY KEY (`oxp_ord_id`, `oxp_prd_id` )
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



drop table if exists `photo`;

CREATE TABLE `photo` (
`id` int(10) unsigned not null auto_increment,
`date_uploaded` datetime not null default current_timestamp(),
Expand All @@ -227,63 +227,62 @@ CREATE TABLE `photo` (
`wins` int(10) unsigned not null DEFAULT '0',
primary key (`id`) using BTREE
) collate='utf8mb4_unicode_520_ci';



drop table if exists `co_products`;

CREATE TABLE `co_products` (
`prd_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`prd_name` VARCHAR(70) NULL,
PRIMARY KEY (`prd_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS co_rb_test_model;CREATE TABLE co_rb_test_model (id SMALLINT, name VARCHAR(10) NOT NULL);


drop table if exists `co_setters`;

create table co_setters
(
`id` int(10) auto_increment primary key,
`column1` varchar(100) null,
`column2` varchar(100) null,
`column3` varchar(100) null
);



drop table if exists `co_sources`;

create table co_sources
(
`id` int(10) auto_increment primary key,
`username` varchar(100) null,
`source` varchar(100) null
);

create index co_sources_username_index
on co_sources (username);



drop table if exists `table_with_uuid_primary`;

create table table_with_uuid_primary
(
`uuid` char(36) not null primary key,
`int_field` int null
);



drop table if exists `stuff`;

create table stuff
(
`stf_id` int(10) auto_increment primary key,
`stf_name` varchar(100) not null,
`stf_type` tinyint(3) unsigned not null
);

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function insert(
$oxp_prd_id = $oxp_prd_id ?: 'null';
$oxp_quantity = $oxp_quantity ?: 'null';
$sql = <<<SQL
insert into co_order_products (
insert into co_order_x_products (
oxp_ord_id, oxp_prd_id, oxp_quantity
) values (
{$oxp_ord_id}, {$oxp_prd_id}, {$oxp_quantity}
Expand Down
1 change: 0 additions & 1 deletion tests/_envs/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ modules:
waitlock: 10
initial_queries:
- "SET NAMES utf8;"
- "CREATE SCHEMA IF NOT EXISTS private"
5 changes: 0 additions & 5 deletions tests/database.suite.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
actor: DatabaseTester
modules:
enabled:
- Db:
dsn: "mysql:host=mysql;dbname=phalcon"
user: 'phalcon'
password: 'secret'

# - Phalcon5:
# bootstrap: 'tests/_config/bootstrap.php'
# # - Helper\PhalconLibmemcached:
Expand Down
23 changes: 10 additions & 13 deletions tests/database/Mvc/Model/Criteria/JoinCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Phalcon\Tests\Database\Mvc\Model\Criteria;

use Codeception\Attribute\Group;
use Codeception\Util\Debug;
use DatabaseTester;
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Mvc\Model\Query\Builder;
Expand Down Expand Up @@ -67,8 +68,7 @@ public function mvcModelCriteriaJoin(DatabaseTester $I)

$criteria
->setModelName(Invoices::class)
->join(Customers::class, 'inv_cst_id = cst_id', 'customer')
;
->join(Customers::class, 'inv_cst_id = cst_id', 'customer');

$builder = $criteria->createBuilder();

Expand All @@ -77,7 +77,7 @@ public function mvcModelCriteriaJoin(DatabaseTester $I)
$expected = 'SELECT [Phalcon\Tests\Models\Invoices].* '
. 'FROM [Phalcon\Tests\Models\Invoices] '
. 'JOIN [Phalcon\Tests\Models\Customers] AS [customer] ON inv_cst_id = cst_id';
$actual = $builder->getPhql();
$actual = $builder->getPhql();
$I->assertEquals($expected, $actual);
}

Expand All @@ -89,20 +89,14 @@ public function mvcModelCriteriaJoin(DatabaseTester $I)
* @author Jeremy PASTOURET <https://github.com/jenovateurs>
* @since 2020-02-06
*
* @group mysql
* @group pgsql
*/
#[Group('mysql', 'pgsql')]
#[Group('pgsql')]
public function mvcModelCriteriaJoinManyToManyMultipleSchema(DatabaseTester $I)
{
$I->wantToTest('Mvc\Model\Criteria - join() and use ManyToMany with Multiple schemas');

$this->setDatabase($I);
// Why is group not working here?
if ($I->getDriver() !== 'mysql' && $I->getDriver() !== 'pgsql') {
$I->skipTest('Driver ' . $I->getDriver() . ' not supported');
return;
}

new OrdersMigration($I->getConnection());
new ProductsMigration($I->getConnection());
Expand All @@ -119,12 +113,15 @@ public function mvcModelCriteriaJoinManyToManyMultipleSchema(DatabaseTester $I)
$builder->from(Orders::class);
$builder->join(Products::class);

$expected = 'private';
$query = $builder->getQuery();
$request = $query->getSql();
$query = $builder->getQuery();
$request = $query->getSql();

$expected = 'private';
$I->assertStringContainsString($expected, $request['sql']);

Debug::debug($I->getDriver());
Debug::debug($request['sql']);

$I->assertInstanceOf(Simple::class, $query->execute());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Phalcon\Tests\Database\Mvc\Model\MetaData\Adapter;

use Codeception\Attribute\Skip;
use Codeception\Example;
use DatabaseTester;
use Phalcon\Mvc\Model\MetaData;
Expand Down Expand Up @@ -53,6 +54,7 @@ public function _before(DatabaseTester $I)
* @group mysql
*
*/
#[Skip('This currently doesn\'t work because of constraint errors.')]
public function mvcModelMetadataGetAttributesRedis(
DatabaseTester $I,
Example $example
Expand Down

0 comments on commit 54a3b21

Please sign in to comment.