Skip to content

Commit

Permalink
test: add test case for model state assertion without JSON fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Lapkovsky committed Dec 19, 2023
1 parent 6728f2b commit d31ee75
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/ModelTestStateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ReflectionClass;
use RonasIT\Support\Tests\Support\Mock\TestModel;
use RonasIT\Support\Tests\Support\Mock\TestModelWithoutJsonFields;
use RonasIT\Support\Tests\Support\Traits\ModelTestStateMockTrait;
use RonasIT\Support\Tests\Support\Traits\MockTrait;

Expand Down Expand Up @@ -49,6 +50,16 @@ public function testAssertChangesEqualsFixture()
$modelTestState->assertChangesEqualsFixture('assertion_fixture.json');
}

public function testAssertChangesWithoutJsonFields()
{
$initialDatasetMock = collect($this->getJsonFixture('changes_equals_fixture_without_json_fields/initial_dataset.json'));
$changedDatasetMock = collect($this->getJsonFixture('changes_equals_fixture_without_json_fields/changed_dataset.json'));
$this->mockGettingDatasetForChanges($changedDatasetMock, $initialDatasetMock);

$modelTestState = new ModelTestState(TestModelWithoutJsonFields::class);
$modelTestState->assertChangesEqualsFixture('assertion_fixture_without_json_fields.json');
}

public function testAssertNoChanges()
{
$datasetMock = collect($this->getJsonFixture('get_without_changes/dataset.json'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"updated": [
{
"id": 1,
"name": "name1 updated"
}
],
"created": [
{
"id": 4,
"name": "name44",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
}
],
"deleted": [
{
"id": 5,
"name": "name5",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"id": 1,
"name": "name1 updated",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
},
{
"id": 2,
"name": "name2",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
},
{
"id": 3,
"name": "name3",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
},
{
"id": 4,
"name": "name44",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"id": 1,
"name": "name1",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
},
{
"id": 2,
"name": "name2",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
},
{
"id": 3,
"name": "name3",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
},
{
"id": 5,
"name": "name5",
"created_at": "2018-10-10 10:10:10",
"updated_at": "2018-10-10 10:10:10"
}
]
16 changes: 16 additions & 0 deletions tests/support/Mock/TestModelWithoutJsonFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace RonasIT\Support\Tests\Support\Mock;

use Illuminate\Database\Eloquent\Model;
use RonasIT\Support\Traits\ModelTrait;
use Illuminate\Database\Eloquent\SoftDeletes;

class TestModelWithoutJsonFields extends Model
{
use ModelTrait, SoftDeletes;

protected $fillable = [
'name',
];
}

0 comments on commit d31ee75

Please sign in to comment.