Skip to content

Commit 93e42ee

Browse files
Merge pull request #205 from TheDragonCode/7.x
Added `OperationHelper`
2 parents 4ac6e7e + 4b0d31c commit 93e42ee

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

ide.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,29 @@
1818
}
1919
]
2020
}
21+
],
22+
"completions": [
23+
{
24+
"complete": "directoryFiles",
25+
"condition": [
26+
{
27+
"classFqn": [
28+
"DragonCode\\LaravelDeployOperations\\Helpers\\OperationHelper"
29+
],
30+
"methodNames": [
31+
"run"
32+
],
33+
"place": "parameter",
34+
"parameters": [
35+
1
36+
]
37+
}
38+
],
39+
"options": {
40+
"directory": "operations",
41+
"suffixToClear": ".php",
42+
"recursive": true
43+
}
44+
}
2145
]
2246
}

src/Helpers/OperationHelper.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelDeployOperations\Helpers;
6+
7+
use DragonCode\LaravelDeployOperations\Console\OperationsCommand;
8+
use DragonCode\LaravelDeployOperations\Constants\Options;
9+
use Illuminate\Support\Collection;
10+
use Illuminate\Support\Facades\Artisan;
11+
12+
class OperationHelper
13+
{
14+
public static function run(?string $path = null, ?bool $realpath = null): void
15+
{
16+
$parameters = (new Collection())
17+
->when($path, fn (Collection $items) => $items->put('--' . Options::Path, $path))
18+
->when($realpath, fn (Collection $items) => $items->put('--' . Options::Realpath, true))
19+
->all();
20+
21+
Artisan::call(OperationsCommand::class, $parameters);
22+
}
23+
}

tests/Helpers/OperationTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Helpers;
6+
7+
use DragonCode\LaravelDeployOperations\Constants\Names;
8+
use DragonCode\LaravelDeployOperations\Helpers\OperationHelper;
9+
use Tests\TestCase;
10+
11+
class OperationTest extends TestCase
12+
{
13+
public function testSuccess(): void
14+
{
15+
$this->assertDatabaseDoesntTable($this->table);
16+
17+
$this->artisan(Names::Install)->assertExitCode(0);
18+
19+
$this->assertDatabaseHasTable($this->table);
20+
$this->assertDatabaseCount($this->table, 0);
21+
22+
$this->artisan(Names::Make, ['name' => 'TestMigration'])->assertExitCode(0);
23+
24+
OperationHelper::run();
25+
26+
$this->assertDatabaseCount($this->table, 1);
27+
$this->assertDatabaseOperationHas($this->table, 'test_migration');
28+
}
29+
30+
public function testPath(): void
31+
{
32+
$this->copyFiles();
33+
34+
$table = 'test';
35+
36+
$path = 'sub_path/2021_12_15_205804_baz.php';
37+
38+
$this->artisan(Names::Install)->assertExitCode(0);
39+
40+
$this->assertDatabaseCount($table, 0);
41+
$this->assertDatabaseCount($this->table, 0);
42+
$this->assertDatabaseOperationDoesntLike($this->table, 'baz');
43+
44+
OperationHelper::run($path);
45+
46+
$this->assertDatabaseCount($table, 1);
47+
$this->assertDatabaseCount($this->table, 1);
48+
$this->assertDatabaseOperationHas($this->table, 'baz');
49+
50+
$this->assertSame('sub_path/2021_12_15_205804_baz', $this->table()->first()->operation);
51+
}
52+
}

0 commit comments

Comments
 (0)