Skip to content

Commit

Permalink
Add support for Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanheffley committed Mar 28, 2024
1 parent 2e2c525 commit 31bed27
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 58 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
],
"require": {
"php": "^8.0",
"illuminate/database": "^10.13.2",
"illuminate/http": "^10.13.2",
"illuminate/routing": "^10.13.2",
"illuminate/support": "^10.13.2"
"illuminate/database": "^11.0",
"illuminate/http": "^11.0",
"illuminate/routing": "^11.0",
"illuminate/support": "^11.0"
},
"require-dev": {
"laravel/sail": "^1.26",
"orchestra/testbench": "^8.15"
"orchestra/testbench": "^9.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function pull(Request $request): JsonResponse

$changes = [];

if ($lastPulledAt === 'null') {
if ($lastPulledAt === null) {
foreach ($this->models as $name => $class) {
$changes[$name] = [
'created' => (new $class)::watermelon()
Expand Down
19 changes: 10 additions & 9 deletions tests/Feature/CustomWatermelonIDModelPullTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Config;
use NathanHeffley\LaravelWatermelon\Tests\models\CustomTask as Task;
use NathanHeffley\LaravelWatermelon\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class CustomWatermelonIDModelPullTest extends TestCase
{
Expand All @@ -25,7 +26,7 @@ public function setUp(): void
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_no_data_and_no_last_pulled_at_timestamp(): void
{
$response = $this->json('GET', '/sync');
Expand All @@ -42,7 +43,7 @@ public function it_can_respond_to_pull_requests_with_no_data_and_no_last_pulled_
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_no_data_and_a_null_last_pulled_at_timestamp(): void
{
$response = $this->json('GET', '/sync?last_pulled_at=null');
Expand All @@ -59,7 +60,7 @@ public function it_can_respond_to_pull_requests_with_no_data_and_a_null_last_pul
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_no_data_and_a_zero_last_pulled_at_timestamp(): void
{
$response = $this->json('GET', '/sync?last_pulled_at=0');
Expand All @@ -76,7 +77,7 @@ public function it_can_respond_to_pull_requests_with_no_data_and_a_zero_last_pul
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_no_changes_and_a_last_pulled_at_timestamp(): void
{
$lastPulledAt = now()->subMinutes(10)->timestamp;
Expand All @@ -94,7 +95,7 @@ public function it_can_respond_to_pull_requests_with_no_changes_and_a_last_pulle
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_data_and_no_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down Expand Up @@ -141,7 +142,7 @@ public function it_can_respond_to_pull_requests_with_data_and_no_last_pulled_at_
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_data_and_a_null_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down Expand Up @@ -188,7 +189,7 @@ public function it_can_respond_to_pull_requests_with_data_and_a_null_last_pulled
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_data_and_a_zero_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down Expand Up @@ -235,7 +236,7 @@ public function it_can_respond_to_pull_requests_with_data_and_a_zero_last_pulled
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_data_and_a_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down Expand Up @@ -298,7 +299,7 @@ public function it_can_respond_to_pull_requests_with_data_and_a_last_pulled_at_t
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_with_lots_of_deleted_records_and_a_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down
13 changes: 7 additions & 6 deletions tests/Feature/CustomWatermelonIDModelPushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Config;
use NathanHeffley\LaravelWatermelon\Tests\models\CustomTask as Task;
use NathanHeffley\LaravelWatermelon\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class CustomWatermelonIDModelPushTest extends TestCase
{
Expand All @@ -25,7 +26,7 @@ public function setUp(): void
]);
}

/** @test */
#[Test]
public function it_ignores_changes_for_models_not_in_the_watermelon_models_config_array(): void
{
$response = $this->json('POST', '/sync', [
Expand All @@ -48,7 +49,7 @@ public function it_ignores_changes_for_models_not_in_the_watermelon_models_confi
$response->assertNoContent();
}

/** @test */
#[Test]
public function it_persists_push_request_changes(): void
{
$firstTask = Task::query()->create([
Expand Down Expand Up @@ -98,7 +99,7 @@ public function it_persists_push_request_changes(): void
]);
}

/** @test */
#[Test]
public function it_updates_the_record_if_there_is_an_attempt_to_create_an_existing_record(): void
{
Task::query()->create([
Expand Down Expand Up @@ -136,7 +137,7 @@ public function it_updates_the_record_if_there_is_an_attempt_to_create_an_existi
]);
}

/** @test */
#[Test]
public function it_creates_a_record_if_there_is_an_attempt_to_update_a_non_existent_record(): void
{
$response = $this->json('POST', '/sync', [
Expand Down Expand Up @@ -164,7 +165,7 @@ public function it_creates_a_record_if_there_is_an_attempt_to_update_a_non_exist
]);
}

/** @test */
#[Test]
public function it_does_not_throw_an_error_if_there_is_an_attempt_to_delete_an_already_deleted_record(): void
{
$deletedAt = now()->subMinute();
Expand All @@ -188,7 +189,7 @@ public function it_does_not_throw_an_error_if_there_is_an_attempt_to_delete_an_a
$this->assertEquals($deletedAt, $task->fresh()->deleted_at);
}

/** @test */
#[Test]
public function it_rolls_back_push_request_changes_if_there_is_an_attempt_to_update_a_deleted_record(): void
{
Task::query()->create([
Expand Down
9 changes: 5 additions & 4 deletions tests/Feature/ModelAuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Config;
use NathanHeffley\LaravelWatermelon\Tests\models\TaskScoped;
use NathanHeffley\LaravelWatermelon\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class ModelAuthorizationTest extends TestCase
{
Expand All @@ -23,7 +24,7 @@ public function setUp(): void
]);
}

/** @test */
#[Test]
public function it_can_apply_a_models_watermelon_scope_with_no_last_pulled_at_timestamp(): void
{
TaskScoped::query()->create([
Expand Down Expand Up @@ -69,7 +70,7 @@ public function it_can_apply_a_models_watermelon_scope_with_no_last_pulled_at_ti
]);
}

/** @test */
#[Test]
public function it_can_apply_a_models_watermelon_scope_with_a_last_pulled_at_timestamp(): void
{
TaskScoped::query()->create([
Expand Down Expand Up @@ -116,7 +117,7 @@ public function it_can_apply_a_models_watermelon_scope_with_a_last_pulled_at_tim
]);
}

/** @test */
#[Test]
public function it_throws_an_exception_and_rolls_back_changes_when_trying_to_update_a_model_restricted_by_watermelon_scope(): void
{
TaskScoped::query()->create([
Expand Down Expand Up @@ -172,7 +173,7 @@ public function it_throws_an_exception_and_rolls_back_changes_when_trying_to_upd
]);
}

/** @test */
#[Test]
public function it_does_not_throw_an_error_but_does_not_delete_a_model_restricted_by_watermelon_scope(): void
{
TaskScoped::query()->create([
Expand Down
9 changes: 5 additions & 4 deletions tests/Feature/MultipleModelPullTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use NathanHeffley\LaravelWatermelon\Tests\models\Project;
use NathanHeffley\LaravelWatermelon\Tests\models\Task;
use NathanHeffley\LaravelWatermelon\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class MultipleModelPullTest extends TestCase
{
Expand All @@ -25,7 +26,7 @@ public function setUp(): void
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_for_multiple_models_without_a_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down Expand Up @@ -68,7 +69,7 @@ public function it_can_respond_to_pull_requests_for_multiple_models_without_a_la
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_for_multiple_models_with_a_null_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down Expand Up @@ -111,7 +112,7 @@ public function it_can_respond_to_pull_requests_for_multiple_models_with_a_null_
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_for_multiple_models_with_a_zero_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down Expand Up @@ -154,7 +155,7 @@ public function it_can_respond_to_pull_requests_for_multiple_models_with_a_zero_
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_for_multiple_models_with_a_last_pulled_at_timestamp(): void
{
Task::query()->create([
Expand Down
9 changes: 5 additions & 4 deletions tests/Feature/MultipleModelPushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use NathanHeffley\LaravelWatermelon\Tests\models\Project;
use NathanHeffley\LaravelWatermelon\Tests\models\Task;
use NathanHeffley\LaravelWatermelon\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class MultipleModelPushTest extends TestCase
{
Expand All @@ -25,7 +26,7 @@ public function setUp(): void
]);
}

/** @test */
#[Test]
public function it_persists_push_requests_for_multiple_models(): void
{
$firstTask = Task::query()->create([
Expand Down Expand Up @@ -108,7 +109,7 @@ public function it_persists_push_requests_for_multiple_models(): void
]);
}

/** @test */
#[Test]
public function it_rolls_back_push_request_changes_for_all_models_when_an_error_is_thrown_for_one_model(): void
{
Task::query()->create([
Expand Down Expand Up @@ -189,7 +190,7 @@ public function it_rolls_back_push_request_changes_for_all_models_when_an_error_
]);
}

/** @test */
#[Test]
public function it_persists_push_requests_even_when_one_model_of_many_is_missing(): void
{
$firstTask = Task::query()->create([
Expand Down Expand Up @@ -239,7 +240,7 @@ public function it_persists_push_requests_even_when_one_model_of_many_is_missing
]);
}

/** @test */
#[Test]
public function it_persists_push_requests_even_when_an_unknown_model_is_encountered_among_many(): void
{
$firstTask = Task::query()->create([
Expand Down
9 changes: 5 additions & 4 deletions tests/Feature/NoModelPullTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use NathanHeffley\LaravelWatermelon\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class NoModelPullTest extends TestCase
{
Expand All @@ -20,7 +21,7 @@ public function setUp(): void
Config::set('watermelon.models', []);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_without_models_and_no_last_pulled_at(): void
{
$response = $this->json('GET', '/sync');
Expand All @@ -31,7 +32,7 @@ public function it_can_respond_to_pull_requests_without_models_and_no_last_pulle
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_without_models_and_null_last_pulled_at(): void
{
$response = $this->json('GET', '/sync?last_pulled_at=null');
Expand All @@ -42,7 +43,7 @@ public function it_can_respond_to_pull_requests_without_models_and_null_last_pul
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_without_models_and_zero_last_pulled_at(): void
{
$response = $this->json('GET', '/sync?last_pulled_at=0');
Expand All @@ -53,7 +54,7 @@ public function it_can_respond_to_pull_requests_without_models_and_zero_last_pul
]);
}

/** @test */
#[Test]
public function it_can_respond_to_pull_requests_without_models_and_last_pulled_at(): void
{
$lastPulledAt = now()->subMinutes(10)->timestamp;
Expand Down
5 changes: 3 additions & 2 deletions tests/Feature/NoModelPushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Support\Facades\Config;
use NathanHeffley\LaravelWatermelon\Tests\TestCase;
use PHPUnit\Framework\Attributes\Test;

class NoModelPushTest extends TestCase
{
Expand All @@ -14,14 +15,14 @@ public function setUp(): void
Config::set('watermelon.models', []);
}

/** @test */
#[Test]
public function it_can_respond_to_push_requests_with_no_models_and_no_data(): void
{
$response = $this->json('POST', '/sync');
$response->assertNoContent();
}

/** @test */
#[Test]
public function it_can_respond_to_push_requests_with_no_models_and_unknown_data(): void
{
$response = $this->json('POST', '/sync', [
Expand Down
Loading

0 comments on commit 31bed27

Please sign in to comment.