Browse Source

Tests for builder macros

- where like
- where ilike
Mr. CaT 1 year ago
parent
commit
211e7e16a2
1 changed files with 36 additions and 0 deletions
  1. 36 0
      tests/Unit/BuilderMacrosTest.php

+ 36 - 0
tests/Unit/BuilderMacrosTest.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace Tests\Unit;
+
+use App\Models\User;
+use Illuminate\Foundation\Testing\RefreshDatabase;
+use Tests\TestCase;
+
+class BuilderMacrosTest extends TestCase
+{
+    use RefreshDatabase;
+    /**
+     * A basic unit test example.
+     */
+    public function test_where_like_macro(): void
+    {
+        for ($i = 1; $i < 5; $i++) {
+            User::factory()->create(['email' => 'tester@test.com' . $i]);
+        }
+
+        $doUsersExist = User::whereLike('email', 'test%')->exists();
+
+        $this->assertTrue($doUsersExist);
+    }
+
+    public function test_where_ilike_macro(): void
+    {
+        for ($i = 1; $i < 5; $i++) {
+            User::factory()->create(['name' => 'TEsT' . $i]);
+        }
+
+        $doUsersExist = User::whereILike('name', '%es%')->exists();
+
+        $this->assertTrue($doUsersExist);
+    }
+}