Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Dec 5, 2023
1 parent 2fc7f7f commit 7a858ba
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 63 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"extra": {
"laravel": {
"providers": [
"Staudenmeir\\EloquentHasManyDeep\\Providers\\EloquentHasManyDeepServiceProvider"
"Staudenmeir\\EloquentHasManyDeep\\EloquentHasManyDeepServiceProvider"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Relations/Traits/JoinsThroughParents.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function (JoinClause $join) use ($joins) {
}

if ($this->throughParentInstanceSoftDeletes($throughParent)) {
$column= $throughParent->getQualifiedDeletedAtColumn();
$column = $throughParent->getQualifiedDeletedAtColumn();

$query->withGlobalScope(__CLASS__ . ":$column", function (Builder $query) use ($column) {
$query->whereNull($column);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Staudenmeir\EloquentHasManyDeep\Providers;
namespace Staudenmeir\EloquentHasManyDeep;

use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Illuminate\Contracts\Support\DeferrableProvider;
Expand Down Expand Up @@ -45,14 +45,14 @@ protected function registerIdeHelperHook(): void
protected function publishConfig(): void
{
$this->publishes([
__DIR__ . '/../../config/eloquent-has-many-deep.php' => config_path('eloquent-has-many-deep.php'),
__DIR__ . '/../config/eloquent-has-many-deep.php' => config_path('eloquent-has-many-deep.php'),
], 'eloquent-has-many-deep');
}

protected function registerConfig(): void
{
$this->mergeConfigFrom(
__DIR__ . '/../../config/eloquent-has-many-deep.php',
__DIR__ . '/../config/eloquent-has-many-deep.php',
'eloquent-has-many-deep',
);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Concatenation/ConcatenationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests\Concatenation;

use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Support\Facades\Schema;
use Tests\Models\Country;
use Tests\Models\Employee;
use Tests\Models\Post;
Expand Down Expand Up @@ -71,7 +71,7 @@ public function testWithAlias()

public function testWithCustomRelatedTable()
{
DB::schema()->rename('comments', 'my_comments');
Schema::rename('comments', 'my_comments');

$comments = Country::find(1)->commentsFromRelationsWithCustomRelatedTable;

Expand All @@ -80,7 +80,7 @@ public function testWithCustomRelatedTable()

public function testWithCustomThroughTable()
{
DB::schema()->rename('users', 'my_users');
Schema::rename('users', 'my_users');

$comments = Country::find(1)->commentsFromRelationsWithCustomThroughTable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\Concatenation\EloquentJsonRelations\BelongsToJson;

use Illuminate\Database\Capsule\Manager as DB;
use Tests\Concatenation\EloquentJsonRelations\Models\User;
use Tests\Concatenation\EloquentJsonRelations\TestCase;

Expand All @@ -12,7 +11,7 @@ protected function setUp(): void
{
parent::setUp();

if (DB::connection()->getDriverName() === 'sqlite') {
if ($this->database === 'sqlite') {
$this->markTestSkipped();
}
}
Expand Down
43 changes: 22 additions & 21 deletions tests/Concatenation/LaravelHasManyMerged/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

namespace Tests\Concatenation\LaravelHasManyMerged;

use Carbon\Carbon;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use PHPUnit\Framework\TestCase as Base;
use Tests\Concatenation\LaravelAdjacencyList\Models\Post;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Orchestra\Testbench\TestCase as Base;
use Tests\Concatenation\LaravelAdjacencyList\Models\User;
use Tests\Concatenation\LaravelHasManyMerged\Models\Attachment;
use Tests\Concatenation\LaravelHasManyMerged\Models\Country;
Expand All @@ -19,20 +18,13 @@ abstract class TestCase extends Base

protected function setUp(): void
{
parent::setUp();

$this->database = getenv('DATABASE') ?: 'sqlite';

$config = require __DIR__.'/../../config/database.php';

$db = new DB();
$db->addConnection($config[$this->database]);
$db->setAsGlobal();
$db->bootEloquent();
parent::setUp();

$this->migrate();
$this->migrateDatabase();

$this->seed();
$this->seedDatabase();
}

protected function tearDown(): void
Expand All @@ -42,19 +34,19 @@ protected function tearDown(): void
parent::tearDown();
}

protected function migrate(): void
protected function migrateDatabase(): void
{
DB::schema()->dropAllTables();
Schema::dropAllTables();

DB::schema()->create(
Schema::create(
'countries',
function (Blueprint $table) {
$table->id();
$table->timestamps();
}
);

DB::schema()->create(
Schema::create(
'users',
function (Blueprint $table) {
$table->id();
Expand All @@ -63,7 +55,7 @@ function (Blueprint $table) {
}
);

DB::schema()->create(
Schema::create(
'messages',
function (Blueprint $table) {
$table->id();
Expand All @@ -73,7 +65,7 @@ function (Blueprint $table) {
}
);

DB::schema()->create(
Schema::create(
'attachments',
function (Blueprint $table) {
$table->id();
Expand All @@ -83,7 +75,7 @@ function (Blueprint $table) {
);
}

protected function seed(): void
protected function seedDatabase(): void
{
Model::unguard();

Expand Down Expand Up @@ -111,4 +103,13 @@ protected function seed(): void

Model::reguard();
}

protected function getEnvironmentSetUp($app)
{
$config = require __DIR__.'/../../config/database.php';

$app['config']->set('database.default', 'testing');

$app['config']->set('database.connections.testing', $config[$this->database]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace Tests\Providers;
namespace Tests;

use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
use Orchestra\Testbench\TestCase;
use Staudenmeir\EloquentHasManyDeep\IdeHelper\DeepRelationsHook;
use Staudenmeir\EloquentHasManyDeep\Providers\EloquentHasManyDeepServiceProvider;
use Staudenmeir\EloquentHasManyDeep\EloquentHasManyDeepServiceProvider;

class EloquentHasManyDeepServiceProviderTest extends TestCase
{
Expand Down
1 change: 1 addition & 0 deletions tests/IdeHelper/DeepRelationsHookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class DeepRelationsHookTest extends TestCase
{
use MockeryPHPUnitIntegration;

protected function setUp(): void
{
parent::setUp();
Expand Down
4 changes: 2 additions & 2 deletions tests/ReversingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Tests;

use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Support\Facades\Schema;
use Tests\Models\Comment;
use Tests\Models\Permission;

Expand Down Expand Up @@ -38,7 +38,7 @@ public function testPivotAlias()

public function testCustomThroughTable()
{
DB::schema()->rename('users', 'my_users');
Schema::rename('users', 'my_users');

$country = Comment::find(31)->countryWithCustomThroughTable;

Expand Down
Loading

0 comments on commit 7a858ba

Please sign in to comment.