Skip to content

Commit

Permalink
WIP: change tests order
Browse files Browse the repository at this point in the history
  • Loading branch information
WatheqAlshowaiter committed Aug 24, 2024
1 parent 5b59bb3 commit 48f1ea3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 51 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
executionOrder="defects"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
executionOrder="defects"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
Expand Down
114 changes: 67 additions & 47 deletions tests/BackupTablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ class BackupTablesTest extends TestCase

public function test_return_when_table_is_not_correct()
{
dump([1 => __FUNCTION__]);
$tableName = 'not_correct_table_name';

$this->assertFalse(BackupTables::generateBackup($tableName));
}

public function test_return_when_table_string_empty()
{
dump([2 => __FUNCTION__]);

$emptyString = '';
$emptyArray = [];

Expand All @@ -36,6 +39,8 @@ public function test_return_when_table_string_empty()

public function test_generate_single_table_backup_with_proper_name()
{
dump([2 => __FUNCTION__]);

Carbon::setTestNow();

$tableName = 'fathers';
Expand All @@ -46,26 +51,15 @@ public function test_generate_single_table_backup_with_proper_name()
$this->assertTrue(Schema::hasTable($newTableName));
}

public function test_generate_single_table_backup_with_with_custom_format()
{
Carbon::setTestNow();
$tableName = 'fathers';
$customFormat = 'Y_d_m_H_i';

BackupTables::generateBackup($tableName, $customFormat);

$newTableName = $tableName.'_backup_'.now()->format($customFormat);

$this->assertTrue(Schema::hasTable($newTableName));
}

public function test_generate_single_table_backup_all_table_data()
{
dump([3=> __FUNCTION__]);

Carbon::setTestNow();
$tableName = 'fathers';

Father::create([
'id' => 1,
'first_name' => 'Ahmed',
'last_name' => 'Saleh',
'email' => '[email protected]',
Expand Down Expand Up @@ -95,6 +89,8 @@ public function test_generate_single_table_backup_all_table_data()

public function test_generate_single_table_backup_with_different_data()
{
dump([4=> __FUNCTION__]);

Carbon::setTestNow();
$tableName = 'mothers';

Expand Down Expand Up @@ -127,6 +123,8 @@ public function test_generate_single_table_backup_with_different_data()

public function test_generate_2_single_table_backup_all_table_data()
{
dump([5 => __FUNCTION__]);

Carbon::setTestNow();
$fatherTable = 'fathers';
$sonTable = 'sons';
Expand Down Expand Up @@ -172,43 +170,64 @@ public function test_generate_2_single_table_backup_all_table_data()
$this->assertEquals(DB::table('sons')->value('father_id'), DB::table($newSonTable)->value('father_id'));
}

//public function test_generate_multiple_table_backup()
//{
// Carbon::setTestNow();
// $tableName = 'fathers';
// $tableName2 = 'sons';
//
// Father::create([
// 'id' => 1,
// 'first_name' => 'Ahmed',
// 'last_name' => 'Saleh',
// 'email' => '[email protected]',
// ]);
//
// Son::create([
// 'father_id' => Father::value('id')
// ]);
//
// BackupTables::generateBackup([$tableName, $tableName2]);
//
// $newTableName = $tableName.'_backup_'.now()->format('Y_m_d_H_i_s');
// $newTableName2 = $tableName2.'_backup_'.now()->format('Y_m_d_H_i_s');
//
// $this->assertTrue(Schema::hasTable($newTableName));
// $this->assertTrue(Schema::hasTable($newTableName2));
//
// $this->assertEquals(DB::table($tableName)->value('first_name'), DB::table($newTableName)->value('first_name'));
// $this->assertEquals(DB::table($tableName)->value('email'), DB::table($newTableName)->value('email'));
//
// if (DB::getDriverName() == 'mysql' || DB::getDriverName() == 'mariadb' || (float) App::version() >= Constants::VERSION_AFTER_STORED_AS_VIRTUAL_AS_SUPPORT) {
// $this->assertEquals(DB::table($tableName)->value('full_name'), DB::table($newTableName)->value('full_name')); // StoredAs tables
// }
//
// $this->assertEquals(DB::table($tableName2)->value('father_id'), DB::table($newTableName2)->value('father_id')); // foreign key
//}
public function test_generate_multiple_table_backup()
{
dump([6 => __FUNCTION__]);

Carbon::setTestNow();
$tableName = 'fathers';
$tableName2 = 'sons';

Father::create([
'id' => 1,
'first_name' => 'Ahmed',
'last_name' => 'Saleh',
'email' => '[email protected]',
]);

Son::create([
'father_id' => Father::value('id')
]);

BackupTables::generateBackup([$tableName, $tableName2]);

$newTableName = $tableName.'_backup_'.now()->format('Y_m_d_H_i_s');
$newTableName2 = $tableName2.'_backup_'.now()->format('Y_m_d_H_i_s');

$this->assertTrue(Schema::hasTable($newTableName));
$this->assertTrue(Schema::hasTable($newTableName2));

$this->assertEquals(DB::table($tableName)->value('first_name'), DB::table($newTableName)->value('first_name'));
$this->assertEquals(DB::table($tableName)->value('email'), DB::table($newTableName)->value('email'));

if (DB::getDriverName() == 'mysql' || DB::getDriverName() == 'mariadb' || (float) App::version() >= Constants::VERSION_AFTER_STORED_AS_VIRTUAL_AS_SUPPORT) {
$this->assertEquals(DB::table($tableName)->value('full_name'), DB::table($newTableName)->value('full_name')); // StoredAs tables
}

$this->assertEquals(DB::table($tableName2)->value('father_id'), DB::table($newTableName2)->value('father_id')); // foreign key
}



public function test_generate_single_table_backup_with_with_custom_format()
{
dump([7 => __FUNCTION__]);

Carbon::setTestNow();
$tableName = 'fathers';
$customFormat = 'Y_d_m_H_i';

BackupTables::generateBackup($tableName, $customFormat);

$newTableName = $tableName.'_backup_'.now()->format($customFormat);

$this->assertTrue(Schema::hasTable($newTableName));
}

//public function test_generate_multiple_models_backup()
//{
//dump([8 => __FUNCTION__]);

// Carbon::setTestNow();
// $tableName = Father::class;
// $tableName2 = Son::class;
Expand Down Expand Up @@ -244,4 +263,5 @@ public function test_generate_2_single_table_backup_all_table_data()
//
// $this->assertEquals(DB::table($tableName2)->value('father_id'), DB::table($newTableName2)->value('father_id')); // foreign key
//}

}
4 changes: 2 additions & 2 deletions todos.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
- [x] add database drop list (sqlite, mysql, sql server, mariadb, postgres) + version for each of them in the ISSUE_TEMPLATE, and make it required and even add it to the next
- [x] extract `mysql 8`, `mysql 5.7` and `mariadb` in separate GitHub actions if the still conflicts with each other and works fine alone.
- [x] fix for foreign keys, and return foreign key father_id
- [ ] fix for MySQL 5.7 with new implementation
- [ ] fix for SQL Server
- [x] fix for MySQL 5.7 with new implementation
- [x] fix for SQL Server
- [ ] return back all tests
- [ ] check the console output when backup is correct and make in tests (prefer)
- [ ] return back pint formatting GitHub actions
Expand Down

0 comments on commit 48f1ea3

Please sign in to comment.