Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Bug with "format: date-time" #161 #38

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/DbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ protected function tearDown(): void
}
}

/**
* @param $configFile
* @param $dbName string enum(mysql, pgsql, maria)
*/
protected function runGenerator($configFile, string $dbName = 'mysql')
{
$config = require $configFile;
Expand Down
14 changes: 14 additions & 0 deletions tests/specs/issue_fix/161_bug_with_format_date_time/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

return [
'openApiPath' => '@specs/issue_fix/161_bug_with_format_date_time/index.yaml',
'generateUrls' => false,
'generateModels' => false,
'excludeModels' => [
'Error',
],
'generateControllers' => false,
'generateMigrations' => true,
'generateModelFaker' => false, // `generateModels` must be `true` in orde to use `generateModelFaker` as `true`
];

61 changes: 61 additions & 0 deletions tests/specs/issue_fix/161_bug_with_format_date_time/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
openapi: 3.0.3
# Edit this schema and start your project
# This is sample schema
# To generate code which is based on this schema
# run commands mentioned Development section in README.md file
info:
title: 'Proxy-Service'
description: ""
version: 1.0.0
contact:
name: '...'
email: you@example.com
servers:
- url: 'http://localhost:9937'
description: 'Local Dev API'
security:
- BasicAuth: []
components:
securitySchemes:
BasicAuth:
type: http
scheme: basic
schemas:

Subscription:
type: object
required:
- id
properties:
id:
type: integer
start:
type: string
format: date-time
end:
type: string
format: date-time
createdAt:
type: string
format: date-time
readOnly: True
updatedAt:
type: string
format: date-time
readOnly: true
updatedAt2: # <------------ new column
type: string
format: date-time
readOnly: true

paths:
'/accounts':

post:
operationId: createAccount
summary: Create a account
description: Create account

responses:
'201':
description: OK
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/
class m200000_000000_create_table_contacts extends \yii\db\Migration
{
public function up()
public function safeUp()
{
$this->createTable('{{%contacts}}', [
'id' => $this->primaryKey(),
]);
}

public function down()
public function safeDown()
{
$this->dropTable('{{%contacts}}');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
*/
class m200000_000000_create_table_accounts extends \yii\db\Migration
{
public function up()
public function safeUp()
{
$this->createTable('{{%accounts}}', [
'id' => $this->primaryKey(),
'name' => $this->string(128)->notNull(),
'paymentMethodName' => $this->text()->null(),
'paymentMethodName' => $this->text()->null()->defaultValue(null),
]);
}

public function down()
public function safeDown()
{
$this->dropTable('{{%accounts}}');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
*/
class m200000_000001_create_table_contacts extends \yii\db\Migration
{
public function up()
public function safeUp()
{
$this->createTable('{{%contacts}}', [
'id' => $this->primaryKey(),
'account_id' => $this->integer()->notNull(),
'active' => $this->boolean()->null()->defaultValue(false),
'nickname' => $this->text()->null(),
'nickname' => $this->text()->null()->defaultValue(null),
]);
$this->addForeignKey('fk_contacts_account_id_accounts_id', '{{%contacts}}', 'account_id', '{{%accounts}}', 'id');
}

public function down()
public function safeDown()
{
$this->dropForeignKey('fk_contacts_account_id_accounts_id', '{{%contacts}}');
$this->dropTable('{{%contacts}}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
class m200000_000002_create_table_payment_methods extends \yii\db\Migration
{
public function up()
public function safeUp()
{
$this->createTable('{{%payment_methods}}', [
'id' => $this->primaryKey(),
Expand All @@ -14,7 +14,7 @@ public function up()
$this->createIndex('payment_methods_name_key', '{{%payment_methods}}', 'name', true);
}

public function down()
public function safeDown()
{
$this->dropIndex('payment_methods_name_key', '{{%payment_methods}}');
$this->dropTable('{{%payment_methods}}');
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/IssueFixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public function test162BugDollarrefWithXFaker()
// 163_generator_crash_when_using_reference_inside_an_object
public function test163GeneratorCrashWhenUsingReferenceInsideAnObject()
{
$this->changeDbToPgsql();
$testFile = Yii::getAlias("@specs/issue_fix/163_generator_crash_when_using_reference_inside_an_object/index.php");
$this->runGenerator($testFile, 'pgsql');
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
Expand All @@ -305,6 +306,7 @@ public function test163GeneratorCrashWhenUsingReferenceInsideAnObject()
// Bug: allOf with multiple $refs
public function test175BugAllOfWithMultipleDollarRefs()
{
$this->changeDbToPgsql();
$testFile = Yii::getAlias("@specs/issue_fix/175_bug_allof_with_multiple_dollarrefs/index.php");
$this->runGenerator($testFile, 'pgsql');
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
Expand All @@ -320,6 +322,7 @@ public function test175BugAllOfWithMultipleDollarRefs()
// schema.yaml: requestBody has no effect
public function test172SchemayamlRequestBodyHasNoEffect()
{
$this->changeDbToPgsql();
$testFile = Yii::getAlias("@specs/issue_fix/172_schemayaml_requestbody_has_no_effect/index.php");
$this->runGenerator($testFile, 'pgsql');
$actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
Expand All @@ -330,4 +333,38 @@ public function test172SchemayamlRequestBodyHasNoEffect()
]);
$this->checkFiles($actualFiles, $expectedFiles);
}

// https://github.com/cebe/yii2-openapi/issues/161
// Bug with "format: date-time"
public function test161BugWithFormatDateTime()
{
$this->changeDbToPgsql();
$testFile = Yii::getAlias("@specs/issue_fix/161_bug_with_format_date_time/index.php");
$this->f161();
$this->runGenerator($testFile, 'pgsql');
// $actualFiles = FileHelper::findFiles(Yii::getAlias('@app'), [
// 'recursive' => true,
// ]);
// $expectedFiles = FileHelper::findFiles(Yii::getAlias("@specs/issue_fix/172_schemayaml_requestbody_has_no_effect/pgsql"), [
// 'recursive' => true,
// ]);
// $this->checkFiles($actualFiles, $expectedFiles);
}

protected function f161() // TODO rename
{
$sql = <<<SQL
create table public.itt_subscriptions
(
id serial,
start timestamp(0) default NULL::timestamp without time zone,
"end" timestamp(0) default NULL::timestamp without time zone,
"createdAt" timestamp(0) default NULL::timestamp without time zone,
"updatedAt" timestamp(0) default NULL::timestamp without time zone

)

SQL;
Yii::$app->pgsql->createCommand($sql)->execute();
}
}
4 changes: 4 additions & 0 deletions tests/unit/MultiDbFreshMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ protected function tearDown(): void
}
}

/**
* @param $configFile
* @param $dbName string enum(mysql, pgsql, maria)
*/
protected function runGenerator($configFile, string $dbName = 'mysql')
{
$config = require $configFile;
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/MultiDbSecondaryMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ protected function tearDown(): void
}
}

/**
* @param $configFile
* @param $dbName string enum(mysql, pgsql, maria)
*/
protected function runGenerator($configFile, string $dbName = 'mysql')
{
$config = require $configFile;
Expand Down
Loading