Skip to content

Commit

Permalink
Merge pull request #17 from FrittenKeeZ/migrations-cleanup
Browse files Browse the repository at this point in the history
Migrations cleanup
  • Loading branch information
FrittenKeeZ authored Jun 13, 2024
2 parents 0a594e4 + 1e5f13f commit 044a91a
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 569 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Publish config using Artisan command:
```bash
php artisan vendor:publish --tag=config --provider="FrittenKeeZ\Vouchers\VouchersServiceProvider"
```
Publish migrations using Artisan command:
```bash
php artisan vendor:publish --tag=migrations --provider="FrittenKeeZ\Vouchers\VouchersServiceProvider"
```
Don't forget to run migrations:
```bash
php artisan migrate
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"psr-4": {
"FrittenKeeZ\\Vouchers\\Tests\\": "tests",
"FrittenKeeZ\\Vouchers\\Tests\\Database\\Factories\\": "tests/database/factories"
"Database\\Factories\\FrittenKeeZ\\Vouchers\\Tests\\Models\\": "tests/database/factories"
}
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateVoucherTables extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down Expand Up @@ -68,4 +68,4 @@ public function down(): void
Schema::dropIfExists(Config::table('redeemers'));
Schema::dropIfExists(Config::table('vouchers'));
}
}
};

This file was deleted.

This file was deleted.

180 changes: 0 additions & 180 deletions src/Console/Commands/MigrateCommand.php

This file was deleted.

14 changes: 4 additions & 10 deletions src/VouchersServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace FrittenKeeZ\Vouchers;

use FrittenKeeZ\Vouchers\Console\Commands\MigrateCommand;
use Illuminate\Support\ServiceProvider;

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

$this->loadMigrationsFrom(__DIR__ . '/../migrations');

if ($this->app->runningInConsole()) {
$this->commands([MigrateCommand::class]);
}
with(method_exists($this, 'publishesMigrations') ? 'publishesMigrations' : 'publishes', function ($method) {
$this->{$method}([$this->getPublishMigrationsPath() => database_path('migrations')], 'migrations');
});
}

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

$this->app->bind('vouchers', function () {
return new Vouchers();
});
$this->app->bind('vouchers', fn () => new Vouchers());
}

/**
Expand Down
10 changes: 3 additions & 7 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,7 @@ public function testDynamicallyOverriddenOptions(): void
$this->assertSame($options['separator'], $config->getSeparator());

// Test 'without' calls.
$config
->withoutPrefix()
->withoutSuffix()
->withoutSeparator()
;
$config->withoutPrefix()->withoutSuffix()->withoutSeparator();
$this->assertSame('', $config->getPrefix());
$this->assertSame('', $config->getSuffix());
$this->assertSame('', $config->getSeparator());
Expand Down Expand Up @@ -212,11 +208,11 @@ public function testAdditionalOptions(): void
);

// Test owner.
$owner = $this->factory(User::class)->make();
$owner = User::factory()->make();
$this->assertSame($owner, $config->withOwner($owner)->getOwner());

// Test entities.
$entities = $this->factory(Color::class, 3)->make()->all();
$entities = Color::factory()->count(3)->make()->all();
$this->assertSame($entities, $config->withEntities(...$entities)->getEntities());
}

Expand Down
16 changes: 8 additions & 8 deletions tests/HasVouchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HasVouchersTest extends TestCase
*/
public function testCreateVoucher(): void
{
$user = $this->factory(User::class)->create();
$user = User::factory()->create();
$voucher = $user->createVoucher();

// Check user voucher relation.
Expand All @@ -31,8 +31,8 @@ public function testCreateVoucher(): void
*/
public function testCreateVoucherWithCallback(): void
{
$user = $this->factory(User::class)->create();
$color = $this->factory(Color::class)->create();
$user = User::factory()->create();
$color = Color::factory()->create();
$voucher = $user->createVoucher(function (Vouchers $vouchers) use ($color) {
$vouchers->withEntities($color);
});
Expand All @@ -48,8 +48,8 @@ public function testCreateVoucherWithCallback(): void
*/
public function testCreateVoucherWithAssociated(): void
{
$user = $this->factory(User::class)->create();
$other = $this->factory(User::class)->create();
$user = User::factory()->create();
$other = User::factory()->create();
$voucher = $user->createVoucher(function (Vouchers $vouchers) use ($other) {
$vouchers->withEntities($other);
});
Expand All @@ -68,7 +68,7 @@ public function testCreateVoucherWithAssociated(): void
*/
public function testCreateVouchers(): void
{
$user = $this->factory(User::class)->create();
$user = User::factory()->create();
$vouchers = $user->createVouchers(3);

foreach ($vouchers as $index => $voucher) {
Expand All @@ -83,8 +83,8 @@ public function testCreateVouchers(): void
*/
public function testCreateVouchersWithCallback(): void
{
$user = $this->factory(User::class)->create();
$color = $this->factory(Color::class)->create();
$user = User::factory()->create();
$color = Color::factory()->create();
$vouchers = $user->createVouchers(3, function (Vouchers $vouchers) use ($color) {
$vouchers->withEntities($color);
});
Expand Down
Loading

0 comments on commit 044a91a

Please sign in to comment.