-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathModelCommandAssociationDetectionTest.php
More file actions
178 lines (163 loc) · 5.69 KB
/
ModelCommandAssociationDetectionTest.php
File metadata and controls
178 lines (163 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
declare(strict_types=1);
/**
* CakePHP : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://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. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP Project
* @since 1.1.4
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Bake\Test\TestCase\Command;
use Bake\Test\TestCase\TestCase;
use Cake\Console\CommandInterface;
use Cake\Core\Plugin;
use Cake\Database\Driver\Mysql;
use Cake\Database\Driver\Postgres;
use Cake\Database\Driver\Sqlite;
use Cake\Database\Driver\Sqlserver;
use Cake\Datasource\ConnectionManager;
/**
* ModelCommand Association detection test
*/
class ModelCommandAssociationDetectionTest extends TestCase
{
/**
* fixtures
*
* Don't sort this list alphabetically - otherwise there are table constraints
* which fail when using postgres
*
* @var array<string>
*/
protected array $fixtures = [
'plugin.Bake.Categories',
'plugin.Bake.CategoriesProducts',
'plugin.Bake.OldProducts',
'plugin.Bake.Products',
'plugin.Bake.ProductVersions',
];
/**
* setUp method
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Model' . DS;
$this->setAppNamespace('Bake\Test\App');
$this->getTableLocator()->clear();
}
/**
* tearDown method
*
* @return void
*/
public function tearDown(): void
{
parent::tearDown();
$this->getTableLocator()->clear();
}
/**
* Compare bake table result with static comparison file
*
* @return void
*/
protected function _compareBakeTableResult($name, $comparisonFile)
{
$this->generatedFiles = [
APP . "Model/Table/{$name}Table.php",
];
$this->exec("bake model --no-entity --no-fixture --no-test --connection test {$name}");
$this->assertExitCode(CommandInterface::CODE_SUCCESS);
$contents = file_get_contents($this->generatedFiles[0]);
$this->assertSameAsFile($comparisonFile . '.php', $contents);
}
/**
* test checking if associations where built correctly for categories.
*
* @return void
*/
public function testBakeAssociationDetectionCategoriesTable()
{
$driver = ConnectionManager::get('test')->getDriver();
$this->skipIf($driver instanceof Mysql, 'Incompatible with mysql');
$this->_compareBakeTableResult('Categories', __FUNCTION__);
}
/**
* test checking if associations where built correctly for categories.
*
* @return void
*/
public function testBakeAssociationDetectionCategoriesTableSigned()
{
$driver = ConnectionManager::get('test')->getDriver();
$this->skipIf($driver instanceof Sqlite, 'Incompatible with sqlite');
$this->skipIf($driver instanceof Postgres, 'Incompatible with postgres');
$this->skipIf($driver instanceof Sqlserver, 'Incompatible with sqlserver');
$this->_compareBakeTableResult('Categories', __FUNCTION__);
}
/**
* test checking if associations where built correctly for categories_products.
*
* @return void
*/
public function testBakeAssociationDetectionCategoriesProductsTable()
{
$this->_compareBakeTableResult('CategoriesProducts', __FUNCTION__);
}
/**
* test checking if associations where built correctly for old_products.
*
* @return void
*/
public function testBakeAssociationDetectionOldProductsTable()
{
$driver = ConnectionManager::get('test')->getDriver();
$this->skipIf($driver instanceof Mysql, 'Incompatible with mysql');
$this->_compareBakeTableResult('OldProducts', __FUNCTION__);
}
/**
* test checking if associations where built correctly for old_products.
*
* @return void
*/
public function testBakeAssociationDetectionOldProductsTableSigned()
{
$driver = ConnectionManager::get('test')->getDriver();
$this->skipIf($driver instanceof Sqlite, 'Incompatible with sqlite');
$this->skipIf($driver instanceof Postgres, 'Incompatible with postgres');
$this->skipIf($driver instanceof Sqlserver, 'Incompatible with sqlserver');
$this->_compareBakeTableResult('OldProducts', __FUNCTION__);
}
/**
* test checking if associations where built correctly for product_versions.
*
* @return void
*/
public function testBakeAssociationDetectionProductVersionsTable()
{
$driver = ConnectionManager::get('test')->getDriver();
$this->skipIf($driver instanceof Mysql, 'Incompatible with mysql');
$this->skipIf($driver instanceof Sqlite, 'Incompatible with sqlite');
$this->_compareBakeTableResult('ProductVersions', __FUNCTION__);
}
/**
* test checking if associations where built correctly for product_versions.
*
* @return void
*/
public function testBakeAssociationDetectionProductVersionsTableSigned()
{
$driver = ConnectionManager::get('test')->getDriver();
$this->skipIf($driver instanceof Postgres, 'Incompatible with postgres');
$this->skipIf($driver instanceof Sqlserver, 'Incompatible with sqlserver');
$this->_compareBakeTableResult('ProductVersions', __FUNCTION__);
}
}