|
11 | 11 | use Cake\Event\EventManager; |
12 | 12 | use Cake\TestSuite\TestCase; |
13 | 13 | use InvalidArgumentException; |
| 14 | +use Phinx\Config\FeatureFlags; |
14 | 15 | use ReflectionProperty; |
15 | 16 |
|
16 | 17 | class SeedCommandTest extends TestCase |
@@ -141,7 +142,7 @@ public function testSeederBaseSeed(): void |
141 | 142 | $this->assertEquals(2, $query->fetchColumn(0)); |
142 | 143 | } |
143 | 144 |
|
144 | | - public function testSeederImplictAll(): void |
| 145 | + public function testSeederImplicitAll(): void |
145 | 146 | { |
146 | 147 | $this->createTables(); |
147 | 148 | $this->exec('migrations seed -c test'); |
@@ -192,4 +193,58 @@ public function testSeederSourceNotFound(): void |
192 | 193 |
|
193 | 194 | $this->exec('migrations seed -c test --source NotThere --seed LettersSeed'); |
194 | 195 | } |
| 196 | + |
| 197 | + public function testSeederWithDateTimeFields(): void |
| 198 | + { |
| 199 | + FeatureFlags::$addTimestampsUseDateTime = true; |
| 200 | + |
| 201 | + $this->createTables(); |
| 202 | + $this->exec('migrations seed -c test --seed StoresSeed'); |
| 203 | + |
| 204 | + $this->assertExitSuccess(); |
| 205 | + $this->assertOutputContains('StoresSeed:</info> <comment>seeding'); |
| 206 | + $this->assertOutputContains('All Done'); |
| 207 | + |
| 208 | + /** @var \Cake\Database\Connection $connection */ |
| 209 | + $connection = ConnectionManager::get('test'); |
| 210 | + $result = $connection->selectQuery() |
| 211 | + ->select(['*']) |
| 212 | + ->from('stores') |
| 213 | + ->orderBy('id DESC') |
| 214 | + ->limit(1) |
| 215 | + ->execute()->fetchAll('assoc'); |
| 216 | + |
| 217 | + $this->assertNotEmpty($result[0]); |
| 218 | + $store = $result[0]; |
| 219 | + $this->assertEquals('foo_with_date', $store['name']); |
| 220 | + $this->assertNotEmpty($store['created']); |
| 221 | + $this->assertNotEmpty($store['modified']); |
| 222 | + } |
| 223 | + |
| 224 | + public function testSeederWithTimestampFields(): void |
| 225 | + { |
| 226 | + FeatureFlags::$addTimestampsUseDateTime = false; |
| 227 | + |
| 228 | + $this->createTables(); |
| 229 | + $this->exec('migrations seed -c test --seed StoresSeed'); |
| 230 | + |
| 231 | + $this->assertExitSuccess(); |
| 232 | + $this->assertOutputContains('StoresSeed:</info> <comment>seeding'); |
| 233 | + $this->assertOutputContains('All Done'); |
| 234 | + |
| 235 | + /** @var \Cake\Database\Connection $connection */ |
| 236 | + $connection = ConnectionManager::get('test'); |
| 237 | + $result = $connection->selectQuery() |
| 238 | + ->select(['*']) |
| 239 | + ->from('stores') |
| 240 | + ->orderBy('id DESC') |
| 241 | + ->limit(1) |
| 242 | + ->execute()->fetchAll('assoc'); |
| 243 | + |
| 244 | + $this->assertNotEmpty($result[0]); |
| 245 | + $store = $result[0]; |
| 246 | + $this->assertEquals('foo_with_date', $store['name']); |
| 247 | + $this->assertNotEmpty($store['created']); |
| 248 | + $this->assertNotEmpty($store['modified']); |
| 249 | + } |
195 | 250 | } |
0 commit comments