Skip to content

Commit 044a91a

Browse files
authored
Merge pull request #17 from FrittenKeeZ/migrations-cleanup
Migrations cleanup
2 parents 0a594e4 + 1e5f13f commit 044a91a

22 files changed

+72
-569
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Publish config using Artisan command:
3939
```bash
4040
php artisan vendor:publish --tag=config --provider="FrittenKeeZ\Vouchers\VouchersServiceProvider"
4141
```
42+
Publish migrations using Artisan command:
43+
```bash
44+
php artisan vendor:publish --tag=migrations --provider="FrittenKeeZ\Vouchers\VouchersServiceProvider"
45+
```
4246
Don't forget to run migrations:
4347
```bash
4448
php artisan migrate

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
],
4747
"psr-4": {
4848
"FrittenKeeZ\\Vouchers\\Tests\\": "tests",
49-
"FrittenKeeZ\\Vouchers\\Tests\\Database\\Factories\\": "tests/database/factories"
49+
"Database\\Factories\\FrittenKeeZ\\Vouchers\\Tests\\Models\\": "tests/database/factories"
5050
}
5151
},
5252
"scripts": {

migrations/2018_06_12_000000_create_voucher_tables.php renamed to publishes/migrations/2018_06_12_000000_create_voucher_tables.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Illuminate\Database\Schema\Blueprint;
88
use Illuminate\Support\Facades\Schema;
99

10-
class CreateVoucherTables extends Migration
10+
return new class extends Migration
1111
{
1212
/**
1313
* Run the migrations.
@@ -68,4 +68,4 @@ public function down(): void
6868
Schema::dropIfExists(Config::table('redeemers'));
6969
Schema::dropIfExists(Config::table('vouchers'));
7070
}
71-
}
71+
};

publishes/migrations/2021_02_02_000000_add_owner_to_vouchers_table.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

publishes/migrations/2021_12_10_000000_add_primary_key_to_entities_table.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Console/Commands/MigrateCommand.php

Lines changed: 0 additions & 180 deletions
This file was deleted.

src/VouchersServiceProvider.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace FrittenKeeZ\Vouchers;
66

7-
use FrittenKeeZ\Vouchers\Console\Commands\MigrateCommand;
87
use Illuminate\Support\ServiceProvider;
98

109
class VouchersServiceProvider extends ServiceProvider
@@ -22,13 +21,10 @@ class VouchersServiceProvider extends ServiceProvider
2221
public function boot(): void
2322
{
2423
$this->publishes([$this->getPublishConfigPath() => config_path('vouchers.php')], 'config');
25-
$this->publishes([$this->getPublishMigrationsPath() => database_path('migrations')], 'migrations');
2624

27-
$this->loadMigrationsFrom(__DIR__ . '/../migrations');
28-
29-
if ($this->app->runningInConsole()) {
30-
$this->commands([MigrateCommand::class]);
31-
}
25+
with(method_exists($this, 'publishesMigrations') ? 'publishesMigrations' : 'publishes', function ($method) {
26+
$this->{$method}([$this->getPublishMigrationsPath() => database_path('migrations')], 'migrations');
27+
});
3228
}
3329

3430
/**
@@ -38,9 +34,7 @@ public function register(): void
3834
{
3935
$this->mergeConfigFrom($this->getPublishConfigPath(), 'vouchers');
4036

41-
$this->app->bind('vouchers', function () {
42-
return new Vouchers();
43-
});
37+
$this->app->bind('vouchers', fn () => new Vouchers());
4438
}
4539

4640
/**

tests/ConfigTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ public function testDynamicallyOverriddenOptions(): void
146146
$this->assertSame($options['separator'], $config->getSeparator());
147147

148148
// Test 'without' calls.
149-
$config
150-
->withoutPrefix()
151-
->withoutSuffix()
152-
->withoutSeparator()
153-
;
149+
$config->withoutPrefix()->withoutSuffix()->withoutSeparator();
154150
$this->assertSame('', $config->getPrefix());
155151
$this->assertSame('', $config->getSuffix());
156152
$this->assertSame('', $config->getSeparator());
@@ -212,11 +208,11 @@ public function testAdditionalOptions(): void
212208
);
213209

214210
// Test owner.
215-
$owner = $this->factory(User::class)->make();
211+
$owner = User::factory()->make();
216212
$this->assertSame($owner, $config->withOwner($owner)->getOwner());
217213

218214
// Test entities.
219-
$entities = $this->factory(Color::class, 3)->make()->all();
215+
$entities = Color::factory()->count(3)->make()->all();
220216
$this->assertSame($entities, $config->withEntities(...$entities)->getEntities());
221217
}
222218

tests/HasVouchersTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HasVouchersTest extends TestCase
1818
*/
1919
public function testCreateVoucher(): void
2020
{
21-
$user = $this->factory(User::class)->create();
21+
$user = User::factory()->create();
2222
$voucher = $user->createVoucher();
2323

2424
// Check user voucher relation.
@@ -31,8 +31,8 @@ public function testCreateVoucher(): void
3131
*/
3232
public function testCreateVoucherWithCallback(): void
3333
{
34-
$user = $this->factory(User::class)->create();
35-
$color = $this->factory(Color::class)->create();
34+
$user = User::factory()->create();
35+
$color = Color::factory()->create();
3636
$voucher = $user->createVoucher(function (Vouchers $vouchers) use ($color) {
3737
$vouchers->withEntities($color);
3838
});
@@ -48,8 +48,8 @@ public function testCreateVoucherWithCallback(): void
4848
*/
4949
public function testCreateVoucherWithAssociated(): void
5050
{
51-
$user = $this->factory(User::class)->create();
52-
$other = $this->factory(User::class)->create();
51+
$user = User::factory()->create();
52+
$other = User::factory()->create();
5353
$voucher = $user->createVoucher(function (Vouchers $vouchers) use ($other) {
5454
$vouchers->withEntities($other);
5555
});
@@ -68,7 +68,7 @@ public function testCreateVoucherWithAssociated(): void
6868
*/
6969
public function testCreateVouchers(): void
7070
{
71-
$user = $this->factory(User::class)->create();
71+
$user = User::factory()->create();
7272
$vouchers = $user->createVouchers(3);
7373

7474
foreach ($vouchers as $index => $voucher) {
@@ -83,8 +83,8 @@ public function testCreateVouchers(): void
8383
*/
8484
public function testCreateVouchersWithCallback(): void
8585
{
86-
$user = $this->factory(User::class)->create();
87-
$color = $this->factory(Color::class)->create();
86+
$user = User::factory()->create();
87+
$color = Color::factory()->create();
8888
$vouchers = $user->createVouchers(3, function (Vouchers $vouchers) use ($color) {
8989
$vouchers->withEntities($color);
9090
});

0 commit comments

Comments
 (0)