|
6 | 6 | use ActiveRecord\Exception\DatabaseException;
|
7 | 7 | use ActiveRecord\Exception\ReadOnlyException;
|
8 | 8 | use ActiveRecord\Exception\UndefinedPropertyException;
|
| 9 | +use ActiveRecord\Table; |
9 | 10 | use test\models\Author;
|
10 | 11 | use test\models\Book;
|
| 12 | +use test\models\Course; |
11 | 13 | use test\models\Venue;
|
12 | 14 |
|
13 | 15 | class DirtyAuthor extends ActiveRecord\Model
|
@@ -90,10 +92,22 @@ public function testSaveAutoIncrementId()
|
90 | 92 | $this->assertTrue($venue->id > 0);
|
91 | 93 | }
|
92 | 94 |
|
| 95 | + public function testFullyQualifiedNameWithExplicitDbName() |
| 96 | + { |
| 97 | + Course::$db = 'test'; |
| 98 | + $name = Table::load(Course::class) |
| 99 | + ->get_fully_qualified_table_name(); |
| 100 | + $this->assert_sql_includes('`test`.`courses`', $name); |
| 101 | + Course::$db = ''; |
| 102 | + } |
| 103 | + |
93 | 104 | public function testSequenceWasSet()
|
94 | 105 | {
|
95 | 106 | if (ConnectionManager::get_connection()->supports_sequences()) {
|
96 |
| - $this->assertEquals(ConnectionManager::get_connection()->get_sequence_name('authors', 'author_id'), Author::table()->sequence); |
| 107 | + $this->assertEquals( |
| 108 | + ConnectionManager::get_connection()->get_sequence_name('authors', 'author_id'), |
| 109 | + Author::table()->sequence |
| 110 | + ); |
97 | 111 | } else {
|
98 | 112 | $this->assertNull(Author::table()->sequence);
|
99 | 113 | }
|
@@ -363,36 +377,16 @@ public function testSetDateFlagsDirtyWithPhpDatetime()
|
363 | 377 | $this->assertArrayHasKey('some_date', $author->dirty_attributes());
|
364 | 378 | }
|
365 | 379 |
|
366 |
| - public function testWhereDeleteAll() |
| 380 | + public function testDeleteAll() |
367 | 381 | {
|
368 |
| - $num_affected = Author::where('parent_author_id = ?', 2)->delete_all(); |
| 382 | + $num_affected = Author::where('parent_author_id = 2')->delete_all(); |
369 | 383 | $this->assertEquals(2, $num_affected);
|
370 | 384 | }
|
371 | 385 |
|
372 |
| - public function testDistinctDeleteAllNotSupported() |
| 386 | + public function testDeleteAllWithDistinct() |
373 | 387 | {
|
374 | 388 | $this->expectException(ActiveRecordException::class);
|
375 |
| - Author::distinct()->delete_all(); |
376 |
| - } |
377 |
| - |
378 |
| - public function testDeleteAll() |
379 |
| - { |
380 |
| - $num_affected = Author::delete_all(); |
381 |
| - $this->assertEquals(5, $num_affected); |
382 |
| - } |
383 |
| - |
384 |
| - public function testDeleteAllWithLimitAndOrder() |
385 |
| - { |
386 |
| - if (!ConnectionManager::get_connection()->accepts_limit_and_order_for_update_and_delete()) { |
387 |
| - $this->markTestSkipped('Only MySQL & Sqlite accept limit/order with UPDATE clause'); |
388 |
| - } |
389 |
| - |
390 |
| - $num_affected = Author::limit(1) |
391 |
| - ->order('name asc') |
392 |
| - ->where(['parent_author_id = ?', 2]) |
393 |
| - ->delete_all(); |
394 |
| - $this->assertEquals(1, $num_affected); |
395 |
| - $this->assertTrue(false !== strpos(Author::table()->last_sql, 'ORDER BY name asc LIMIT 1')); |
| 389 | + Author::distinct()->where('parent_author_id = 2')->delete_all(); |
396 | 390 | }
|
397 | 391 |
|
398 | 392 | public function testUpdateAllWithSetAsString()
|
|
0 commit comments