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
2 changes: 1 addition & 1 deletion src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Field extends OrganicField implements JsonSerializable
public $value;

/**
* In case of the update, this will keep the previous value
* In case of the update, this will keep the previous value.
* @var
*/
public $valueBeforeUpdate;
Expand Down
26 changes: 10 additions & 16 deletions tests/Unit/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Binaryk\LaravelRestify\Fields\Field;
use Binaryk\LaravelRestify\Http\Requests\RepositoryStoreRequest;
use Binaryk\LaravelRestify\Http\Requests\RepositoryUpdateRequest;
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
use Binaryk\LaravelRestify\Tests\Fixtures\PostRepository;
use Binaryk\LaravelRestify\Tests\IntegrationTest;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -19,10 +18,10 @@ public function test_fields_can_have_custom_index_callback()
return strtoupper($value);
});

$field->resolveForIndex((object)['name' => 'Binaryk'], 'name');
$field->resolveForIndex((object) ['name' => 'Binaryk'], 'name');
$this->assertEquals('BINARYK', $field->value);

$field->resolveForShow((object)['name' => 'Binaryk'], 'name');
$field->resolveForShow((object) ['name' => 'Binaryk'], 'name');
$this->assertEquals('Binaryk', $field->value);
}

Expand All @@ -32,10 +31,10 @@ public function test_fields_can_have_custom_show_callback()
return strtoupper($value);
});

$field->resolveForShow((object)['name' => 'Binaryk'], 'name');
$field->resolveForShow((object) ['name' => 'Binaryk'], 'name');
$this->assertEquals('BINARYK', $field->value);

$field->resolveForIndex((object)['name' => 'Binaryk'], 'name');
$field->resolveForIndex((object) ['name' => 'Binaryk'], 'name');
$this->assertEquals('Binaryk', $field->value);
}

Expand All @@ -45,7 +44,7 @@ public function test_fields_can_have_custom_resolver_callback_even_if_field_is_m
return strtoupper('default');
});

$field->resolveForShow((object)['name' => 'Binaryk'], 'email');
$field->resolveForShow((object) ['name' => 'Binaryk'], 'email');

$this->assertEquals('DEFAULT', $field->value);
}
Expand All @@ -56,7 +55,7 @@ public function test_computed_fields_resolve()
return 'Computed';
});

$field->resolveForIndex((object)[]);
$field->resolveForIndex((object) []);

$this->assertEquals('Computed', $field->value);
}
Expand All @@ -67,7 +66,7 @@ public function test_fields_may_have_callback_resolver()
return 'Resolved Title';
});

$field->resolveForIndex((object)[]);
$field->resolveForIndex((object) []);

$this->assertEquals('Resolved Title', $field->value);
}
Expand All @@ -76,7 +75,7 @@ public function test_fields_has_default_value()
{
$field = Field::make('title')->default('Title');

$field->resolveForIndex((object)[]);
$field->resolveForIndex((object) []);

$this->assertEquals('Title', data_get($field->jsonSerialize(), 'value'));
}
Expand All @@ -94,7 +93,6 @@ public function test_field_can_have_custom_store_callback()
$model->title = 'from store callback';
});


$field->fillAttribute($request, $model);

$this->assertEquals('from store callback', $model->title);
Expand All @@ -113,7 +111,6 @@ public function test_field_can_have_custom_udpate_callback()
$model->title = 'from update callback';
});


$field->fillAttribute($request, $model);

$this->assertEquals('from update callback', $model->title);
Expand All @@ -136,9 +133,8 @@ public function test_field_fill_callback_has_high_priority()
$model->title = 'from store callback';
})
->updateCallback(function ($request, $model) {
$model->title = 'from update callback';
});

$model->title = 'from update callback';
});

$field->fillAttribute($request, $model);

Expand All @@ -157,7 +153,6 @@ public function test_field_fill_from_request()
});
});


$request->merge([
'title' => 'title from request',
]);
Expand All @@ -169,7 +164,6 @@ public function test_field_fill_from_request()
/** * @var Field $field */
$field = Field::new('title');


$field->fillAttribute($request, $model);

$this->assertEquals('title from request', $model->title);
Expand Down