Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
],
"require": {
"php": "^8.0",
"laravel/framework": "^11.0|^10.0|^9.0|^8.0|^12.0"
"laravel/framework": "^11.0|^12.0|^13.0"
},
"autoload-dev": {
"psr-4": {
"Refinephp\\LaravelRefine\\Tests\\": "tests"
}
},
"require-dev": {
"orchestra/testbench": "^9.0|^8.0|^10.0",
"phpunit/phpunit": "^10.0|^11.5.3"
"orchestra/testbench": "^8.0|^9.0|^10.0|^11.0",
"phpunit/phpunit": "^10.0|^11.5.3|^12.0"
},
"extra": {
"laravel": {
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/FilterableByMultipleFieldInRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Refinephp\LaravelRefine\Tests\Feature;

use PHPUnit\Framework\Attributes\Test;
use Refinephp\LaravelRefine\Tests\App\Models\Author;
use Refinephp\LaravelRefine\Tests\TestCase;

Expand Down Expand Up @@ -67,8 +68,7 @@ public function setUp(): void
'description' => 'The Silmarillion is a collection of mythopoeic works by English writer J. R. R. Tolkien.',
]);
}

/** @test */
#[Test]
public function it_can_filter_by_multiple_fields_in_relation(): void
{
$originalSilentMode = $this->app['config']->get('laravel-refine.silent');
Expand Down
103 changes: 35 additions & 68 deletions tests/Feature/FilterableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Refinephp\LaravelRefine\Tests\App\Models\Product;
use Refinephp\LaravelRefine\Tests\TestCase;
use Illuminate\Support\Facades\Route;
use PHPUnit\Framework\Attributes\Test;

use function PHPUnit\Framework\assertEquals;

Expand All @@ -25,35 +26,31 @@ public function setUp(): void
'title' => 'laravel refine is the best',
]);
}

/** @test */
#[Test]
public function it_can_process_a_basic_request_without_any_filter(): void
{
$response = $this->getJson('/posts');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_process_a_request_without_any_matches(): void
{
$response = $this->getJson('/posts?filters[title][$eq]=no matches');

$response->assertOk();
$response->assertJsonCount(0);
}

/** @test */
#[Test]
public function it_can_filter_with_a_basic_eq_operator(): void
{
$response = $this->getJson('/posts?filters[title][$eq]=laravel refine is the best');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_process_with_grouped_filters()
{
$post = Post::create(['title' => 'title'])
Expand All @@ -65,8 +62,7 @@ public function it_can_process_with_grouped_filters()

assertEquals('title', $response->json()[0]['title']);
}

/** @test */
#[Test]
public function it_can_filter_by_decimal_values_with_results()
{
$product = Product::factory()->create([
Expand All @@ -79,8 +75,7 @@ public function it_can_filter_by_decimal_values_with_results()

assertEquals($product->id, $response->json()[0]['id']);
}

/** @test */
#[Test]
public function it_can_filter_by_decimal_values_without_matches()
{
$product = Product::factory()->create([
Expand All @@ -91,8 +86,7 @@ public function it_can_filter_by_decimal_values_without_matches()
->assertOk()
->assertJsonCount(0);
}

/** @test */
#[Test]
public function it_can_filter_by_float_values_with_results()
{
$product = Product::factory()->create([
Expand All @@ -105,8 +99,7 @@ public function it_can_filter_by_float_values_with_results()

assertEquals($product->id, $response->json()[0]['id']);
}

/** @test */
#[Test]
public function it_can_filter_by_float_values_without_matches()
{
$product = Product::factory()->create([
Expand All @@ -117,8 +110,7 @@ public function it_can_filter_by_float_values_without_matches()
->assertOk()
->assertJsonCount(0);
}

/** @test */
#[Test]
public function it_can_filter_by_boolean_values_with_results()
{
$product = Product::factory()->create([
Expand All @@ -131,8 +123,7 @@ public function it_can_filter_by_boolean_values_with_results()

assertEquals($product->id, $response->json()[0]['id']);
}

/** @test */
#[Test]
public function it_can_filter_by_timestamp_values_without_matches()
{
$product = Product::factory()->create();
Expand All @@ -143,8 +134,7 @@ public function it_can_filter_by_timestamp_values_without_matches()
->assertOk()
->assertJsonCount(0);
}

/** @test */
#[Test]
public function it_can_filter_by_timestamp_values_with_results()
{
$product = Product::factory()->create();
Expand All @@ -157,8 +147,7 @@ public function it_can_filter_by_timestamp_values_with_results()

assertEquals($product->id, $response->json()[0]['id']);
}

/** @test */
#[Test]
public function it_can_filter_by_boolean_values_without_matches()
{
$product = Product::factory()->create([
Expand All @@ -169,26 +158,23 @@ public function it_can_filter_by_boolean_values_without_matches()
->assertOk()
->assertJsonCount(0);
}

/** @test */
#[Test]
public function it_can_filter_with_eqc_operator(): void
{
$response = $this->getJson('/posts?filters[title][$eqc]=LARAVEL refine is the best');

$response->assertOk();
$response->assertJsonCount(0);
}

/** @test */
#[Test]
public function it_can_filter_with_ne_operator(): void
{
$response = $this->getJson('/posts?filters[title][$ne]=no matches');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_lt_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -199,8 +185,7 @@ public function it_can_filter_with_lt_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_lte_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -211,8 +196,7 @@ public function it_can_filter_with_lte_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_gt_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -223,8 +207,7 @@ public function it_can_filter_with_gt_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_gte_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -235,8 +218,7 @@ public function it_can_filter_with_gte_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_in_operator(): void
{
Product::factory()->create([
Expand All @@ -255,8 +237,7 @@ public function it_can_filter_with_in_operator(): void
->assertOk()
->assertJsonCount(2);
}

/** @test */
#[Test]
public function it_can_filter_with_notIn_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -267,43 +248,38 @@ public function it_can_filter_with_notIn_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_contains_operator(): void
{
$response = $this->getJson('/posts?filters[title][$contains]=laravel');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_notContains_operator(): void
{
$response = $this->getJson('/posts?filters[title][$notContains]=complexity');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_containsc_operator(): void
{
$response = $this->getJson('/posts?filters[title][$containsc]=laravel');
$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_notContainsc_operator(): void
{
$response = $this->getJson('/posts?filters[title][$notContainsc]=complexity');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_null_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -314,8 +290,7 @@ public function it_can_filter_with_null_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_notNull_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -326,8 +301,7 @@ public function it_can_filter_with_notNull_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_between_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -338,8 +312,7 @@ public function it_can_filter_with_between_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_notBetween_operator(): void
{
$product = Product::factory()->create([
Expand All @@ -350,44 +323,39 @@ public function it_can_filter_with_notBetween_operator(): void
->assertOk()
->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_startsWith_operator(): void
{
$response = $this->getJson('/posts?filters[title][$startsWith]=laravel');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_startsWithc_operator(): void
{
$response = $this->getJson('/posts?filters[title][$startsWithc]=laravel');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_endsWith_operator(): void
{
$response = $this->getJson('/posts?filters[title][$endsWith]=best');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_endsWithc_operator(): void
{
$response = $this->getJson('/posts?filters[title][$endsWithc]=best');

$response->assertOk();
$response->assertJsonCount(1);
}

/** @test */
#[Test]
public function it_can_filter_with_or_operator(): void
{
$post1 = Post::create(['title' => 'laravel refine']);
Expand All @@ -399,8 +367,7 @@ public function it_can_filter_with_or_operator(): void
->assertOk()
->assertJsonCount(2);
}

/** @test */
#[Test]
public function it_can_filter_with_and_operator(): void
{
$post = Product::factory()->create([
Expand Down
Loading
Loading