Skip to content

Commit

Permalink
chore: add test coverage for whereYear
Browse files Browse the repository at this point in the history
  • Loading branch information
patoui committed Jan 18, 2025
1 parent 38e4989 commit 40d242a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Below is a list of currently untested methods or functionality. This does not me
- `whereJsonLength`
- `whereBetween`
- `whereNotBetween`
- `whereDay`, `whereYear`, `whereTime`
- `whereDay`, `whereTime`
- `orWhereColumn`
- `whereExists`
- Subquery Where Clauses
Expand Down
17 changes: 17 additions & 0 deletions tests/Feature/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ public function test_where_month(): void
);
}

public function test_where_year(): void
{
// Arrange
Analytic::create(['ts' => strtotime('-2 years'), 'analytic_id' => mt_rand(1000, 9999), 'status' => mt_rand(200, 599)]);
Analytic::create(['ts' => time(), 'analytic_id' => mt_rand(1000, 9999), 'status' => mt_rand(200, 599)]);

// Act & Assert
self::assertSame(
1,
Analytic::whereYear('ts', date('Y'))->count()
);
self::assertSame(
1,
Analytic::whereYear('ts', new DateTimeImmutable())->count()
);
}

public function test_where_null(): void
{
// Arrange
Expand Down
29 changes: 29 additions & 0 deletions tests/Feature/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,35 @@ public function test_where_month(): void
);
}

public function test_where_year(): void
{
// Arrange
DB::connection('clickhouse')->insert(
'analytics',
['ts' => strtotime('-2 years'), 'analytic_id' => mt_rand(1000, 9999), 'status' => mt_rand(200, 599)]
);
DB::connection('clickhouse')->insert(
'analytics',
['ts' => time(), 'analytic_id' => mt_rand(1000, 9999), 'status' => mt_rand(200, 599)]
);

// Act & Assert
self::assertSame(
1,
DB::connection('clickhouse')
->table('analytics')
->whereYear('ts', date('Y'))
->count()
);
self::assertSame(
1,
DB::connection('clickhouse')
->table('analytics')
->whereYear('ts', new DateTimeImmutable())
->count()
);
}

public function test_select(): void
{
// Arrange
Expand Down

0 comments on commit 40d242a

Please sign in to comment.