mirror of
https://github.com/superhelio/commands.git
synced 2026-01-27 14:45:07 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83a07b225e | ||
|
|
9ca5301b77 | ||
|
|
5d3aab30c0 |
@@ -1,16 +0,0 @@
|
||||
# EditorConfig is awesome: https://editorconfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
max_line_length = 100
|
||||
|
||||
[*.yml]
|
||||
indent_size = 2
|
||||
|
||||
12
.github/workflows/auto-approve.yml
vendored
12
.github/workflows/auto-approve.yml
vendored
@@ -1,12 +0,0 @@
|
||||
name: Auto Approve Dependabot
|
||||
|
||||
on: pull_request_target
|
||||
|
||||
jobs:
|
||||
auto-approve:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: hmarr/auto-approve-action@v2.0.0
|
||||
if: github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]'
|
||||
with:
|
||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
45
.github/workflows/phpunit.yml
vendored
45
.github/workflows/phpunit.yml
vendored
@@ -1,45 +0,0 @@
|
||||
name: PHPUnit
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build-test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
php_version:
|
||||
- 7.4
|
||||
- 8.0
|
||||
- 8.1
|
||||
- 8.2
|
||||
- 8.3
|
||||
- latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php_version }}
|
||||
tools: composer, phpunit
|
||||
|
||||
- name: Get composer cache directory
|
||||
id: composer-cache
|
||||
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Cache Composer dependencies
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ steps.composer-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-${{ matrix.php_version }}-${{ hashFiles('**/composer.json') }}
|
||||
|
||||
- name: Install Dependencies
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
|
||||
- name: Configure matchers
|
||||
uses: mheap/phpunit-matcher-action@v1
|
||||
|
||||
- name: Run tests
|
||||
run: composer test-ci
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1 @@
|
||||
vendor
|
||||
composer.lock
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
$finder = (new PhpCsFixer\Finder())
|
||||
->in(__DIR__);
|
||||
|
||||
return (new PhpCsFixer\Config())
|
||||
->setRules([
|
||||
'@PhpCsFixer' => true,
|
||||
'@PHP74Migration' => true,
|
||||
'@PSR12' => true,
|
||||
'strict_param' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
])
|
||||
->setFinder($finder)
|
||||
;
|
||||
20
.travis.yml
Normal file
20
.travis.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
language: php
|
||||
php:
|
||||
- 7.0
|
||||
- 7.1
|
||||
- nightly
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: nightly
|
||||
fast_finish: true
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache/files
|
||||
before_script:
|
||||
- phpenv global "$TRAVIS_PHP_VERSION"
|
||||
- composer config extra.platform.php $TRAVIS_PHP_VERSION
|
||||
install:
|
||||
- flags="--ansi --prefer-dist --no-interaction --optimize-autoloader --no-suggest --no-progress"
|
||||
- travis_wait 30 composer install $flags
|
||||
script:
|
||||
- ./vendor/bin/phpunit -c phpunit.xml
|
||||
32
README.md
32
README.md
@@ -1,19 +1,22 @@
|
||||
# Laravel Commands by [SuperHelio][link-author]
|
||||
# Laravel Commands by [SuperHelio](link-author)
|
||||
|
||||
[![Latest Version on Packagist][ico-version]][link-packagist]
|
||||
[![Software License][ico-license]](LICENSE.md)
|
||||
[![Build Status][ico-travis]][link-travis]
|
||||
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
|
||||
[![Quality Score][ico-code-quality]][link-code-quality]
|
||||
[![Total Downloads][ico-downloads]][link-downloads]
|
||||
|
||||
This is a collection of Laravel Artisan commands created to help everyone
|
||||
in their development work. We try to keep these as useful as possible.
|
||||
|
||||
This package requires PHP 7.3 or later. The `composer.lock` file has been generated with PHP v7.4.13.
|
||||
This package requires PHP 7.0 or later. `composer.lock` has been generated with PHP v7.0.23.
|
||||
|
||||
## Install
|
||||
|
||||
### Step 1: Install Through Composer
|
||||
|
||||
```bash
|
||||
``` bash
|
||||
$ composer require superhelio/commands --dev
|
||||
```
|
||||
|
||||
@@ -24,7 +27,7 @@ You'll only want to use these generators for local development, so you don't wan
|
||||
```php
|
||||
public function register()
|
||||
{
|
||||
if ($this->app->environment() === 'local') {
|
||||
if ($this->app->environment() == 'local') {
|
||||
$this->app->register('SuperHelio\Commands\ServiceProvider');
|
||||
}
|
||||
}
|
||||
@@ -32,12 +35,12 @@ public function register()
|
||||
|
||||
## Usage
|
||||
|
||||
- _superhelio:gozer_
|
||||
- Force delete database tables that have your table prefix
|
||||
- `php artisan superhelio:gozer`
|
||||
- _superhelio:reload_
|
||||
- Reset database, migrate and seed
|
||||
- `php artisan superhelio:reload`
|
||||
- *superhelio:gozer*
|
||||
- Force delete database tables that have your table prefix
|
||||
- `php artisan superhelio:gozer`
|
||||
- *superhelio:reload*
|
||||
- Reset database, migrate and seed
|
||||
- `php artisan superhelio:reload`
|
||||
|
||||
## Change log
|
||||
|
||||
@@ -45,7 +48,7 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
``` bash
|
||||
$ composer test
|
||||
```
|
||||
|
||||
@@ -64,8 +67,15 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio
|
||||
|
||||
[ico-version]: https://img.shields.io/packagist/v/superhelio/commands.svg?style=flat-square
|
||||
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
|
||||
[ico-travis]: https://img.shields.io/travis/superhelio/commands/master.svg?style=flat-square
|
||||
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/superhelio/commands.svg?style=flat-square
|
||||
[ico-code-quality]: https://img.shields.io/scrutinizer/g/superhelio/commands.svg?style=flat-square
|
||||
[ico-downloads]: https://img.shields.io/packagist/dt/superhelio/commands.svg?style=flat-square
|
||||
|
||||
[link-packagist]: https://packagist.org/packages/superhelio/commands
|
||||
[link-travis]: https://travis-ci.org/superhelio/commands
|
||||
[link-scrutinizer]: https://scrutinizer-ci.com/g/superhelio/commands/code-structure
|
||||
[link-code-quality]: https://scrutinizer-ci.com/g/superhelio/commands
|
||||
[link-downloads]: https://packagist.org/packages/superhelio/commands
|
||||
[link-author]: https://github.com/superhelio
|
||||
[link-contributors]: https://github.com/superhelio/commands/graphs/contributors
|
||||
|
||||
@@ -17,15 +17,13 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.4|^8",
|
||||
"illuminate/support": "^5.3|^6|^7|^8|^9|^10|^11",
|
||||
"doctrine/dbal": "^2.5|^2.6|^3"
|
||||
"php" : ">=7.0",
|
||||
"illuminate/support": "^5.3|^5.4|^5.5",
|
||||
"doctrine/dbal": "^2.5|^2.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"roave/security-advisories": "dev-master",
|
||||
"phpunit/phpunit": "^8.0",
|
||||
"orchestra/testbench": "^3.3|^4|^5|^6|^7|^8",
|
||||
"friendsofphp/php-cs-fixer": "^3.9"
|
||||
"phpunit/phpunit" : "^5.0",
|
||||
"orchestra/testbench": "~3.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -38,13 +36,16 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --diff --allow-risky=yes",
|
||||
"test": "phpunit",
|
||||
"test-ci": "phpunit --teamcity"
|
||||
"test": "phpunit"
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0-dev"
|
||||
},
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Superhelio\\Commands\\ServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3489
composer.lock
generated
Normal file
3489
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
phpcs.xml
19
phpcs.xml
@@ -1,19 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="Project"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
|
||||
<description>Project PHP Code Style Rules</description>
|
||||
|
||||
<file>src</file>
|
||||
<file>tests</file>
|
||||
|
||||
<arg name="basepath" value="."/>
|
||||
<arg name="colors"/>
|
||||
<arg name="parallel" value="75"/>
|
||||
<arg value="np"/>
|
||||
|
||||
<exclude-pattern>*/.git/*</exclude-pattern>
|
||||
<exclude-pattern>*/vendor/*</exclude-pattern>
|
||||
|
||||
<rule ref="PSR2" />
|
||||
</ruleset>
|
||||
@@ -7,7 +7,8 @@
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false">
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Superhelio\Commands Test Suite">
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Superhelio\Commands\Commands;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Gozer extends Command
|
||||
{
|
||||
@@ -76,14 +75,16 @@ class Gozer extends Command
|
||||
*/
|
||||
$tables = $this->getFilteredTables($tables);
|
||||
|
||||
// Check that we got at least one table, bail out if not
|
||||
/**
|
||||
* Check that we got at least one table, bail out if not
|
||||
*/
|
||||
if ($tables->count() < 1) {
|
||||
$this->info('There are no tables, only Zuul.');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Bid your farewells to these tables.
|
||||
* Last look and confirmation.
|
||||
*/
|
||||
@@ -93,22 +94,27 @@ class Gozer extends Command
|
||||
));
|
||||
$this->line('');
|
||||
|
||||
// Last confirmation before dropping tables
|
||||
/**
|
||||
* Last confirmation before dropping tables
|
||||
*/
|
||||
if ($this->confirm('Really delete those tables?')) {
|
||||
|
||||
/** Fancy pants progress bar to see your tables get destroyed */
|
||||
$bar = $this->output->createProgressBar($tables->count());
|
||||
|
||||
Schema::disableForeignKeyConstraints();
|
||||
$tables->each(function ($table) use ($bar, $connection) {
|
||||
// Drop the table
|
||||
|
||||
/** Drop the table */
|
||||
$connection->dropTable($table);
|
||||
|
||||
// Advance our progress bar
|
||||
/** Advance our progress bar */
|
||||
$bar->advance();
|
||||
|
||||
});
|
||||
Schema::enableForeignKeyConstraints();
|
||||
|
||||
// Progress bar is now finished
|
||||
/** Progress bar is now finished */
|
||||
$bar->finish();
|
||||
}
|
||||
|
||||
@@ -127,16 +133,20 @@ class Gozer extends Command
|
||||
public function getConnection()
|
||||
{
|
||||
try {
|
||||
// @var \Doctrine\DBAL\Schema\AbstractSchemaManager $connection
|
||||
return app('db')->connection()->getDoctrineSchemaManager();
|
||||
/** @var \Doctrine\DBAL\Schema\AbstractSchemaManager $connection */
|
||||
$connection = app('db')->connection()->getDoctrineSchemaManager();
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $connection
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function getTables(\Doctrine\DBAL\Schema\AbstractSchemaManager $connection)
|
||||
@@ -155,11 +165,11 @@ class Gozer extends Command
|
||||
|
||||
public function getDatabasePrefix()
|
||||
{
|
||||
return trim(DB::connection()->getTablePrefix());
|
||||
return trim(DB::getTablePrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* This is mainly for testing purposes.
|
||||
* This is mainly for testing purposes
|
||||
*
|
||||
* @param string $prefix
|
||||
*/
|
||||
@@ -169,7 +179,7 @@ class Gozer extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|\Illuminate\Support\Collection $tables
|
||||
* @param array $tables
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
@@ -178,7 +188,7 @@ class Gozer extends Command
|
||||
$prefix = $this->dbPrefix;
|
||||
|
||||
return collect($tables)->reject(function ($table) use ($prefix) {
|
||||
return !Str::startsWith($table, $prefix);
|
||||
return !starts_with($table, $prefix);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ class Reload extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'superhelio:reload';
|
||||
protected $signature = 'superhelio:reload
|
||||
{--automate=false : Should run without questions?}
|
||||
{--loud=true : Should output reset and migrate outputs?}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -27,28 +29,51 @@ class Reload extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if ($this->confirm('Rollback all your database tables, recreate them and seed?')) {
|
||||
$this->call(
|
||||
'migrate:reset',
|
||||
[
|
||||
'--no-interaction' => true,
|
||||
'--env' => 'development',
|
||||
'--verbose' => 3,
|
||||
]
|
||||
);
|
||||
$this->call(
|
||||
'migrate',
|
||||
[
|
||||
'--seed' => true,
|
||||
'--no-interaction' => true,
|
||||
'--env' => 'development',
|
||||
'--verbose' => 3,
|
||||
]
|
||||
);
|
||||
$automated = $this->automate();
|
||||
|
||||
return true;
|
||||
if ($automated && $this->confirm('Rollback all your database tables, recreate them and seed?')) {
|
||||
return $this->runReload();
|
||||
}
|
||||
if (!$automated) {
|
||||
return $this->runReload();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
public function automate()
|
||||
{
|
||||
$automate = $this->option('automate');
|
||||
|
||||
return !($automate === '1' || $automate === 1 || $automate === 'yes' || $automate === 'true');
|
||||
}
|
||||
|
||||
public function outputVerbosity()
|
||||
{
|
||||
$output = $this->option('loud');
|
||||
|
||||
return ($output === '1' || $output === 1 || $output == 'yes' || $output == 'true');
|
||||
}
|
||||
|
||||
public function runReload()
|
||||
{
|
||||
$verbose = ($this->outputVerbosity() ? 3 : 0);
|
||||
$this->call(
|
||||
'migrate:reset',
|
||||
[
|
||||
'--no-interaction' => true,
|
||||
'--env' => 'development',
|
||||
'--verbose' => $verbose
|
||||
]
|
||||
);
|
||||
$this->call(
|
||||
'migrate',
|
||||
[
|
||||
'--seed' => true,
|
||||
'--no-interaction' => true,
|
||||
'--env' => 'development',
|
||||
'--verbose' => $verbose
|
||||
]
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ namespace Superhelio\Commands;
|
||||
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
||||
|
||||
/**
|
||||
* Class PackageServiceProvider.
|
||||
* Class PackageServiceProvider
|
||||
*
|
||||
* @package Superhelio\Commands
|
||||
* @see http://laravel.com/docs/master/packages#service-providers
|
||||
* @see http://laravel.com/docs/master/providers
|
||||
*/
|
||||
@@ -16,7 +17,6 @@ class ServiceProvider extends BaseServiceProvider
|
||||
* Indicates if loading of the provider is deferred.
|
||||
*
|
||||
* @see http://laravel.com/docs/master/providers#deferred-providers
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $defer = false;
|
||||
@@ -25,6 +25,7 @@ class ServiceProvider extends BaseServiceProvider
|
||||
* Register the service provider.
|
||||
*
|
||||
* @see http://laravel.com/docs/master/providers#the-register-method
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
@@ -35,7 +36,7 @@ class ServiceProvider extends BaseServiceProvider
|
||||
private function registerReloader()
|
||||
{
|
||||
$this->app->singleton('command.superhelio.reload', function ($app) {
|
||||
return $app[\Superhelio\Commands\Commands\Reload::class];
|
||||
return $app['Superhelio\Commands\Commands\Reload'];
|
||||
});
|
||||
$this->commands('command.superhelio.reload');
|
||||
}
|
||||
@@ -43,7 +44,7 @@ class ServiceProvider extends BaseServiceProvider
|
||||
private function registerGozer()
|
||||
{
|
||||
$this->app->singleton('command.superhelio.gozer', function ($app) {
|
||||
return $app[\Superhelio\Commands\Commands\Gozer::class];
|
||||
return $app['Superhelio\Commands\Commands\Gozer'];
|
||||
});
|
||||
$this->commands('command.superhelio.gozer');
|
||||
}
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Superhelio\Commands\Tests;
|
||||
namespace Superhelio\Commands;
|
||||
|
||||
use ReflectionClass;
|
||||
use Superhelio\Commands\Commands\Gozer;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class GozerTest extends \Orchestra\Testbench\TestCase
|
||||
{
|
||||
/**
|
||||
* Setup the test environment.
|
||||
*/
|
||||
public function setUp(): void
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->artisan('migrate', ['--database' => 'testbench']);
|
||||
@@ -25,7 +21,9 @@ class GozerTest extends \Orchestra\Testbench\TestCase
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
@@ -45,90 +43,90 @@ class GozerTest extends \Orchestra\Testbench\TestCase
|
||||
* In a normal app environment these would be added to
|
||||
* the 'providers' array in the config/app.php file.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [
|
||||
\Superhelio\Commands\Tests\Stubs\ServiceProvider::class,
|
||||
\Superhelio\Commands\ServiceProvider::class,
|
||||
'\Superhelio\Commands\Tests\Stubs\ServiceProvider',
|
||||
'\Superhelio\Commands\ServiceProvider'
|
||||
];
|
||||
}
|
||||
|
||||
public function testDatabaseIsThereAndFunctions()
|
||||
public function test_database_is_there_and_functions()
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'name' => 'User name',
|
||||
'email' => 'hello@gozer.dev',
|
||||
'password' => bcrypt('123'),
|
||||
'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));
|
||||
$this->assertEquals('hello@gozer.dev', $users->email);
|
||||
$this->assertEquals('User name', $users->name);
|
||||
$this->assertTrue(Hash::check('123', $users->password));
|
||||
}
|
||||
|
||||
public function testDbalIsInstalled()
|
||||
public function test_dbal_is_installed()
|
||||
{
|
||||
self::assertTrue(class_exists('\\Doctrine\\DBAL\\Schema\\Schema'));
|
||||
$this->assertTrue(class_exists('\\Doctrine\\DBAL\\Schema\\Schema'));
|
||||
}
|
||||
|
||||
public function testGozerIsInstalled()
|
||||
public function test_gozer_is_installed()
|
||||
{
|
||||
self::assertTrue(class_exists('\\Superhelio\\Commands\\Commands\\Gozer'));
|
||||
$this->assertTrue(class_exists('\\Superhelio\\Commands\\Commands\\Gozer'));
|
||||
}
|
||||
|
||||
public function testGozerHasRequiredMethodsAndProperties()
|
||||
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'));
|
||||
$this->assertTrue($gozer->hasMethod('handle'));
|
||||
$this->assertTrue($gozer->hasProperty('signature'));
|
||||
$this->assertTrue($gozer->hasProperty('description'));
|
||||
$this->assertTrue($gozer->hasProperty('dbPrefix'));
|
||||
}
|
||||
|
||||
public function testGozerFindsDatabasePrefix()
|
||||
public function test_gozer_finds_database_prefix()
|
||||
{
|
||||
$gozer = new Gozer();
|
||||
|
||||
self::assertEquals('gozerTest__', $gozer->getDatabasePrefix());
|
||||
$this->assertEquals('gozerTest__', $gozer->getDatabasePrefix());
|
||||
}
|
||||
|
||||
public function testGozerFindsUsersTable()
|
||||
public function test_gozer_finds_users_table()
|
||||
{
|
||||
$gozer = new Gozer();
|
||||
|
||||
$connection = $gozer->getConnection();
|
||||
|
||||
$tables = $gozer->getTables($connection);
|
||||
self::assertContains('gozerTest__users', $tables);
|
||||
$this->assertTrue(\in_array('gozerTest__users', $tables, false));
|
||||
|
||||
$gozer->setDatabasePrefix('gozerTest__');
|
||||
$filteredTables = $gozer->getFilteredTables($tables);
|
||||
self::assertTrue(is_a($filteredTables, \Illuminate\Support\Collection::class));
|
||||
self::assertContains('gozerTest__users', $filteredTables->toArray());
|
||||
$this->assertTrue(is_a($filteredTables, \Illuminate\Support\Collection::class));
|
||||
$this->assertTrue(\in_array('gozerTest__users', $filteredTables->toArray(), false));
|
||||
}
|
||||
|
||||
public function testGozerTableFilteringWorks()
|
||||
public function test_gozer_table_filtering_works()
|
||||
{
|
||||
$gozer = new Gozer();
|
||||
$tables = [
|
||||
$tables = array(
|
||||
'gozerTest__users',
|
||||
'gozerTest__migrations',
|
||||
'this_should_be_filtered',
|
||||
'filter_me_too',
|
||||
];
|
||||
'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);
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
24
tests/PackageTest.php
Normal file
24
tests/PackageTest.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Superhelio\Commands;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
class PackageTest extends \Orchestra\Testbench\TestCase
|
||||
{
|
||||
public function test_facade()
|
||||
{
|
||||
$facade = new ReflectionClass(Facade::class);
|
||||
$this->assertTrue($facade->hasMethod('getFacadeAccessor'));
|
||||
$this->assertTrue($facade->getMethod('getFacadeAccessor')->isProtected());
|
||||
$this->assertTrue($facade->getMethod('getFacadeAccessor')->isStatic());
|
||||
}
|
||||
|
||||
public function test_service_provider()
|
||||
{
|
||||
$sp = new ReflectionClass(\Superhelio\Commands\ServiceProvider::class);
|
||||
$this->assertTrue($sp->hasMethod('register'));
|
||||
$this->assertTrue($sp->hasMethod('registerReloader'));
|
||||
$this->assertTrue($sp->hasMethod('registerGozer'));
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Superhelio\Commands\Tests;
|
||||
namespace Superhelio\Commands;
|
||||
|
||||
use ReflectionClass;
|
||||
use Superhelio\Commands\Commands\Reload;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class ReloadTest extends \Orchestra\Testbench\TestCase
|
||||
{
|
||||
public function testReloadTest()
|
||||
/**
|
||||
* Setup the test environment.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
self::assertTrue(true);
|
||||
parent::setUp();
|
||||
$this->artisan('migrate', ['--database' => 'testbench']);
|
||||
}
|
||||
|
||||
public function testReloadIsInstalled()
|
||||
/**
|
||||
* Define environment setup.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
self::assertTrue(class_exists('\\Superhelio\\Commands\\Commands\\Reload'));
|
||||
// Setup default database to use sqlite :memory:
|
||||
$app['config']->set('database.default', 'testbench');
|
||||
$app['config']->set('database.connections.testbench', [
|
||||
'driver' => 'sqlite',
|
||||
'database' => ':memory:',
|
||||
'prefix' => 'reloadTest__',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testReloadHasRequiredMethodsAndProperties()
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$reload = new \ReflectionClass('\\Superhelio\\Commands\\Commands\\Reload');
|
||||
self::assertTrue($reload->hasMethod('handle'));
|
||||
self::assertTrue($reload->hasProperty('signature'));
|
||||
self::assertTrue($reload->hasProperty('description'));
|
||||
return [
|
||||
'\Superhelio\Commands\Tests\Stubs\ServiceProvider',
|
||||
'\Superhelio\Commands\ServiceProvider'
|
||||
];
|
||||
}
|
||||
|
||||
public function test_reload_exists()
|
||||
{
|
||||
$this->assertTrue(class_exists(Reload::class));
|
||||
$reload = new Reload();
|
||||
|
||||
$this->assertInstanceOf(Reload::class, $reload);
|
||||
}
|
||||
|
||||
public function test_reload_has_required_methods_and_properties()
|
||||
{
|
||||
$reload = new Reload();
|
||||
$this->assertTrue(method_exists($reload, 'handle'), 'handle');
|
||||
$this->assertTrue(method_exists($reload, 'runReload'), 'runReload');
|
||||
$this->assertTrue(method_exists($reload, 'automate'), 'automate');
|
||||
|
||||
$reload = new ReflectionClass(Reload::class);
|
||||
$this->assertTrue($reload->hasProperty('signature'), 'signature');
|
||||
$this->assertTrue($reload->hasProperty('description'), 'description');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Superhelio\Commands\Tests\Stubs;
|
||||
|
||||
class ServiceProvider extends \Illuminate\Support\ServiceProvider
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
$this->loadMigrationsFrom(dirname(__DIR__).'/migrations');
|
||||
$this->loadMigrationsFrom(\dirname(__DIR__) . '/migrations');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ class CreateUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
@@ -23,6 +25,8 @@ class CreateUsersTable extends Migration
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user