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

Test fixtures and support of TIMESTAMP(x) #12623

Closed
1 of 3 tasks
Userlocal2 opened this issue Oct 3, 2018 · 2 comments
Closed
1 of 3 tasks

Test fixtures and support of TIMESTAMP(x) #12623

Userlocal2 opened this issue Oct 3, 2018 · 2 comments

Comments

@Userlocal2
Copy link

Userlocal2 commented Oct 3, 2018

This is a (multiple allowed):

  • bug

  • enhancement

  • feature-discussion (RFC)

  • CakePHP Version: 3.6.12.

  • Mysql Version: 5.6.39.

What you did

Created table with scheme

create table messages
(
	id int auto_increment
		primary key,
	data longtext null comment 'Request data must be valid XML',
	MsgId varchar(35) null comment 'Message identifier',
	updated_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
	created_at timestamp(5) default CURRENT_TIMESTAMP(5) not null,
	constraint MsgId
		unique (MsgId)
)
charset=utf8
;

Created Fixture to write test:

use Cake\TestSuite\Fixture\TestFixture;

/**
 * MessagesFixture
 *
 */
class MessagesFixture extends TestFixture
{
    public $import = ['model' => 'Messages'];

    /**
     * Records
     *
     * @var array
     */
    public $records = [];
}

Wrote test:

class MessagesTableTest extends TestCase
{

    public $fixtures = [
        'messages'
    ];

    public function testInitialize()
    {
        $this->markTestIncomplete('Not implemented yet.');
    }
}

What happened

After starting this test I've got an error:

Warning Error: Fixture creation for "messages" failed "SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'created_at'" in [/var/www/html/vendor/cakephp/cakephp/src/TestSuite/Fixture/TestFixture.php, line 313]

This table did not created for my test ad generates invalid DDL command for it(retrived with xdebug):

CREATE TABLE `messages` (
`id` INTEGER(11) NOT NULL AUTO_INCREMENT,
`data` LONGTEXT COLLATE utf8_general_ci COMMENT 'Request data must be valid XML',
`MsgId` VARCHAR(35) COLLATE utf8_general_ci COMMENT 'Message identifier',
`updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` TIMESTAMP NOT NULL DEFAULT 'CURRENT_TIMESTAMP(5)',
PRIMARY KEY (`id`),
UNIQUE KEY `MsgId` (`MsgId`)
) ENGINE=InnoDB

Error in scheme is here:

`created_at` TIMESTAMP NOT NULL DEFAULT 'CURRENT_TIMESTAMP(5)',

Must be

`created_at` TIMESTAMP(5) NOT NULL DEFAULT 'CURRENT_TIMESTAMP(5)',

What you expected to happen

Create table for tests with valid scheme

@markstory markstory added this to the 3.6.13 milestone Oct 3, 2018
@markstory
Copy link
Member

We don't currently support preserving the fractional microseconds in TIMESTAMP columns for schema generation. We could trim off the (5) from CURRENT_TIMESTAMP to prevent this issue though.

@markstory markstory added the mysql label Oct 3, 2018
@markstory markstory modified the milestones: 3.6.13, 3.7.0 Oct 29, 2018
@markstory markstory modified the milestones: 3.7.0, Future Dec 9, 2018
@github-actions
Copy link

This issue is stale because it has been open for 120 days with no activity. Remove the stale label or comment or this will be closed in 15 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants