Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"require": {
"php": "^7.3 || ^8.0",
"dragon-code/contracts": "^2.15",
"dragon-code/laravel-support": "^3.2",
"dragon-code/laravel-support": "^3.3",
"illuminate/console": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"illuminate/database": "^6.0 || ^7.0 || ^8.0 || ^9.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0",
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions src/Concerns/Anonymous.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace DragonCode\LaravelActions\Concerns;

use DragonCode\LaravelSupport\Facades\AppVersion;

trait Anonymous
{
protected function allowAnonymous(): bool
{
return AppVersion::is('8.37.0');
}

protected function disallowAnonymous(): bool
{
return ! $this->allowAnonymous();
}
}
20 changes: 0 additions & 20 deletions src/Concerns/Versionable.php

This file was deleted.

6 changes: 4 additions & 2 deletions src/Support/MigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace DragonCode\LaravelActions\Support;

use DragonCode\LaravelSupport\Facades\AppVersion;
use DragonCode\LaravelActions\Concerns\Anonymous;
use Illuminate\Database\Migrations\MigrationCreator as BaseMigrationCreator;
use Illuminate\Filesystem\Filesystem;

class MigrationCreator extends BaseMigrationCreator
{
use Anonymous;

protected $customStubPath;

public function __construct(Filesystem $files, ?string $custom_stub_path)
Expand All @@ -31,7 +33,7 @@ public function stubPath()

protected function getStub($table, $create): string
{
$stub = AppVersion::is9x() ? '/action-9.x.stub' : '/action-prev.stub';
$stub = $this->allowAnonymous() ? '/action-anonymous.stub' : '/action-named.stub';

return $this->files->get(
$this->stubPath() . $stub
Expand Down
8 changes: 4 additions & 4 deletions src/Support/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use DragonCode\Contracts\LaravelActions\Actionable as ActionableContract;
use DragonCode\LaravelActions\Concerns\Infoable;
use DragonCode\LaravelActions\Concerns\Versionable;
use DragonCode\LaravelActions\Concerns\Anonymous;
use Illuminate\Database\Migrations\Migrator as BaseMigrator;
use Illuminate\Support\Facades\DB;
use Throwable;

class Migrator extends BaseMigrator
{
use Infoable;
use Versionable;
use Anonymous;

public function usingConnection($name, callable $callback)
{
Expand All @@ -39,7 +39,7 @@ protected function runUp($file, $batch, $pretend)
// First we will resolve a "real" instance of the migration class from this
// migration file name. Once we have the instances we can run the actual
// command such as "up" or "down", or we can just simulate the action.
if ($this->isLatestApp()) {
if ($this->allowAnonymous()) {
$migration = $this->resolvePath($file);

$name = $this->getMigrationName($file);
Expand Down Expand Up @@ -90,7 +90,7 @@ protected function runUp($file, $batch, $pretend)
*/
protected function runDown($file, $migration, $pretend)
{
if ($this->isLatestApp()) {
if ($this->allowAnonymous()) {
$instance = $this->resolvePath($file);

$name = $this->getMigrationName($file);
Expand Down
4 changes: 2 additions & 2 deletions tests/Commands/CreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testCreateAction()

public function testDuplicateOnPrev()
{
if ($this->isLatestApp()) {
if ($this->allowAnonymous()) {
$this->assertTrue(true);

return;
Expand All @@ -41,7 +41,7 @@ public function testDuplicateOnPrev()

public function testDuplicateOnLatest()
{
if ($this->isPrevApp()) {
if ($this->disallowAnonymous()) {
$this->assertTrue(true);

return;
Expand Down
7 changes: 3 additions & 4 deletions tests/Commands/MakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Commands;

use DragonCode\LaravelSupport\Facades\AppVersion;
use Tests\TestCase;

class MakeTest extends TestCase
Expand All @@ -21,9 +20,9 @@ public function testMakingFiles()

$this->assertFileExists($path);

$expected = AppVersion::is9x()
? __DIR__ . '/../fixtures/app/9.x/stubs/make_example.stub'
: __DIR__ . '/../fixtures/app/prev/stubs/make_example.stub';
$expected = $this->allowAnonymous()
? __DIR__ . '/../fixtures/app/anonymous/stubs/make_example.stub'
: __DIR__ . '/../fixtures/app/named/stubs/make_example.stub';

$this->assertEquals(file_get_contents($expected), file_get_contents($path));
}
Expand Down
8 changes: 3 additions & 5 deletions tests/Concerns/Actionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Tests\Concerns;

use DragonCode\LaravelSupport\Facades\AppVersion;

trait Actionable
{
protected function getMigrationPath(): string
{
return AppVersion::is9x()
? __DIR__ . '/../fixtures/app/9.x/actions'
: __DIR__ . '/../fixtures/app/prev/actions';
return $this->allowAnonymous()
? __DIR__ . '/../fixtures/app/anonymous/actions'
: __DIR__ . '/../fixtures/app/named/actions';
}
}
30 changes: 15 additions & 15 deletions tests/Concerns/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,45 @@ protected function freshFiles(): void

protected function copyFiles(): void
{
$source = $this->isLatestApp()
? __DIR__ . '/../fixtures/app/9.x/actions'
: __DIR__ . '/../fixtures/app/prev/actions';
$source = $this->allowAnonymous()
? __DIR__ . '/../fixtures/app/anonymous/actions'
: __DIR__ . '/../fixtures/app/named/actions';

File::copyDirectory($source, $this->targetDirectory());
}

protected function copySuccessFailureMethod()
{
$source = $this->isLatestApp()
? __DIR__ . '/../fixtures/app/9.x/actions_failed/2021_12_23_165048_run_success_on_failed.php'
: __DIR__ . '/../fixtures/app/prev/actions_failed/2021_12_23_165048_run_success_on_failed.php';
$source = $this->allowAnonymous()
? __DIR__ . '/../fixtures/app/anonymous/actions_failed/2021_12_23_165048_run_success_on_failed.php'
: __DIR__ . '/../fixtures/app/named/actions_failed/2021_12_23_165048_run_success_on_failed.php';

File::copy($source, $this->targetDirectory('2021_12_23_165048_run_success_on_failed.php'));
}

protected function copyFailedMethod()
{
$source = $this->isLatestApp()
? __DIR__ . '/../fixtures/app/9.x/actions_failed/2021_12_23_184029_run_failed_failure.php'
: __DIR__ . '/../fixtures/app/prev/actions_failed/2021_12_23_184029_run_failed_failure.php';
$source = $this->allowAnonymous()
? __DIR__ . '/../fixtures/app/anonymous/actions_failed/2021_12_23_184029_run_failed_failure.php'
: __DIR__ . '/../fixtures/app/named/actions_failed/2021_12_23_184029_run_failed_failure.php';

File::copy($source, $this->targetDirectory('2021_12_23_184029_run_failed_failure.php'));
}

protected function copySuccessTransaction(): void
{
$source = $this->isLatestApp()
? __DIR__ . '/../fixtures/app/9.x/stubs/2021_02_15_124237_test_success_transactions.stub'
: __DIR__ . '/../fixtures/app/prev/stubs/2021_02_15_124237_test_success_transactions.stub';
$source = $this->allowAnonymous()
? __DIR__ . '/../fixtures/app/anonymous/stubs/2021_02_15_124237_test_success_transactions.stub'
: __DIR__ . '/../fixtures/app/named/stubs/2021_02_15_124237_test_success_transactions.stub';

File::copy($source, $this->targetDirectory('2021_02_15_124237_test_success_transactions.php'));
}

protected function copyFailedTransaction(): void
{
$source = $this->isLatestApp()
? __DIR__ . '/../fixtures/app/9.x/stubs/2021_02_15_124852_test_failed_transactions.stub'
: __DIR__ . '/../fixtures/app/prev/stubs/2021_02_15_124852_test_failed_transactions.stub';
$source = $this->allowAnonymous()
? __DIR__ . '/../fixtures/app/anonymous/stubs/2021_02_15_124852_test_failed_transactions.stub'
: __DIR__ . '/../fixtures/app/named/stubs/2021_02_15_124852_test_failed_transactions.stub';

File::copy($source, $this->targetDirectory('2021_02_15_124852_test_failed_transactions.php'));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests;

use DragonCode\LaravelActions\Concerns\Versionable;
use DragonCode\LaravelActions\Concerns\Anonymous;
use DragonCode\LaravelActions\ServiceProvider;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
Expand All @@ -17,13 +17,13 @@
abstract class TestCase extends BaseTestCase
{
use Actionable;
use Anonymous;
use AssertDatabase;
use Database;
use Files;
use Laraveable;
use RefreshDatabase;
use Settings;
use Versionable;

protected function setUp(): void
{
Expand Down