mirror of
https://github.com/superhelio/commands.git
synced 2026-01-26 03:33:59 +00:00
New Gozer tests, exposed methods for public usage (mainly for testing)
This commit is contained in:
@@ -60,9 +60,7 @@ class Gozer extends Command
|
||||
|
||||
');
|
||||
|
||||
$tables = [];
|
||||
|
||||
$this->dbPrefix = $this->getDatabasePrefix();
|
||||
$this->setDatabasePrefix($this->getDatabasePrefix());
|
||||
|
||||
$confirmationQuestion = 'Delete all of your database tables?';
|
||||
if (!empty($this->dbPrefix)) {
|
||||
@@ -139,7 +137,7 @@ class Gozer extends Command
|
||||
/**
|
||||
* @return bool|\Doctrine\DBAL\Schema\AbstractSchemaManager
|
||||
*/
|
||||
private function getConnection()
|
||||
public function getConnection()
|
||||
{
|
||||
try {
|
||||
/** @var \Doctrine\DBAL\Schema\AbstractSchemaManager $connection */
|
||||
@@ -158,7 +156,7 @@ class Gozer extends Command
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
private function getTables(\Doctrine\DBAL\Schema\AbstractSchemaManager $connection)
|
||||
public function getTables(\Doctrine\DBAL\Schema\AbstractSchemaManager $connection)
|
||||
{
|
||||
try {
|
||||
/** @var array $tables */
|
||||
@@ -172,17 +170,27 @@ class Gozer extends Command
|
||||
return $tables;
|
||||
}
|
||||
|
||||
private function getDatabasePrefix()
|
||||
public function getDatabasePrefix()
|
||||
{
|
||||
return trim(DB::getTablePrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* This is mainly for testing purposes
|
||||
*
|
||||
* @param string $prefix
|
||||
*/
|
||||
public function setDatabasePrefix($prefix = '')
|
||||
{
|
||||
$this->dbPrefix = $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $tables
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
private function getFilteredTables($tables = [])
|
||||
public function getFilteredTables($tables = [])
|
||||
{
|
||||
$prefix = $this->dbPrefix;
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@ namespace Superhelio\Commands;
|
||||
|
||||
use ReflectionClass;
|
||||
use Superhelio\Commands\Commands\Gozer;
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
@@ -84,6 +82,50 @@ class GozerTest extends \Orchestra\Testbench\TestCase
|
||||
{
|
||||
$gozer = new ReflectionClass('\\Superhelio\\Commands\\Commands\\Gozer');
|
||||
$this->assertTrue($gozer->hasMethod('handle'));
|
||||
$this->assertTrue($gozer->hasProperty('signature'));
|
||||
$this->assertTrue($gozer->hasProperty('description'));
|
||||
$this->assertTrue($gozer->hasProperty('dbPrefix'));
|
||||
}
|
||||
|
||||
public function test_gozer_finds_database_prefix()
|
||||
{
|
||||
$gozer = new Gozer();
|
||||
|
||||
$this->assertEquals('gozerTest__', $gozer->getDatabasePrefix());
|
||||
}
|
||||
|
||||
public function test_gozer_finds_users_table()
|
||||
{
|
||||
$gozer = new Gozer();
|
||||
|
||||
$connection = $gozer->getConnection();
|
||||
|
||||
$tables = $gozer->getTables($connection);
|
||||
$this->assertTrue(in_array('gozerTest__users', $tables, false));
|
||||
|
||||
$gozer->setDatabasePrefix('gozerTest__');
|
||||
$filteredTables = $gozer->getFilteredTables($tables);
|
||||
$this->assertTrue(is_a($filteredTables, \Illuminate\Support\Collection::class));
|
||||
$this->assertTrue(in_array('gozerTest__users', $filteredTables->toArray(), false));
|
||||
}
|
||||
|
||||
public function test_gozer_table_filtering_works()
|
||||
{
|
||||
$gozer = new Gozer();
|
||||
$tables = array(
|
||||
'gozerTest__users',
|
||||
'gozerTest__migrations',
|
||||
'this_should_be_filtered',
|
||||
'filter_me_too'
|
||||
);
|
||||
|
||||
$gozer->setDatabasePrefix('gozerTest__');
|
||||
$filtered = $gozer->getFilteredTables($tables);
|
||||
$array = $filtered->toArray();
|
||||
|
||||
$this->assertFalse(in_array('this_should_be_filtered', $array, false));
|
||||
$this->assertFalse(in_array('filter_me_too', $array, false));
|
||||
$this->assertTrue(in_array('gozerTest__users', $array, false));
|
||||
$this->assertTrue(in_array('gozerTest__migrations', $array, false));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user