Skip to content

Commit ea4d537

Browse files
Merge pull request #214 from TheDragonCode/7.x
Added `operation` helper
2 parents f065b6d + 65efc79 commit ea4d537

13 files changed

+71
-7
lines changed

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@
6464
"autoload": {
6565
"psr-4": {
6666
"DragonCode\\LaravelDeployOperations\\": "src/"
67-
}
67+
},
68+
"files": [
69+
"src/helpers.php"
70+
]
6871
},
6972
"autoload-dev": {
7073
"psr-4": {
25.1 KB
Loading
20.6 KB
Loading
40.4 KB
Loading
36.3 KB
Loading
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
use function DragonCode\LaravelDeployOperations\operation;
8+
9+
return new class extends Migration {
10+
public function withOperation(): string
11+
{
12+
return operation('foo/2022_10_14_000002_test2');
13+
}
14+
};

docs/topics/operation-helper.topic

+12
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@
5858

5959
<code-block lang="bash" src="operations_helper.sh" include-lines="2" />
6060
</chapter>
61+
62+
<chapter title="Laravel Idea support" id="laravel_idea_support">
63+
<p>
64+
If you are using
65+
<a href="https://www.jetbrains.com/phpstorm/">JetBrains PhpStorm</a>
66+
with the
67+
<a href="https://laravel-idea.com">Laravel Idea</a> plugin installed,
68+
you can use the <code>operation</code> function to autocomplete.
69+
</p>
70+
71+
<img src="operation_helper_class.png" alt="operation helper" />
72+
</chapter>
6173
</topic>

docs/topics/running-operations.topic

+18
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,23 @@
262262
When the <code>%artisan% migrate:rollback</code> console command is called,
263263
the operation will call the <code>down</code> method if it exists in the operation file.
264264
</p>
265+
266+
<chapter title="Laravel Idea support" id="laravel_idea_support">
267+
<p>
268+
If you are using
269+
<a href="https://www.jetbrains.com/phpstorm/">JetBrains PhpStorm</a>
270+
with the
271+
<a href="https://laravel-idea.com">Laravel Idea</a> plugin installed,
272+
then autocomplete will be available to you:
273+
</p>
274+
<p>
275+
To avoid entering file names manually, you can use the <code>deploy_operation</code> helper function.
276+
All it does is to suggest IDE paths to operation files with recursive search.
277+
</p>
278+
279+
<code-block lang="php" src="with_operation_helper.php" include-lines="7-" />
280+
281+
<img src="operations_helper_function.png" alt="operation helper"/>
282+
</chapter>
265283
</chapter>
266284
</topic>

ide.json

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"methodNames": [
3131
"run"
3232
],
33+
"functionFqn": [
34+
"DragonCode\\LaravelDeployOperations\\operation"
35+
],
3336
"place": "parameter",
3437
"parameters": [
3538
1

src/helpers.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DragonCode\LaravelDeployOperations;
6+
7+
if (! function_exists('\DragonCode\LaravelDeployOperations\operation')) {
8+
function operation(string $filename): string
9+
{
10+
return $filename;
11+
}
12+
}

tests/Commands/OperationsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,9 @@ public function testViaMigrationMethod(): void
787787
])->assertSuccessful();
788788

789789
$this->assertDatabaseCount($table, 1);
790-
$this->assertDatabaseCount($this->table, 0);
790+
$this->assertDatabaseCount($this->table, 1);
791791
$this->assertDatabaseOperationDoesntLike($this->table, 'custom');
792-
$this->assertDatabaseOperationDoesntLike($this->table, 'invoke');
792+
$this->assertDatabaseOperationHas($this->table, 'invoke');
793793
$this->assertDatabaseOperationDoesntLike($this->table, 'up_down');
794794
$this->assertDatabaseOperationDoesntLike($table, 'custom', column: 'value');
795795
$this->assertDatabaseOperationHas($table, 'invoke', column: 'value');

tests/fixtures/migrations_with_operations/2025_03_31_213847_call_invokable.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use Illuminate\Database\Migrations\Migration;
66

7+
use function DragonCode\LaravelDeployOperations\operation;
8+
79
return new class extends Migration {
810
public function up(): void {}
911

10-
public function down(): void {}
11-
1212
public function withOperation(): string
1313
{
14-
return '2025_03_31_234251_invoke';
14+
return operation('2025_03_31_234251_invoke');
1515
}
1616
};

tests/fixtures/migrations_with_operations/2025_03_31_213921_call_up_down.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
use Illuminate\Database\Migrations\Migration;
66

7+
use function DragonCode\LaravelDeployOperations\operation;
8+
79
return new class extends Migration {
810
public function up(): void {}
911

1012
public function down(): void {}
1113

1214
public function withOperation(): string
1315
{
14-
return '2025_03_31_234312_up_down';
16+
return operation('2025_03_31_234312_up_down');
1517
}
1618
};

0 commit comments

Comments
 (0)