Skip to content

Commit 2e6c8e8

Browse files
authored
Merge pull request #11 from lukeraymonddowning/allow-spread-operators
Allows parameters for setup methods to be passed in as a spread array
2 parents 8d86978 + e97ccbe commit 2e6c8e8

File tree

8 files changed

+147
-12
lines changed

8 files changed

+147
-12
lines changed

src/Package.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function hasConfigFile(string $configFileName = null): self
3838
return $this;
3939
}
4040

41+
public function shortName(): string
42+
{
43+
return Str::after($this->name, 'laravel-');
44+
}
45+
4146
public function hasViews(): self
4247
{
4348
$this->hasViews = true;
@@ -66,9 +71,12 @@ public function hasMigration(string $migrationFileName): self
6671
return $this;
6772
}
6873

69-
public function hasMigrations(array $migrationFileNames): self
74+
public function hasMigrations(...$migrationFileNames): self
7075
{
71-
$this->migrationFileNames = array_merge($this->migrationFileNames, $migrationFileNames);
76+
$this->migrationFileNames = array_merge(
77+
$this->migrationFileNames,
78+
collect($migrationFileNames)->flatten()->toArray()
79+
);
7280

7381
return $this;
7482
}
@@ -80,9 +88,9 @@ public function hasCommand(string $commandClassName): self
8088
return $this;
8189
}
8290

83-
public function hasCommands(array $commandClassNames): self
91+
public function hasCommands(...$commandClassNames): self
8492
{
85-
$this->commands = array_merge($this->commands, $commandClassNames);
93+
$this->commands = array_merge($this->commands, collect($commandClassNames)->flatten()->toArray());
8694

8795
return $this;
8896
}
@@ -94,9 +102,9 @@ public function hasRoute(string $routeFileName): self
94102
return $this;
95103
}
96104

97-
public function hasRoutes(array $routeFileNames): self
105+
public function hasRoutes(...$routeFileNames): self
98106
{
99-
$this->routeFileNames = array_merge($this->routeFileNames, $routeFileNames);
107+
$this->routeFileNames = array_merge($this->routeFileNames, collect($routeFileNames)->flatten()->toArray());
100108

101109
return $this;
102110
}
@@ -116,9 +124,4 @@ public function setBasePath(string $path): self
116124

117125
return $this;
118126
}
119-
120-
public function shortName(): string
121-
{
122-
return Str::after($this->name, 'laravel-');
123-
}
124127
}

tests/PackageServiceProviderTests/PackageCommandsTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace Spatie\LaravelPackageTools\Tests\PackageServiceProviderTests;
44

55
use Spatie\LaravelPackageTools\Package;
6+
use Spatie\LaravelPackageTools\Tests\TestClasses\FourthTestCommand;
67
use Spatie\LaravelPackageTools\Tests\TestClasses\OtherTestCommand;
78
use Spatie\LaravelPackageTools\Tests\TestClasses\TestCommand;
9+
use Spatie\LaravelPackageTools\Tests\TestClasses\ThirdTestCommand;
810

911
class PackageCommandsTest extends PackageServiceProviderTestCase
1012
{
@@ -13,7 +15,8 @@ public function configurePackage(Package $package)
1315
$package
1416
->name('laravel-package-tools')
1517
->hasCommand(TestCommand::class)
16-
->hasCommands([OtherTestCommand::class]);
18+
->hasCommands([OtherTestCommand::class])
19+
->hasCommands(ThirdTestCommand::class, FourthTestCommand::class);
1720
}
1821

1922
/** @test */
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Spatie\LaravelPackageTools\Tests\PackageServiceProviderTests;
4+
5+
use Spatie\LaravelPackageTools\Package;
6+
use Spatie\TestTime\TestTime;
7+
8+
class PackageMigrationsTest extends PackageServiceProviderTestCase
9+
{
10+
public function configurePackage(Package $package)
11+
{
12+
TestTime::freeze('Y-m-d H:i:s', '2020-01-01 00:00:00');
13+
14+
$package
15+
->name('laravel-package-tools')
16+
->hasMigrations(['create_laravel_package_tools_table'])
17+
->hasMigrations('create_other_laravel_package_tools_table', 'create_third_laravel_package_tools_table');
18+
}
19+
20+
/** @test */
21+
public function it_can_publish_the_migration()
22+
{
23+
$this
24+
->artisan('vendor:publish --tag=laravel-package-tools-migrations')
25+
->assertExitCode(0);
26+
27+
$this->assertFileExists(database_path('migrations/2020_01_01_000000_create_laravel_package_tools_table.php'));
28+
$this->assertFileExists(database_path('migrations/2020_01_01_000000_create_other_laravel_package_tools_table.php'));
29+
$this->assertFileExists(database_path('migrations/2020_01_01_000000_create_third_laravel_package_tools_table.php'));
30+
}
31+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Spatie\LaravelPackageTools\Tests\PackageServiceProviderTests;
4+
5+
use Spatie\LaravelPackageTools\Package;
6+
use Spatie\TestTime\TestTime;
7+
8+
class PackageRoutesTest extends PackageServiceProviderTestCase
9+
{
10+
public function configurePackage(Package $package)
11+
{
12+
TestTime::freeze('Y-m-d H:i:s', '2020-01-01 00:00:00');
13+
14+
$package
15+
->name('laravel-package-tools')
16+
->hasRoutes('web', 'other');
17+
}
18+
19+
/** @test */
20+
public function it_can_load_the_route()
21+
{
22+
$response = $this->get('my-route');
23+
24+
$response->assertSeeText('my response');
25+
}
26+
27+
/** @test */
28+
public function it_can_load_multiple_route()
29+
{
30+
$adminResponse = $this->get('other-route');
31+
32+
$adminResponse->assertSeeText('other response');
33+
}
34+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Spatie\LaravelPackageTools\Tests\TestClasses;
4+
5+
use Illuminate\Console\Command;
6+
7+
class FourthTestCommand extends Command
8+
{
9+
public $name = 'fourth-test-command';
10+
11+
public function handle()
12+
{
13+
$this->info('output of test command');
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Spatie\LaravelPackageTools\Tests\TestClasses;
4+
5+
use Illuminate\Console\Command;
6+
7+
class ThirdTestCommand extends Command
8+
{
9+
public $name = 'third-test-command';
10+
11+
public function handle()
12+
{
13+
$this->info('output of test command');
14+
}
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateLaravelPackageToolsTable extends Migration
8+
{
9+
public function up()
10+
{
11+
Schema::create('other-laravel-package-tools_table', function (Blueprint $table) {
12+
$table->bigIncrements('id');
13+
14+
$table->timestamps();
15+
});
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateLaravelPackageToolsTable extends Migration
8+
{
9+
public function up()
10+
{
11+
Schema::create('third-laravel-package-tools_table', function (Blueprint $table) {
12+
$table->bigIncrements('id');
13+
14+
$table->timestamps();
15+
});
16+
}
17+
}

0 commit comments

Comments
 (0)