Skip to content

Commit 08173c7

Browse files
committed
Restore IDs in SiteAuthors fixture.
Not having them made non-sqlserver databases unhappy. We'll need another fixture for composite key + autoincrement.
1 parent 75d6db8 commit 08173c7

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* For full copyright and license information, please see the LICENSE.txt
8+
* Redistributions of files must retain the above copyright notice.
9+
*
10+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
11+
* @link http://cakephp.org CakePHP(tm) Project
12+
* @since 3.0.0
13+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
14+
*/
15+
namespace Cake\Test\Fixture;
16+
17+
use Cake\TestSuite\Fixture\TestFixture;
18+
19+
class CompositeIncrementsFixture extends TestFixture
20+
{
21+
22+
/**
23+
* fields property
24+
*
25+
* @var array
26+
*/
27+
public $fields = [
28+
'id' => ['type' => 'integer', 'null' => false, 'autoIncrement' => true],
29+
'account_id' => ['type' => 'integer', 'null' => false],
30+
'name' => ['type' => 'string', 'default' => null],
31+
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id', 'account_id']]]
32+
];
33+
34+
/**
35+
* records property
36+
*
37+
* @var array
38+
*/
39+
public $records = [
40+
];
41+
}

tests/Fixture/SiteAuthorsFixture.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SiteAuthorsFixture extends TestFixture
2525
* @var array
2626
*/
2727
public $fields = [
28-
'id' => ['type' => 'integer', 'autoIncrement' => true],
28+
'id' => ['type' => 'integer'],
2929
'name' => ['type' => 'string', 'default' => null],
3030
'site_id' => ['type' => 'integer', 'null' => true],
3131
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id', 'site_id']]]
@@ -37,9 +37,9 @@ class SiteAuthorsFixture extends TestFixture
3737
* @var array
3838
*/
3939
public $records = [
40-
['name' => 'mark', 'site_id' => 1],
41-
['name' => 'juan', 'site_id' => 2],
42-
['name' => 'jose', 'site_id' => 2],
43-
['name' => 'andy', 'site_id' => 1]
40+
['id' => 1, 'name' => 'mark', 'site_id' => 1],
41+
['id' => 2, 'name' => 'juan', 'site_id' => 2],
42+
['id' => 3, 'name' => 'jose', 'site_id' => 2],
43+
['id' => 4, 'name' => 'andy', 'site_id' => 1]
4444
];
4545
}

tests/TestCase/ORM/TableTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TableTest extends TestCase
5555
'core.authors',
5656
'core.tags',
5757
'core.articles_tags',
58-
'core.site_authors',
58+
'core.composite_increments',
5959
'core.site_articles',
6060
];
6161

@@ -2000,11 +2000,11 @@ public function testSaveNewErrorCompositeKeyNoIncrement()
20002000
public function testSaveNewCompositeKeyIncrement()
20012001
{
20022002
$this->skipIfSqlite();
2003-
$articles = TableRegistry::get('SiteAuthors');
2004-
$article = $articles->newEntity(['site_id' => 3, 'name' => 'new guy']);
2005-
$this->assertSame($article, $articles->save($article));
2006-
$this->assertNotEmpty($article->id, 'Primary key should have been populated');
2007-
$this->assertSame(3, $article->site_id);
2003+
$table = TableRegistry::get('CompositeIncrements');
2004+
$thing = $table->newEntity(['account_id' => 3, 'name' => 'new guy']);
2005+
$this->assertSame($thing, $table->save($thing));
2006+
$this->assertNotEmpty($thing->id, 'Primary key should have been populated');
2007+
$this->assertSame(3, $thing->account_id);
20082008
}
20092009

20102010
/**

0 commit comments

Comments
 (0)