Skip to content

Commit

Permalink
Delete unused fixture and add a test which asserts that single column…
Browse files Browse the repository at this point in the history
… constraint works as expected
  • Loading branch information
HavokInspiration committed Jun 17, 2015
1 parent 8b45acb commit cd4ac1d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 67 deletions.
2 changes: 1 addition & 1 deletion tests/Fixture/ArticlesTagsFixture.php
Expand Up @@ -33,7 +33,7 @@ class ArticlesTagsFixture extends TestFixture
'tag_id' => ['type' => 'integer', 'null' => false],
'_constraints' => [
'unique_tag' => ['type' => 'primary', 'columns' => ['article_id', 'tag_id']],
'tag_idx' => [
'tag_id_fk' => [
'type' => 'foreign',
'columns' => ['tag_id'],
'references' => ['tags', 'id'],
Expand Down
50 changes: 0 additions & 50 deletions tests/Fixture/CustomersFixture.php

This file was deleted.

14 changes: 1 addition & 13 deletions tests/Fixture/OrdersFixture.php
Expand Up @@ -37,15 +37,10 @@ class OrdersFixture extends TestFixture
'id' => ['type' => 'integer'],
'product_category' => ['type' => 'integer', 'null' => false],
'product_id' => ['type' => 'integer', 'null' => false],
'customer_id' => ['type' => 'integer', 'null' => false],
'_indexes' => [
'product_category' => [
'type' => 'index',
'columns' => ['product_category', 'product_id']
],
'customer_id' => [
'type' => 'index',
'columns' => ['customer_id']
]
],
'_constraints' => [
Expand All @@ -58,13 +53,6 @@ class OrdersFixture extends TestFixture
'references' => ['products', ['id', 'category']],
'update' => 'cascade',
'delete' => 'cascade',
],
'order_ibfk_2' => [
'type' => 'foreign',
'columns' => ['customer_id'],
'references' => ['customers', 'id'],
'update' => 'cascade',
'delete' => 'cascade',
]
]
];
Expand All @@ -75,6 +63,6 @@ class OrdersFixture extends TestFixture
* @var array
*/
public $records = [
['product_category' => 1, 'product_id' => 1, 'customer_id' => 1]
['product_category' => 1, 'product_id' => 1]
];
}
30 changes: 27 additions & 3 deletions tests/TestCase/Database/Schema/TableTest.php
Expand Up @@ -25,7 +25,7 @@
class TableTest extends TestCase
{

public $fixtures = ['core.customers', 'core.products', 'core.orders'];
public $fixtures = ['core.articles_tags', 'core.products', 'core.orders'];

/**
* Test construction with columns
Expand Down Expand Up @@ -409,12 +409,36 @@ public function testAddConstraintForeignKey()
$this->assertEquals(['author_id_idx'], $table->constraints());
}

/**
* Test single column foreign keys constraint support
*
* @return void
*/
public function testConstraintForeignKey()
{
$table = TableRegistry::get('ArticlesTags');
$compositeConstraint = $table->schema()->constraint('tag_id_fk');
$expected = [
'type' => 'foreign',
'columns' => ['tag_id'],
'references' => ['tags', 'id'],
'update' => 'cascade',
'delete' => 'cascade',
'length' => []
];

$this->assertEquals($expected, $compositeConstraint);

$expectedSubstring = 'CONSTRAINT <tag_id_fk> FOREIGN KEY \(<tag_id>\) REFERENCES <tags> \(<id>\)';
$this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('test'))[0]);
}

/**
* Test composite foreign keys support
*
* @return void
*/
public function testAddConstraintForeignKeyTwoColumns()
public function testConstraintForeignKeyTwoColumns()
{
$table = TableRegistry::get('Orders');
$compositeConstraint = $table->schema()->constraint('product_id_fk');
Expand All @@ -438,7 +462,7 @@ public function testAddConstraintForeignKeyTwoColumns()
$expectedSubstring = 'CONSTRAINT <product_id_fk> FOREIGN KEY \(<product_id>, <product_category>\)' .
' REFERENCES <products> \(<id>, <category>\)';

$this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('default'))[0]);
$this->assertQuotedQuery($expectedSubstring, $table->schema()->createSql(ConnectionManager::get('test'))[0]);
}

/**
Expand Down

0 comments on commit cd4ac1d

Please sign in to comment.