Skip to content

Commit

Permalink
refactor: test
Browse files Browse the repository at this point in the history
  • Loading branch information
yogyrton committed Dec 25, 2024
1 parent 84d566d commit 30b3d08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 6 additions & 4 deletions tests/EntityControlTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class EntityControlTraitTest extends HelpersTestCase
{
use SqlMockTrait;

protected string $mockedNow = '2020-01-01 00:00:00';

protected static array $selectResult;

protected static TestRepository $testRepositoryClass;
Expand Down Expand Up @@ -47,7 +49,7 @@ public function setUp(): void

self::$selectResult ??= $this->getJsonFixture('select_query_result.json');

Carbon::setTestNow('2020-01-01 00:00:00');
Carbon::setTestNow($this->mockedNow);
}

public function testOnlyTrashed()
Expand Down Expand Up @@ -204,7 +206,7 @@ public function testCreateOnlyFillable()

public function testInsert()
{
$this->mockInsertData(Carbon::now());
$this->mockInsertData();

$result = self::$testRepositoryClass->insert([
['name' => 'test_name_1'],
Expand All @@ -217,7 +219,7 @@ public function testInsert()

public function testInsertWithSettableProperties()
{
$this->mockInsertData(Carbon::now());
$this->mockInsertData();

$result = self::$testRepositoryClass
->withTrashed()
Expand Down Expand Up @@ -249,7 +251,7 @@ public function testInsertWithoutTimestamps()

public function testInsertWithDifferentTimestampNames()
{
$this->mockInsertDataWithDifferentTimestampNames(Carbon::now());
$this->mockInsertDataWithDifferentTimestampNames();

$result = self::$testRepositoryWithDifferentTimestampNames->insert([
['name' => 'test_name_1'],
Expand Down
16 changes: 8 additions & 8 deletions tests/support/Traits/SqlMockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ protected function mockCreate(array $selectResult, $notFillableValue): void
);
}

protected function mockInsertData(Carbon $now): void
protected function mockInsertData(): void
{
$query = 'insert into "test_models" ("created_at", "name", "updated_at") values (?, ?, ?), (?, ?, ?), (?, ?, ?)';

$values = [
$now, 'test_name_1', $now,
$now, 'test_name_2', $now,
$now, 'test_name_3', $now,
$this->mockedNow, 'test_name_1', $this->mockedNow,
$this->mockedNow, 'test_name_2', $this->mockedNow,
$this->mockedNow, 'test_name_3', $this->mockedNow,
];

$this->getPdo()->shouldInsert($query, $values);
Expand All @@ -179,14 +179,14 @@ protected function mockInsertDataWithoutTimestamps(): void
$this->getPdo()->shouldInsert($query, $values);
}

protected function mockInsertDataWithDifferentTimestampNames(Carbon $now): void
protected function mockInsertDataWithDifferentTimestampNames(): void
{
$query = 'insert into "test_models" ("creation_date", "name", "updated_date") values (?, ?, ?), (?, ?, ?), (?, ?, ?)';

$values = [
$now, 'test_name_1', $now,
$now, 'test_name_2', $now,
$now, 'test_name_3', $now,
$this->mockedNow, 'test_name_1', $this->mockedNow,
$this->mockedNow, 'test_name_2', $this->mockedNow,
$this->mockedNow, 'test_name_3', $this->mockedNow,
];

$this->getPdo()->shouldInsert($query, $values);
Expand Down

0 comments on commit 30b3d08

Please sign in to comment.