|
11 | 11 | use Cake\Event\EventManager; |
12 | 12 | use Cake\TestSuite\TestCase; |
13 | 13 | use InvalidArgumentException; |
| 14 | +use Phinx\Config\FeatureFlags; |
| 15 | +use ReflectionClass; |
14 | 16 | use ReflectionProperty; |
15 | 17 |
|
16 | 18 | class SeedCommandTest extends TestCase |
@@ -38,6 +40,13 @@ public function tearDown(): void |
38 | 40 | $connection->execute('DROP TABLE IF EXISTS numbers'); |
39 | 41 | $connection->execute('DROP TABLE IF EXISTS letters'); |
40 | 42 | $connection->execute('DROP TABLE IF EXISTS stores'); |
| 43 | + |
| 44 | + if (class_exists(FeatureFlags::class)) { |
| 45 | + $reflection = new ReflectionClass(FeatureFlags::class); |
| 46 | + if ($reflection->hasProperty('addTimestampsUseDateTime')) { |
| 47 | + FeatureFlags::$addTimestampsUseDateTime = false; |
| 48 | + } |
| 49 | + } |
41 | 50 | } |
42 | 51 |
|
43 | 52 | protected function resetOutput(): void |
@@ -141,7 +150,7 @@ public function testSeederBaseSeed(): void |
141 | 150 | $this->assertEquals(2, $query->fetchColumn(0)); |
142 | 151 | } |
143 | 152 |
|
144 | | - public function testSeederImplictAll(): void |
| 153 | + public function testSeederImplicitAll(): void |
145 | 154 | { |
146 | 155 | $this->createTables(); |
147 | 156 | $this->exec('migrations seed -c test'); |
@@ -192,4 +201,68 @@ public function testSeederSourceNotFound(): void |
192 | 201 |
|
193 | 202 | $this->exec('migrations seed -c test --source NotThere --seed LettersSeed'); |
194 | 203 | } |
| 204 | + |
| 205 | + public function testSeederWithTimestampFields(): void |
| 206 | + { |
| 207 | + if (class_exists(FeatureFlags::class)) { |
| 208 | + $reflection = new ReflectionClass(FeatureFlags::class); |
| 209 | + if ($reflection->hasProperty('addTimestampsUseDateTime')) { |
| 210 | + FeatureFlags::$addTimestampsUseDateTime = false; |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + $this->createTables(); |
| 215 | + $this->exec('migrations seed -c test --seed StoresSeed'); |
| 216 | + |
| 217 | + $this->assertExitSuccess(); |
| 218 | + $this->assertOutputContains('StoresSeed:</info> <comment>seeding'); |
| 219 | + $this->assertOutputContains('All Done'); |
| 220 | + |
| 221 | + /** @var \Cake\Database\Connection $connection */ |
| 222 | + $connection = ConnectionManager::get('test'); |
| 223 | + $result = $connection->selectQuery() |
| 224 | + ->select(['*']) |
| 225 | + ->from('stores') |
| 226 | + ->orderBy('id DESC') |
| 227 | + ->limit(1) |
| 228 | + ->execute()->fetchAll('assoc'); |
| 229 | + |
| 230 | + $this->assertNotEmpty($result[0]); |
| 231 | + $store = $result[0]; |
| 232 | + $this->assertEquals('foo_with_date', $store['name']); |
| 233 | + $this->assertNotEmpty($store['created']); |
| 234 | + $this->assertNotEmpty($store['modified']); |
| 235 | + } |
| 236 | + |
| 237 | + public function testSeederWithDateTimeFields(): void |
| 238 | + { |
| 239 | + $this->skipIf(!class_exists(FeatureFlags::class)); |
| 240 | + |
| 241 | + $reflection = new ReflectionClass(FeatureFlags::class); |
| 242 | + $this->skipIf(!$reflection->hasProperty('addTimestampsUseDateTime')); |
| 243 | + |
| 244 | + FeatureFlags::$addTimestampsUseDateTime = true; |
| 245 | + |
| 246 | + $this->createTables(); |
| 247 | + $this->exec('migrations seed -c test --seed StoresSeed'); |
| 248 | + |
| 249 | + $this->assertExitSuccess(); |
| 250 | + $this->assertOutputContains('StoresSeed:</info> <comment>seeding'); |
| 251 | + $this->assertOutputContains('All Done'); |
| 252 | + |
| 253 | + /** @var \Cake\Database\Connection $connection */ |
| 254 | + $connection = ConnectionManager::get('test'); |
| 255 | + $result = $connection->selectQuery() |
| 256 | + ->select(['*']) |
| 257 | + ->from('stores') |
| 258 | + ->orderBy('id DESC') |
| 259 | + ->limit(1) |
| 260 | + ->execute()->fetchAll('assoc'); |
| 261 | + |
| 262 | + $this->assertNotEmpty($result[0]); |
| 263 | + $store = $result[0]; |
| 264 | + $this->assertEquals('foo_with_date', $store['name']); |
| 265 | + $this->assertNotEmpty($store['created']); |
| 266 | + $this->assertNotEmpty($store['modified']); |
| 267 | + } |
195 | 268 | } |
0 commit comments