63 Commits

Author SHA1 Message Date
Ismo Vuorinen
61ac97155c feat: update dependencies, add linting, fix codebase, cleanup (#11)
* chore(deps): update dependencies

* feat(tests): add matrix testing, problem matcher

* feat(lint): add php-cs-fixer, fix codebase
2024-11-08 18:40:40 +02:00
dfd2dc0d8a Merge pull request #8 from superhelio/dependabot/composer/laravel/framework-8.83.27 2023-02-02 08:59:49 +02:00
dependabot[bot]
b35379840e Bump laravel/framework from 8.40.0 to 8.83.27
Bumps [laravel/framework](https://github.com/laravel/framework) from 8.40.0 to 8.83.27.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/9.x/CHANGELOG.md)
- [Commits](https://github.com/laravel/framework/compare/v8.40.0...v8.83.27)

---
updated-dependencies:
- dependency-name: laravel/framework
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-02 06:58:27 +00:00
cf40294ccc Merge pull request #7 from superhelio/dependabot/composer/symfony/http-kernel-5.4.20 2023-02-02 08:58:01 +02:00
dependabot[bot]
15e48db012 Bump symfony/http-kernel from 5.2.6 to 5.4.20
Bumps [symfony/http-kernel](https://github.com/symfony/http-kernel) from 5.2.6 to 5.4.20.
- [Release notes](https://github.com/symfony/http-kernel/releases)
- [Changelog](https://github.com/symfony/http-kernel/blob/6.2/CHANGELOG.md)
- [Commits](https://github.com/symfony/http-kernel/compare/v5.2.6...v5.4.20)

---
updated-dependencies:
- dependency-name: symfony/http-kernel
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-01 22:19:10 +00:00
837c27e126 Merge pull request #6 from superhelio/actions-phpunit
Github Actions: PHPUnit
2021-08-02 10:54:26 +03:00
9a29937b1b added xdebug and mbstring 2021-06-29 13:14:59 +03:00
ee0ea99680 Create phpunit.yml 2021-06-29 13:08:50 +03:00
e1f7575dd7 Merge pull request #5 from superhelio/dependabot/composer/league/flysystem-1.1.4
Bump league/flysystem from 1.1.3 to 1.1.4
2021-06-29 13:00:33 +03:00
dependabot[bot]
d42dc0e4b5 Bump league/flysystem from 1.1.3 to 1.1.4
Bumps [league/flysystem](https://github.com/thephpleague/flysystem) from 1.1.3 to 1.1.4.
- [Release notes](https://github.com/thephpleague/flysystem/releases)
- [Changelog](https://github.com/thephpleague/flysystem/blob/2.x/CHANGELOG.md)
- [Commits](https://github.com/thephpleague/flysystem/compare/1.1.3...1.1.4)

---
updated-dependencies:
- dependency-name: league/flysystem
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-06-29 05:24:23 +00:00
ded480fd29 Merge pull request #4 from superhelio/dependabot/composer/laravel/framework-8.40.0
Bump laravel/framework from 8.26.1 to 8.40.0
2021-04-30 10:24:12 +03:00
dependabot[bot]
c987038e44 Bump laravel/framework from 8.26.1 to 8.40.0
Bumps [laravel/framework](https://github.com/laravel/framework) from 8.26.1 to 8.40.0.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/8.x/CHANGELOG-8.x.md)
- [Commits](https://github.com/laravel/framework/compare/v8.26.1...v8.40.0)

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-29 22:34:20 +00:00
528a4f06a3 Update auto-approve.yml 2021-02-18 19:16:54 +02:00
2cd7420fe3 Auto Approve Dependabot 2021-02-18 16:54:57 +02:00
8a9ad3faf7 Merge pull request #3 from superhelio/dependabot/composer/laravel/framework-8.26.1
Bump laravel/framework from 8.23.1 to 8.26.1
2021-02-02 19:36:38 +02:00
dependabot[bot]
c1e58d03a7 Bump laravel/framework from 8.23.1 to 8.26.1
Bumps [laravel/framework](https://github.com/laravel/framework) from 8.23.1 to 8.26.1.
- [Release notes](https://github.com/laravel/framework/releases)
- [Changelog](https://github.com/laravel/framework/blob/8.x/CHANGELOG-8.x.md)
- [Commits](https://github.com/laravel/framework/compare/v8.23.1...v8.26.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-02 16:28:30 +00:00
2d0eeef248 Merge pull request #2 from superhelio/feat/maintenance-2021
Updated requirements
2021-01-21 12:33:36 +02:00
Ismo Vuorinen
c0ba631f42 PSR2 fixes 2021-01-20 14:18:42 +02:00
Ismo Vuorinen
dd33dcbb61 Updated requirements 2021-01-20 11:44:34 +02:00
7985d7c777 Merge pull request #1 from superhelio/dependabot/composer/symfony/http-foundation-3.4.36
Bump symfony/http-foundation from 3.3.10 to 3.4.36
2019-12-10 11:07:10 +02:00
dependabot[bot]
8d14242960 Bump symfony/http-foundation from 3.3.10 to 3.4.36
Bumps [symfony/http-foundation](https://github.com/symfony/http-foundation) from 3.3.10 to 3.4.36.
- [Release notes](https://github.com/symfony/http-foundation/releases)
- [Changelog](https://github.com/symfony/http-foundation/blob/master/CHANGELOG.md)
- [Commits](https://github.com/symfony/http-foundation/compare/v3.3.10...v3.4.36)

Signed-off-by: dependabot[bot] <support@github.com>
2019-12-04 14:24:47 +00:00
Ismo Vuorinen
310d5979e9 Merge branch 'release/1.2.0' 2017-10-19 10:58:52 +03:00
Ismo Vuorinen
06039cdcfd Changelog 2017-10-19 10:58:37 +03:00
Ismo Vuorinen
fcb274d3d6 Upgrading required PHP version to >=7.0
This bump is because it took really long time to find suitable packages
for PHP 5.6.
2017-10-19 10:40:05 +03:00
Ismo Vuorinen
8bc16492f6 Changed require-dev phpunit version limits to include ^4.0 2017-10-03 08:20:24 +03:00
Ismo Vuorinen
0cb85af737 Merge branch 'release/1.1.2' 2017-09-15 19:24:49 +03:00
Ismo Vuorinen
662acf0b48 Merge branch 'release/1.1.2' into develop 2017-09-15 19:24:49 +03:00
Ismo Vuorinen
37f35eeb26 CHANGELOG 2017-09-15 19:24:17 +03:00
Ismo Vuorinen
8fe5df77fb PHP5.6 composer install takes a long time... 2017-09-15 18:35:46 +03:00
Ismo Vuorinen
6140c7b999 Testing settings for travis-ci build config 2017-09-15 07:20:25 +03:00
Ismo Vuorinen
3d635a04b9 Merge branch 'release/1.1.1' 2017-08-27 19:48:36 +03:00
Ismo Vuorinen
4f51fd8c51 Typo fixes, composer.lock and removal of dead code. Ready for v1.1.1. 2017-08-27 19:48:06 +03:00
Ismo Vuorinen
6eb2e1499c Merge branch 'release/1.1.0'
# Conflicts:
#	CHANGELOG.md
2017-08-27 19:22:57 +03:00
Ismo Vuorinen
cf7d4d37de Release CHANGELOG and few fixes to README 2017-08-27 19:20:53 +03:00
Ismo Vuorinen
8aa4639b04 New Gozer tests, exposed methods for public usage (mainly for testing) 2017-08-27 19:04:42 +03:00
Ismo Vuorinen
3e9d7e8b06 PHP Code Sniffer fixes 2017-02-27 13:32:13 +02:00
Ismo Vuorinen
f14a1d8769 Gozer: Refactoring and tests 2017-02-14 13:47:33 +02:00
Ismo Vuorinen
5fe7412588 Dropping 5.6 from travis for now. Will investigate later. 2017-02-10 11:53:36 +02:00
Ismo Vuorinen
bbd501c2d6 Travis.yml cache settings to speed up our testing 2017-02-10 10:25:46 +02:00
Ismo Vuorinen
0509cbb2fb Typo in autoload-dev class mapping, removed Orchestra\Testbench 2017-02-10 10:12:28 +02:00
Ismo Vuorinen
f146683ae4 Mirroring Orhestra\Testbench travis config 2017-02-10 10:03:17 +02:00
Ismo Vuorinen
5ca3d391ad Another attempt to make travis find our classes 2017-02-10 10:01:29 +02:00
Ismo Vuorinen
8e49c144fd Autoloader addition, Orchestra\Testbench could not be found 2017-02-10 09:55:39 +02:00
Ismo Vuorinen
bb18cdd30f Setup error cleaning 2017-02-10 09:51:42 +02:00
Ismo Vuorinen
ab0a5a8d9d Testing Orchestra/TestBench workflow 2017-02-10 09:48:40 +02:00
Ismo Vuorinen
3d236cb55e Just get to the green already 2017-02-08 14:51:47 +02:00
Ismo Vuorinen
1dc771dfaa Moving from Laravel TestCase to \PHPUnit_Framework_TestCase 2017-02-08 14:49:53 +02:00
Ismo Vuorinen
239f5d718c phpunit.xml 2017-02-08 14:46:37 +02:00
Ismo Vuorinen
03405ded71 Add base tests to get something out 2017-02-08 14:43:20 +02:00
Ismo Vuorinen
0e0c094071 Documentation, fixes and better messages 2017-02-08 14:27:00 +02:00
Ismo Vuorinen
313dfec8d8 New command: superhelio:gozer, the Destroyer 2017-02-08 14:04:52 +02:00
Ismo Vuorinen
8c9e0ff85a Set better description to superhelio:reload 2017-02-08 14:04:13 +02:00
Ismo Vuorinen
4cd5eb29f4 TravisCI config 2017-02-08 10:29:36 +02:00
Ismo Vuorinen
a470911429 Merge branch 'release/1.0.0' into develop 2017-02-08 10:25:02 +02:00
Ismo Vuorinen
2cf81a2d98 Merge branch 'release/1.0.0'
# Conflicts:
#	CHANGELOG.md
2017-02-08 10:24:25 +02:00
Ismo Vuorinen
ee3fefbe63 Changelog 2017-02-08 10:22:02 +02:00
Ismo Vuorinen
be99c75812 Fixed Scrutinizer reported issue 2017-02-08 10:20:33 +02:00
Ismo Vuorinen
671bb0300b Updated changelog 2017-02-07 17:47:29 +02:00
Ismo Vuorinen
20fd92412e New changelog, testing github_changelog_generator out 2017-02-07 17:45:41 +02:00
Ismo Vuorinen
fffc0ff9ca Renamed LICENSE 2017-02-07 17:45:00 +02:00
Ismo Vuorinen
25840e0c5c Merge branch 'release/0.0.1' into develop 2017-02-07 17:24:32 +02:00
Ismo Vuorinen
5132d97534 Merge branch 'release/0.0.1'
# Conflicts:
#	CHANGELOG.md
2017-02-07 17:24:21 +02:00
Ismo Vuorinen
1ae74443c9 Initial commit, superhelio:reload 2017-02-07 17:23:28 +02:00
19 changed files with 592 additions and 48 deletions

16
.editorconfig Normal file
View File

@@ -0,0 +1,16 @@
# 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 Normal file
View File

@@ -0,0 +1,12 @@
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 Normal file
View File

@@ -0,0 +1,45 @@
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

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
vendor
composer.lock

15
.php-cs-fixer.dist.php Normal file
View File

@@ -0,0 +1,15 @@
<?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)
;

View File

@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## 0.0.1 - 2017-02-07 ## [1.2.0](https://github.com/superhelio/commands/tree/1.2.0) (2017-10-19)
### Added - Bumped PHP version requirement to >=7.0, PHP5.6 was taking really long time to resolve
- `superhelio:reload` - Included composer.lock, which is generated with PHP v7.0.23
## [1.1.2](https://github.com/superhelio/commands/tree/1.1.2) (2017-09-15)
- Removed composer.lock, only to enable correct CI builds
- Reworked travis-ci.org configuration, builds should now go green
## [1.1.1](https://github.com/superhelio/commands/tree/1.1.1) (2017-08-27)
- Typo fixes
- Removal of dead/unnecessary code
- Added composer.lock for faster builds
## [1.1.0](https://github.com/superhelio/commands/tree/1.1.0) (2017-08-27)
- New command: `superhelio:gozer` with tests
## [1.0.0](https://github.com/superhelio/commands/tree/1.0.0) (2017-02-08)
- Fixed Scrutinizer reported issue
- Renamed LICENSE
- Tested `github_changelog_generator`, but did not like it
## [0.0.1](https://github.com/superhelio/commands/tree/0.0.1) (2017-02-07)
- `superhelio:reload`

View File

View File

@@ -1,20 +1,19 @@
# Laravel Commands by [SuperHelio](link-author) # Laravel Commands by [SuperHelio][link-author]
[![Latest Version on Packagist][ico-version]][link-packagist] [![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md) [![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] [![Total Downloads][ico-downloads]][link-downloads]
This is a collection of Laravel Artisan commands created to help everyone 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. 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.
## Install ## Install
### Step 1: Install Through Composer ### Step 1: Install Through Composer
``` bash ```bash
$ composer require superhelio/commands --dev $ composer require superhelio/commands --dev
``` ```
@@ -25,7 +24,7 @@ You'll only want to use these generators for local development, so you don't wan
```php ```php
public function register() public function register()
{ {
if ($this->app->environment() == 'local') { if ($this->app->environment() === 'local') {
$this->app->register('SuperHelio\Commands\ServiceProvider'); $this->app->register('SuperHelio\Commands\ServiceProvider');
} }
} }
@@ -33,9 +32,12 @@ public function register()
## Usage ## Usage
- *superhelio:reload* - _superhelio:gozer_
- Reset database, migrate and seed - Force delete database tables that have your table prefix
- `php artisan superhelio:reload` - `php artisan superhelio:gozer`
- _superhelio:reload_
- Reset database, migrate and seed
- `php artisan superhelio:reload`
## Change log ## Change log
@@ -43,14 +45,10 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen
## Testing ## Testing
``` bash ```bash
$ composer test $ composer test
``` ```
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Security ## Security
If you discover any security related issues, please contact [SuperHelio](link-author). If you discover any security related issues, please contact [SuperHelio](link-author).
@@ -66,15 +64,9 @@ 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-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-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 [ico-downloads]: https://img.shields.io/packagist/dt/superhelio/commands.svg?style=flat-square
[link-packagist]: https://packagist.org/packages/superhelio/commands [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-downloads]: https://packagist.org/packages/superhelio/commands
[link-author]: https://github.com/superhelio [link-author]: https://github.com/superhelio
[link-contributors]: ../../contributors [link-contributors]: https://github.com/superhelio/commands/graphs/contributors
[link-dbal]: https://packagist.org/packages/doctrine/dbal

View File

@@ -1,6 +1,6 @@
{ {
"name": "superhelio/commands", "name": "superhelio/commands",
"description": "Laravel Commands", "description": "This is a collection of Laravel Artisan commands created to help everyone in their development work.",
"keywords": [ "keywords": [
"laravel", "laravel",
"superhelio", "superhelio",
@@ -17,11 +17,15 @@
} }
], ],
"require": { "require": {
"php" : ">=5.5.0", "php": "^7.4|^8",
"illuminate/support": "~5.2" "illuminate/support": "^5.3|^6|^7|^8|^9|^10|^11",
"doctrine/dbal": "^2.5|^2.6|^3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit" : "4.*" "roave/security-advisories": "dev-master",
"phpunit/phpunit": "^8.0",
"orchestra/testbench": "^3.3|^4|^5|^6|^7|^8",
"friendsofphp/php-cs-fixer": "^3.9"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@@ -30,11 +34,13 @@
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Superhelio\\Commands\\Test\\": "tests" "Superhelio\\Commands\\Tests\\": "tests"
} }
}, },
"scripts": { "scripts": {
"test": "phpunit" "lint": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --diff --allow-risky=yes",
"test": "phpunit",
"test-ci": "phpunit --teamcity"
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {

19
phpcs.xml Normal file
View File

@@ -0,0 +1,19 @@
<?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>

26
phpunit.xml Normal file
View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Superhelio\Commands Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
</php>
<filter>
<whitelist addUncoveredFilesFromWhitelist="false">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>

184
src/Commands/Gozer.php Normal file
View File

@@ -0,0 +1,184 @@
<?php
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
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'superhelio:gozer';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Force delete database tables that have your table prefix';
/**
* @var string Database table prefix
*/
private $dbPrefix = '';
/**
* Execute the console command.
*
* @return bool
*/
public function handle()
{
if (!class_exists('\\Doctrine\\DBAL\\Schema\\Schema')) {
$this->error('You are missing doctrine/dbal, you should add it to your project:');
$this->info('composer require doctrine/dbal');
return false;
}
$this->info('
________
/ _____/ ____________ ___________
/ \ ___ / _ \___ // __ \_ __ \
\ \_\ ( <_> ) /\ ___/| | \/
\______ /\____/_____ \\___ >__|
\/ \/ \/
');
$this->setDatabasePrefix($this->getDatabasePrefix());
$confirmationQuestion = 'Delete all of your database tables?';
if (!empty($this->dbPrefix)) {
$confirmationQuestion = sprintf(
'Delete your tables that begin with %s*',
$this->dbPrefix
);
}
if ($this->confirm($confirmationQuestion)) {
$connection = $this->getConnection();
$tables = $this->getTables($connection);
/**
* Reject tables that do not have specified table prefix.
* We would not want to destroy other tables that might
* be in the same database, in "homestead" for example.
*
* @var \Illuminate\Support\Collection $tables
*/
$tables = $this->getFilteredTables($tables);
// 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.
*/
$this->info(sprintf(
"Tables found:\n - %s",
implode(",\n - ", $tables->toArray())
));
$this->line('');
// 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
$connection->dropTable($table);
// Advance our progress bar
$bar->advance();
});
Schema::enableForeignKeyConstraints();
// Progress bar is now finished
$bar->finish();
}
$this->line('');
$this->line('');
}
$this->info('Done.');
return true;
}
/**
* @return bool|\Doctrine\DBAL\Schema\AbstractSchemaManager
*/
public function getConnection()
{
try {
// @var \Doctrine\DBAL\Schema\AbstractSchemaManager $connection
return app('db')->connection()->getDoctrineSchemaManager();
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
}
/**
* @return array|bool
*/
public function getTables(\Doctrine\DBAL\Schema\AbstractSchemaManager $connection)
{
try {
/** @var array $tables */
$tables = $connection->listTableNames();
} catch (\Exception $e) {
$this->error($e->getMessage());
return false;
}
return $tables;
}
public function getDatabasePrefix()
{
return trim(DB::connection()->getTablePrefix());
}
/**
* This is mainly for testing purposes.
*
* @param string $prefix
*/
public function setDatabasePrefix($prefix = '')
{
$this->dbPrefix = $prefix;
}
/**
* @param array|\Illuminate\Support\Collection $tables
*
* @return \Illuminate\Support\Collection
*/
public function getFilteredTables($tables = [])
{
$prefix = $this->dbPrefix;
return collect($tables)->reject(function ($table) use ($prefix) {
return !Str::startsWith($table, $prefix);
});
}
}

View File

@@ -18,17 +18,7 @@ class Reload extends Command
* *
* @var string * @var string
*/ */
protected $description = 'Delete database tables, migrate and run seeds'; protected $description = 'Rollback migrations, migrate and run seeds';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/** /**
* Execute the console command. * Execute the console command.
@@ -43,7 +33,7 @@ class Reload extends Command
[ [
'--no-interaction' => true, '--no-interaction' => true,
'--env' => 'development', '--env' => 'development',
'--verbose' => 3 '--verbose' => 3,
] ]
); );
$this->call( $this->call(
@@ -52,9 +42,13 @@ class Reload extends Command
'--seed' => true, '--seed' => true,
'--no-interaction' => true, '--no-interaction' => true,
'--env' => 'development', '--env' => 'development',
'--verbose' => 3 '--verbose' => 3,
] ]
); );
return true;
} }
return false;
} }
} }

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Superhelio\Commands; namespace Superhelio\Commands;
class Facade extends \Illuminate\Support\Facades\Facade class Facade extends \Illuminate\Support\Facades\Facade

View File

@@ -5,9 +5,8 @@ namespace Superhelio\Commands;
use Illuminate\Support\ServiceProvider as BaseServiceProvider; 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/packages#service-providers
* @see http://laravel.com/docs/master/providers * @see http://laravel.com/docs/master/providers
*/ */
@@ -17,6 +16,7 @@ class ServiceProvider extends BaseServiceProvider
* Indicates if loading of the provider is deferred. * Indicates if loading of the provider is deferred.
* *
* @see http://laravel.com/docs/master/providers#deferred-providers * @see http://laravel.com/docs/master/providers#deferred-providers
*
* @var bool * @var bool
*/ */
protected $defer = false; protected $defer = false;
@@ -25,18 +25,26 @@ class ServiceProvider extends BaseServiceProvider
* Register the service provider. * Register the service provider.
* *
* @see http://laravel.com/docs/master/providers#the-register-method * @see http://laravel.com/docs/master/providers#the-register-method
* @return void
*/ */
public function register() public function register()
{ {
$this->registerReloader(); $this->registerReloader();
$this->registerGozer();
} }
private function registerReloader() private function registerReloader()
{ {
$this->app->singleton('command.superhelio.reload', function ($app) { $this->app->singleton('command.superhelio.reload', function ($app) {
return $app['Superhelio\Commands\Commands\Reload']; return $app[\Superhelio\Commands\Commands\Reload::class];
}); });
$this->commands('command.superhelio.reload'); $this->commands('command.superhelio.reload');
} }
private function registerGozer()
{
$this->app->singleton('command.superhelio.gozer', function ($app) {
return $app[\Superhelio\Commands\Commands\Gozer::class];
});
$this->commands('command.superhelio.gozer');
}
} }

134
tests/GozerTest.php Normal file
View File

@@ -0,0 +1,134 @@
<?php
namespace Superhelio\Commands\Tests;
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
{
parent::setUp();
$this->artisan('migrate', ['--database' => 'testbench']);
}
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*/
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 testDatabaseIsThereAndFunctions()
{
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 testDbalIsInstalled()
{
self::assertTrue(class_exists('\\Doctrine\\DBAL\\Schema\\Schema'));
}
public function testGozerIsInstalled()
{
self::assertTrue(class_exists('\\Superhelio\\Commands\\Commands\\Gozer'));
}
public function testGozerHasRequiredMethodsAndProperties()
{
$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 testGozerFindsDatabasePrefix()
{
$gozer = new Gozer();
self::assertEquals('gozerTest__', $gozer->getDatabasePrefix());
}
public function testGozerFindsUsersTable()
{
$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 testGozerTableFilteringWorks()
{
$gozer = new Gozer();
$tables = [
'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);
}
}

28
tests/ReloadTest.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace Superhelio\Commands\Tests;
/**
* @internal
* @coversNothing
*/
class ReloadTest extends \Orchestra\Testbench\TestCase
{
public function testReloadTest()
{
self::assertTrue(true);
}
public function testReloadIsInstalled()
{
self::assertTrue(class_exists('\\Superhelio\\Commands\\Commands\\Reload'));
}
public function testReloadHasRequiredMethodsAndProperties()
{
$reload = new \ReflectionClass('\\Superhelio\\Commands\\Commands\\Reload');
self::assertTrue($reload->hasMethod('handle'));
self::assertTrue($reload->hasProperty('signature'));
self::assertTrue($reload->hasProperty('description'));
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Superhelio\Commands\Tests\Stubs;
class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function boot()
{
$this->loadMigrationsFrom(dirname(__DIR__).'/migrations');
}
}

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down()
{
Schema::dropIfExists('users');
}
}