Skip to content

Commit

Permalink
Removed old overrides (QB improvements renders these overrides unnece…
Browse files Browse the repository at this point in the history
…ssary)
  • Loading branch information
LaravelFreelancerNL committed Aug 25, 2024
1 parent cb978bf commit 5789131
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 114 deletions.
114 changes: 0 additions & 114 deletions src/Testing/Concerns/InteractsWithDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,122 +5,9 @@
namespace LaravelFreelancerNL\Aranguent\Testing\Concerns;

use Illuminate\Support\Facades\DB;
use Illuminate\Testing\Constraints\HasInDatabase;
use Illuminate\Testing\Constraints\NotSoftDeletedInDatabase;
use Illuminate\Testing\Constraints\SoftDeletedInDatabase;
use PHPUnit\Framework\Constraint\LogicalNot as ReverseConstraint;

trait InteractsWithDatabase
{
/**
* Assert that a given where condition exists in the database.
*
* @param \Illuminate\Database\Eloquent\Model|string $table
* @param array<mixed> $data
* @param string|null $connection
* @return $this
*/
protected function assertDatabaseHas($table, array $data = [], $connection = null)
{
$this->assertThat(
$this->getTable($table),
new HasInDatabase($this->getConnection($connection), associativeFlatten($data)),
);

return $this;
}

/**
* Assert that a given where condition does not exist in the database.
*
* @param \Illuminate\Database\Eloquent\Model|string $table
* @param array<mixed> $data
* @param string|null $connection
* @return $this
*/
protected function assertDatabaseMissing($table, array $data = [], $connection = null)
{
$constraint = new ReverseConstraint(
new HasInDatabase($this->getConnection($connection), associativeFlatten($data)),
);

$this->assertThat($this->getTable($table), $constraint);

return $this;
}

/**
* Assert the given record has been "soft deleted".
*
* @param \Illuminate\Database\Eloquent\Model|string $table
* @param array<mixed> $data
* @param string|null $connection
* @param string|null $deletedAtColumn
* @return $this
*/
protected function assertSoftDeleted(
$table,
array $data = [],
$connection = null,
$deletedAtColumn = 'deleted_at',
) {
if ($this->isSoftDeletableModel($table) && !is_string($table)) {
return $this->assertSoftDeleted(
$table->getTable(),
[$table->getKeyName() => $table->getKey()],
$table->getConnectionName(), /** @phpstan-ignore-next-line */
$table->getDeletedAtColumn(),
);
}

$this->assertThat(
$this->getTable($table),
new SoftDeletedInDatabase(
$this->getConnection($connection),
associativeFlatten($data),
(string) $deletedAtColumn,
),
);

return $this;
}

/**
* Assert the given record has not been "soft deleted".
*
* @param \Illuminate\Database\Eloquent\Model|string $table
* @param array<mixed> $data
* @param string|null $connection
* @param string|null $deletedAtColumn
* @return $this
*/
protected function assertNotSoftDeleted(
$table,
array $data = [],
$connection = null,
$deletedAtColumn = 'deleted_at',
) {
if ($this->isSoftDeletableModel($table) && !is_string($table)) {
return $this->assertNotSoftDeleted(
$table->getTable(),
[$table->getKeyName() => $table->getKey()],
$table->getConnectionName(), /** @phpstan-ignore-next-line */
$table->getDeletedAtColumn(),
);
}

$this->assertThat(
$this->getTable($table),
new NotSoftDeletedInDatabase(
$this->getConnection($connection),
associativeFlatten($data),
(string) $deletedAtColumn,
),
);

return $this;
}

/**
* Cast a JSON string to a database compatible type.
* Supported for backwards compatibility in existing projects.
Expand All @@ -133,5 +20,4 @@ public function castAsJson($value)
{
return DB::raw($value);
}

}
1 change: 1 addition & 0 deletions tests/Testing/InteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

test('assert model exists', function () {
$ned = Character::find('NedStark');

$this->assertModelExists($ned);
});

Expand Down

0 comments on commit 5789131

Please sign in to comment.