Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use exists validation without manually specifying connection name & fix multiple model support #96

Merged
merged 6 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Sushi.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected static function setSqliteConnection($database)

static::$sushiConnection = app(ConnectionFactory::class)->make($config);

app('config')->set('database.connections.sushi', $config);
app('config')->set('database.connections.'.static::class, $config);
}

public function migrate()
Expand Down Expand Up @@ -212,4 +212,9 @@ public function usesTimestamps()
public function getSushiInsertChunkSize() {
return $this->sushiInsertChunkSize ?? 100;
}

public function getConnectionName()
{
return static::class;
}
}
19 changes: 10 additions & 9 deletions tests/SushiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,20 @@ function it_returns_an_empty_collection()
/** @test */
function can_use_exists_validation_rule()
{
ModelWithNonStandardKeys::boot();
ModelWithNonStandardKeys::all();
Foo::all();

$this->assertTrue(Validator::make(['bob' => 'lob'], ['bob' => 'exists:sushi.model_with_non_standard_keys'])->passes());
$this->assertTrue(Validator::make(['bob' => 'lob'], ['bob' => 'exists:sushi.model_with_non_standard_keys'])->passes());
$this->assertTrue(Validator::make(['bob' => 'lob'], ['bob' => 'exists:'.ModelWithNonStandardKeys::class.'.model_with_non_standard_keys'])->passes());
$this->assertTrue(Validator::make(['foo' => 'bar'], ['foo' => 'exists:'.Foo::class.'.foos'])->passes());
(int) explode('.', app()->version())[0] >= 6
? $this->assertTrue(Validator::make(['foo' => 5], ['foo' => 'exists:sushi.Tests\ModelWithNonStandardKeys,id'])->passes())
: $this->assertTrue(Validator::make(['foo' => 5], ['foo' => 'exists:sushi.model_with_non_standard_keys,id'])->passes());
? $this->assertTrue(Validator::make(['foo' => 5], ['foo' => 'exists:'.ModelWithNonStandardKeys::class.',id'])->passes())
: $this->assertTrue(Validator::make(['foo' => 5], ['foo' => 'exists:'.ModelWithNonStandardKeys::class.'.model_with_non_standard_keys,id'])->passes());

$this->assertFalse(Validator::make(['id' => 4], ['id' => 'exists:sushi.model_with_non_standard_keys'])->passes());
$this->assertFalse(Validator::make(['id' => 6], ['id' => 'exists:sushi.model_with_non_standard_keys,bob'])->passes());
$this->assertFalse(Validator::make(['id' => 4], ['id' => 'exists:'.ModelWithNonStandardKeys::class.'.model_with_non_standard_keys'])->passes());
$this->assertFalse(Validator::make(['foo' => 'bob'], ['foo' => 'exists:'.Foo::class.'.foos'])->passes());
(int) explode('.', app()->version())[0] >= 6
? $this->assertFalse(Validator::make(['bob' => 'ble'], ['bob' => 'exists:sushi.Tests\ModelWithNonStandardKeys'])->passes())
: $this->assertFalse(Validator::make(['bob' => 'ble'], ['bob' => 'exists:sushi.model_with_non_standard_keys'])->passes());
? $this->assertFalse(Validator::make(['bob' => 'ble'], ['bob' => 'exists:'.ModelWithNonStandardKeys::class])->passes())
: $this->assertFalse(Validator::make(['bob' => 'ble'], ['bob' => 'exists:'.ModelWithNonStandardKeys::class.'.model_with_non_standard_keys'])->passes());
}
}

Expand Down