This repository was archived by the owner on Apr 1, 2023. It is now read-only.
forked from spatie/db-dumper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert all tests to Pest (spatie#188)
* feat: install Pest * refactor: MongoDbTest * refactor: MySqlTest * refactor: PostgreSqlTest * refactor: SqliteTest * feat: replace test suite in Github action and `composer.json`
- Loading branch information
1 parent
7f75307
commit 53e1bbd
Showing
7 changed files
with
853 additions
and
978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,111 @@ | ||
<?php | ||
|
||
namespace Spatie\DbDumper\Test; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Spatie\DbDumper\Compressors\Bzip2Compressor; | ||
use Spatie\DbDumper\Compressors\GzipCompressor; | ||
use Spatie\DbDumper\Databases\MongoDb; | ||
use Spatie\DbDumper\Exceptions\CannotStartDump; | ||
|
||
class MongoDbTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_provides_a_factory_method() | ||
{ | ||
$this->assertInstanceOf(MongoDb::class, MongoDb::create()); | ||
} | ||
|
||
/** @test */ | ||
public function it_will_throw_an_exception_when_no_credentials_are_set() | ||
{ | ||
$this->expectException(CannotStartDump::class); | ||
|
||
MongoDb::create()->dumpToFile('test.gz'); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_dump_command() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
$this->assertSame('\'mongodump\' --db dbname' | ||
.' --archive --host localhost --port 27017 > "dbname.gz"', $dumpCommand); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_dump_command_with_gzip_compressor_enabled() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->useCompressor(new GzipCompressor()) | ||
->getDumpCommand('dbname.gz'); | ||
|
||
$expected = '((((\'mongodump\' --db dbname --archive --host localhost --port 27017; echo $? >&3) | gzip > "dbname.gz") 3>&1) | (read x; exit $x))'; | ||
|
||
$this->assertSame($expected, $dumpCommand); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_dump_command_with_bzip2_compressor_enabled() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->useCompressor(new Bzip2Compressor()) | ||
->getDumpCommand('dbname.bz2'); | ||
|
||
$expected = '((((\'mongodump\' --db dbname --archive --host localhost --port 27017; echo $? >&3) | bzip2 > "dbname.bz2") 3>&1) | (read x; exit $x))'; | ||
|
||
$this->assertSame($expected, $dumpCommand); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_dump_command_with_absolute_path_having_space_and_brackets() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->getDumpCommand('/save/to/new (directory)/dbname.gz'); | ||
|
||
$this->assertSame('\'mongodump\' --db dbname --archive --host localhost --port 27017 > "/save/to/new (directory)/dbname.gz"', $dumpCommand); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_dump_command_with_username_and_password() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setUserName('username') | ||
->setPassword('password') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
$this->assertSame('\'mongodump\' --db dbname --archive' | ||
.' --username \'username\' --password \'password\' --host localhost --port 27017 > "dbname.gz"', $dumpCommand); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_command_with_custom_host_and_port() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setHost('mongodb.test.com') | ||
->setPort(27018) | ||
->getDumpCommand('dbname.gz'); | ||
|
||
$this->assertSame('\'mongodump\' --db dbname --archive' | ||
.' --host mongodb.test.com --port 27018 > "dbname.gz"', $dumpCommand); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_backup_command_for_a_single_collection() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setCollection('mycollection') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
$this->assertSame('\'mongodump\' --db dbname --archive' | ||
.' --host localhost --port 27017 --collection mycollection > "dbname.gz"', $dumpCommand); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_dump_command_with_custom_binary_path() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setDumpBinaryPath('/custom/directory') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
$this->assertSame('\'/custom/directory/mongodump\' --db dbname --archive' | ||
.' --host localhost --port 27017 > "dbname.gz"', $dumpCommand); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_generate_a_dump_command_with_authentication_database() | ||
{ | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setAuthenticationDatabase('admin') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
$this->assertSame('\'mongodump\' --db dbname --archive' | ||
.' --host localhost --port 27017 --authenticationDatabase admin > "dbname.gz"', $dumpCommand); | ||
} | ||
} | ||
it('provides a factory method') | ||
->expect(MongoDb::create()) | ||
->toBeInstanceOf(MongoDb::class); | ||
|
||
it('will_throw_an_exception_when_no_credentials_are_set') | ||
->tap(fn () => MongoDb::create()->dumpToFile('test.gz')) | ||
->throws(CannotStartDump::class); | ||
|
||
it('can generate a dump command', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
expect($dumpCommand)->toEqual('\'mongodump\' --db dbname' | ||
. ' --archive --host localhost --port 27017 > "dbname.gz"'); | ||
}); | ||
|
||
it('can generate a dump command with gzip compressor enabled', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->useCompressor(new GzipCompressor()) | ||
->getDumpCommand('dbname.gz'); | ||
|
||
expect($dumpCommand)->toEqual( | ||
'((((\'mongodump\' --db dbname --archive --host localhost --port 27017; echo $? >&3) | gzip > "dbname.gz") 3>&1) | (read x; exit $x))' | ||
); | ||
}); | ||
|
||
it('can generate a dump command with bzip2 compressor enabled', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->useCompressor(new Bzip2Compressor()) | ||
->getDumpCommand('dbname.bz2'); | ||
|
||
expect($dumpCommand)->toEqual( | ||
'((((\'mongodump\' --db dbname --archive --host localhost --port 27017; echo $? >&3) | bzip2 > "dbname.bz2") 3>&1) | (read x; exit $x))' | ||
); | ||
}); | ||
|
||
it('can generate a dump command with absolute path having space and brackets', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->getDumpCommand('/save/to/new (directory)/dbname.gz'); | ||
|
||
expect($dumpCommand)->toEqual( | ||
'\'mongodump\' --db dbname --archive --host localhost --port 27017 > "/save/to/new (directory)/dbname.gz"' | ||
); | ||
}); | ||
|
||
it('can generate a dump command with username and password', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setUserName('username') | ||
->setPassword('password') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
expect($dumpCommand)->toEqual('\'mongodump\' --db dbname --archive' | ||
. ' --username \'username\' --password \'password\' --host localhost --port 27017 > "dbname.gz"'); | ||
}); | ||
|
||
it('can generate a command with custom host and port', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setHost('mongodb.test.com') | ||
->setPort(27018) | ||
->getDumpCommand('dbname.gz'); | ||
|
||
expect($dumpCommand)->toEqual('\'mongodump\' --db dbname --archive' | ||
. ' --host mongodb.test.com --port 27018 > "dbname.gz"'); | ||
}); | ||
|
||
it('can generate a backup command for a single collection', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setCollection('mycollection') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
expect($dumpCommand)->toEqual('\'mongodump\' --db dbname --archive' | ||
. ' --host localhost --port 27017 --collection mycollection > "dbname.gz"'); | ||
}); | ||
|
||
it('can generate a dump command with custom binary path', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setDumpBinaryPath('/custom/directory') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
expect($dumpCommand)->toEqual( | ||
'\'/custom/directory/mongodump\' --db dbname --archive' | ||
. ' --host localhost --port 27017 > "dbname.gz"' | ||
); | ||
}); | ||
|
||
it('can generate a dump command with authentication database', function () { | ||
$dumpCommand = MongoDb::create() | ||
->setDbName('dbname') | ||
->setAuthenticationDatabase('admin') | ||
->getDumpCommand('dbname.gz'); | ||
|
||
expect($dumpCommand)->toEqual( | ||
'\'mongodump\' --db dbname --archive' | ||
. ' --host localhost --port 27017 --authenticationDatabase admin > "dbname.gz"' | ||
); | ||
}); |
Oops, something went wrong.