diff --git a/README.md b/README.md index 49c1418..271ef3a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tests/Feature/ModelTest.php b/tests/Feature/ModelTest.php index 42302bb..3184096 100644 --- a/tests/Feature/ModelTest.php +++ b/tests/Feature/ModelTest.php @@ -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 diff --git a/tests/Feature/QueryTest.php b/tests/Feature/QueryTest.php index 5850647..64d953c 100644 --- a/tests/Feature/QueryTest.php +++ b/tests/Feature/QueryTest.php @@ -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