Skip to content

Commit

Permalink
Restore IDs in SiteAuthors fixture.
Browse files Browse the repository at this point in the history
Not having them made non-sqlserver databases unhappy. We'll need another
fixture for composite key + autoincrement.
  • Loading branch information
markstory committed Mar 6, 2015
1 parent 75d6db8 commit 08173c7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 11 deletions.
41 changes: 41 additions & 0 deletions tests/Fixture/CompositeIncrementsFixture.php
@@ -0,0 +1,41 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Test\Fixture;

use Cake\TestSuite\Fixture\TestFixture;

class CompositeIncrementsFixture extends TestFixture
{

/**
* fields property
*
* @var array
*/
public $fields = [
'id' => ['type' => 'integer', 'null' => false, 'autoIncrement' => true],
'account_id' => ['type' => 'integer', 'null' => false],
'name' => ['type' => 'string', 'default' => null],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id', 'account_id']]]
];

/**
* records property
*
* @var array
*/
public $records = [
];
}
10 changes: 5 additions & 5 deletions tests/Fixture/SiteAuthorsFixture.php
Expand Up @@ -25,7 +25,7 @@ class SiteAuthorsFixture extends TestFixture
* @var array
*/
public $fields = [
'id' => ['type' => 'integer', 'autoIncrement' => true],
'id' => ['type' => 'integer'],
'name' => ['type' => 'string', 'default' => null],
'site_id' => ['type' => 'integer', 'null' => true],
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id', 'site_id']]]
Expand All @@ -37,9 +37,9 @@ class SiteAuthorsFixture extends TestFixture
* @var array
*/
public $records = [
['name' => 'mark', 'site_id' => 1],
['name' => 'juan', 'site_id' => 2],
['name' => 'jose', 'site_id' => 2],
['name' => 'andy', 'site_id' => 1]
['id' => 1, 'name' => 'mark', 'site_id' => 1],
['id' => 2, 'name' => 'juan', 'site_id' => 2],
['id' => 3, 'name' => 'jose', 'site_id' => 2],
['id' => 4, 'name' => 'andy', 'site_id' => 1]
];
}
12 changes: 6 additions & 6 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -55,7 +55,7 @@ class TableTest extends TestCase
'core.authors',
'core.tags',
'core.articles_tags',
'core.site_authors',
'core.composite_increments',
'core.site_articles',
];

Expand Down Expand Up @@ -2000,11 +2000,11 @@ public function testSaveNewErrorCompositeKeyNoIncrement()
public function testSaveNewCompositeKeyIncrement()
{
$this->skipIfSqlite();
$articles = TableRegistry::get('SiteAuthors');
$article = $articles->newEntity(['site_id' => 3, 'name' => 'new guy']);
$this->assertSame($article, $articles->save($article));
$this->assertNotEmpty($article->id, 'Primary key should have been populated');
$this->assertSame(3, $article->site_id);
$table = TableRegistry::get('CompositeIncrements');
$thing = $table->newEntity(['account_id' => 3, 'name' => 'new guy']);
$this->assertSame($thing, $table->save($thing));
$this->assertNotEmpty($thing->id, 'Primary key should have been populated');
$this->assertSame(3, $thing->account_id);
}

/**
Expand Down

0 comments on commit 08173c7

Please sign in to comment.