mirror of
https://github.com/superhelio/commands.git
synced 2026-01-26 11:44:01 +00:00
132 lines
4.0 KiB
PHP
132 lines
4.0 KiB
PHP
<?php
|
|
namespace Superhelio\Commands\Tests;
|
|
|
|
use ReflectionClass;
|
|
use Superhelio\Commands\Commands\Gozer;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class GozerTest extends \Orchestra\Testbench\TestCase
|
|
{
|
|
/**
|
|
* Setup the test environment.
|
|
*/
|
|
public function setUp() : void
|
|
{
|
|
parent::setUp();
|
|
$this->artisan('migrate', ['--database' => 'testbench']);
|
|
}
|
|
|
|
/**
|
|
* Define environment setup.
|
|
*
|
|
* @param \Illuminate\Foundation\Application $app
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function getEnvironmentSetUp($app)
|
|
{
|
|
// Setup default database to use sqlite :memory:
|
|
$app['config']->set('database.default', 'testbench');
|
|
$app['config']->set('database.connections.testbench', [
|
|
'driver' => 'sqlite',
|
|
'database' => ':memory:',
|
|
'prefix' => 'gozerTest__',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Get package providers.
|
|
* At a minimum this is the package being tested, but also
|
|
* would include packages upon which our package depends.
|
|
* In a normal app environment these would be added to
|
|
* the 'providers' array in the config/app.php file.
|
|
*
|
|
* @param \Illuminate\Foundation\Application $app
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getPackageProviders($app)
|
|
{
|
|
return [
|
|
\Superhelio\Commands\Tests\Stubs\ServiceProvider::class,
|
|
\Superhelio\Commands\ServiceProvider::class
|
|
];
|
|
}
|
|
|
|
public function test_database_is_there_and_functions()
|
|
{
|
|
DB::table('users')->insert([
|
|
'name' => 'User name',
|
|
'email' => 'hello@gozer.dev',
|
|
'password' => bcrypt('123')
|
|
]);
|
|
|
|
$users = DB::table('users')->where('id', '=', 1)->first();
|
|
self::assertEquals('hello@gozer.dev', $users->email);
|
|
self::assertEquals('User name', $users->name);
|
|
self::assertTrue(Hash::check('123', $users->password));
|
|
}
|
|
|
|
public function test_dbal_is_installed()
|
|
{
|
|
self::assertTrue(class_exists('\\Doctrine\\DBAL\\Schema\\Schema'));
|
|
}
|
|
|
|
public function test_gozer_is_installed()
|
|
{
|
|
self::assertTrue(class_exists('\\Superhelio\\Commands\\Commands\\Gozer'));
|
|
}
|
|
|
|
public function test_gozer_has_required_methods_and_properties()
|
|
{
|
|
$gozer = new ReflectionClass('\\Superhelio\\Commands\\Commands\\Gozer');
|
|
self::assertTrue($gozer->hasMethod('handle'));
|
|
self::assertTrue($gozer->hasProperty('signature'));
|
|
self::assertTrue($gozer->hasProperty('description'));
|
|
self::assertTrue($gozer->hasProperty('dbPrefix'));
|
|
}
|
|
|
|
public function test_gozer_finds_database_prefix()
|
|
{
|
|
$gozer = new Gozer();
|
|
|
|
self::assertEquals('gozerTest__', $gozer->getDatabasePrefix());
|
|
}
|
|
|
|
public function test_gozer_finds_users_table()
|
|
{
|
|
$gozer = new Gozer();
|
|
|
|
$connection = $gozer->getConnection();
|
|
|
|
$tables = $gozer->getTables($connection);
|
|
self::assertContains( 'gozerTest__users', $tables );
|
|
|
|
$gozer->setDatabasePrefix('gozerTest__');
|
|
$filteredTables = $gozer->getFilteredTables($tables);
|
|
self::assertTrue(is_a($filteredTables, \Illuminate\Support\Collection::class));
|
|
self::assertContains( 'gozerTest__users', $filteredTables->toArray() );
|
|
}
|
|
|
|
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();
|
|
|
|
self::assertNotContains( 'this_should_be_filtered', $array );
|
|
self::assertNotContains( 'filter_me_too', $array );
|
|
self::assertContains( 'gozerTest__users', $array );
|
|
self::assertContains( 'gozerTest__migrations', $array );
|
|
}
|
|
}
|