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
3 changes: 1 addition & 2 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
Route::post('/profile', '\\'.ProfileUpdateController::class);
Route::post('/profile/avatar', '\\'.ProfileAvatarController::class);


// RestifyJS
Route::get('/restifyjs/setup', '\\' . RestifyJsSetupController::class);
Route::get('/restifyjs/setup', '\\'.RestifyJsSetupController::class);

// Filters
Route::get('/{repository}/filters', '\\'.RepositoryFilterController::class);
Expand Down
4 changes: 2 additions & 2 deletions src/Eager/Related.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(string $relation, EagerField $field = null)

public function isEager(): bool
{
return !is_null($this->field);
return ! is_null($this->field);
}

public function getRelation(): string
Expand All @@ -41,7 +41,7 @@ public function jsonSerialize()
'relation' => $this->getRelation(),
'field' => isset($this->field)
? $this->field->jsonSerialize()
: null
: null,
];
}
}
4 changes: 2 additions & 2 deletions src/LaravelRestifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function registerPublishing()
$migrationFileName = 'create_action_logs_table.php';
if (! $this->migrationFileExists($migrationFileName)) {
$this->publishes([
__DIR__ . "/../database/migrations/{$migrationFileName}" => database_path('migrations/' . date('Y_m_d_His', time()) . '_' . $migrationFileName),
__DIR__."/../database/migrations/{$migrationFileName}" => database_path('migrations/'.date('Y_m_d_His', time()).'_'.$migrationFileName),
], 'restify-migrations');
}

Expand All @@ -98,7 +98,7 @@ protected function registerPublishing()
public static function migrationFileExists(string $migrationFileName): bool
{
$len = strlen($migrationFileName);
foreach (glob(database_path("migrations/*.php")) as $filename) {
foreach (glob(database_path('migrations/*.php')) as $filename) {
if ((substr($filename, -$len) === $migrationFileName)) {
return true;
}
Expand Down
9 changes: 4 additions & 5 deletions src/Models/ActionLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Support\Str;

/**
* Class ActionLog
* Class ActionLog.
* @property string batch_id
* @property string user_id
* @property string name
Expand All @@ -22,7 +22,6 @@
* @property string original
* @property string changes
* @property string exception
* @package Binaryk\LaravelRestify\Models
*/
class ActionLog extends Model
{
Expand All @@ -44,7 +43,7 @@ class ActionLog extends Model
public static function forRepositoryStored(Model $model, Authenticatable $user = null, array $dirty = null): self
{
return new static([
'batch_id' => (string)Str::uuid(),
'batch_id' => (string) Str::uuid(),
'user_id' => optional($user)->getAuthIdentifier(),
'name' => static::ACTION_CREATED,
'actionable_type' => $model->getMorphClass(),
Expand All @@ -66,7 +65,7 @@ public static function forRepositoryStored(Model $model, Authenticatable $user =
public static function forRepositoryUpdated(Model $model, Authenticatable $user = null): self
{
return new static([
'batch_id' => (string)Str::uuid(),
'batch_id' => (string) Str::uuid(),
'user_id' => optional($user)->getAuthIdentifier(),
'name' => static::ACTION_UPDATED,
'actionable_type' => $model->getMorphClass(),
Expand All @@ -88,7 +87,7 @@ public static function forRepositoryUpdated(Model $model, Authenticatable $user
public static function forRepositoryDestroy(Model $model, Authenticatable $user = null): self
{
return new static([
'batch_id' => (string)Str::uuid(),
'batch_id' => (string) Str::uuid(),
'user_id' => optional($user)->getAuthIdentifier(),
'name' => static::ACTION_DELETED,
'actionable_type' => $model->getMorphClass(),
Expand Down
2 changes: 1 addition & 1 deletion src/Repositories/ActionLogRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function fields(RestifyRequest $request)
return [
field('actionable_type'),

field('actionable_id')
field('actionable_id'),
];
}
}
1 change: 0 additions & 1 deletion src/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,6 @@ public function detach(RestifyRequest $request, $repositoryId, Collection $pivot
public function destroy(RestifyRequest $request, $repositoryId)
{
$status = DB::transaction(function () use ($request) {

if ($this->resource instanceof ActionLogable) {
Restify::actionLog()
->forRepositoryDestroy($this->resource, $request->user())
Expand Down
12 changes: 6 additions & 6 deletions tests/Controllers/RepositoryUpdateControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function test_basic_update_works()
{
$post = factory(Post::class)->create();

$this->patch('posts/' . $post->id, [
$this->patch('posts/'.$post->id, [
'title' => 'Updated title',
])->assertStatus(200);

Expand All @@ -34,7 +34,7 @@ public function test_put_works()
{
$post = factory(Post::class)->create();

$this->withoutExceptionHandling()->put('posts/' . $post->id, [
$this->withoutExceptionHandling()->put('posts/'.$post->id, [
'title' => 'Updated title',
])->assertStatus(200);

Expand All @@ -51,7 +51,7 @@ public function test_unathorized_to_update()

$_SERVER['restify.post.update'] = false;

$this->patch('posts/' . $post->id, [
$this->patch('posts/'.$post->id, [
'title' => 'Updated title',
])->assertStatus(403)
->assertJson([
Expand All @@ -65,7 +65,7 @@ public function test_do_not_update_fields_without_permission()

$_SERVER['posts.authorizable.title'] = false;

$response = $this->putJson('post-with-unathorized-fields/' . $post->id, [
$response = $this->putJson('post-with-unathorized-fields/'.$post->id, [
'title' => 'Updated title',
'user_id' => 2,
])
Expand All @@ -81,7 +81,7 @@ public function test_will_not_update_readonly_fields()

$post = factory(Post::class)->create(['image' => null]);

$r = $this->putJson('posts-unauthorized-fields/' . $post->id, [
$r = $this->putJson('posts-unauthorized-fields/'.$post->id, [
'user_id' => $user->id,
'image' => 'avatar.png',
'title' => 'Some post title',
Expand All @@ -108,7 +108,7 @@ public function test_updating_repository_log_action()
'user_id' => $this->authenticatedAs->getAuthIdentifier(),
'name' => ActionLog::ACTION_UPDATED,
'actionable_type' => Post::class,
'actionable_id' => (string)$post->id
'actionable_id' => (string) $post->id,
]);

$log = ActionLog::latest()->first();
Expand Down
4 changes: 2 additions & 2 deletions tests/Controllers/RestifyJsSetupControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function test_returns_configurations()
'sort',
'match',
'searchables',
]
]
],
],
])
->assertOk();
}
Expand Down
18 changes: 8 additions & 10 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function setUp(): void
$this->repositoryMock();
$this->loadMigrations();
$this->loadRoutes();
$this->withFactories(__DIR__ . '/Factories');
$this->withFactories(__DIR__.'/Factories');
$this->injectTranslator();
$this->app->bind(ExceptionHandler::class, RestifyHandler::class);

Expand Down Expand Up @@ -87,7 +87,7 @@ protected function getEnvironmentSetUp($app)
'prefix' => '',
]);

include_once __DIR__ . '/../database/migrations/create_action_logs_table.php';
include_once __DIR__.'/../database/migrations/create_action_logs_table.php';
(new \CreateActionLogsTable())->up();
}

Expand All @@ -100,7 +100,7 @@ protected function loadMigrations()
{
$this->loadMigrationsFrom([
'--database' => 'sqlite',
'--path' => realpath(__DIR__ . DIRECTORY_SEPARATOR . 'Migrations'),
'--path' => realpath(__DIR__.DIRECTORY_SEPARATOR.'Migrations'),
]);
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public function mockUsers($count = 1, $predefinedEmails = [])
$i = 0;
while ($i < $count) {
$users->push(factory(User::class)->create());
$i ++;
$i++;
}

foreach ($predefinedEmails as $email) {
Expand All @@ -262,31 +262,29 @@ public function mockPosts($userId, $count = 1)
$users->push(factory(Post::class)->create(
['user_id' => $userId]
));
$i ++;
$i++;
}

return $users->shuffle(); // randomly shuffles the items in the collection
}

public function getTempDirectory($suffix = ''): string
{
return __DIR__ . '/TestSupport/temp' . ($suffix == '' ? '' : '/' . $suffix);
return __DIR__.'/TestSupport/temp'.($suffix == '' ? '' : '/'.$suffix);
}

public function getMediaDirectory($suffix = ''): string
{
return $this->getTempDirectory() . '/media' . ($suffix == '' ? '' : '/' . $suffix);
return $this->getTempDirectory().'/media'.($suffix == '' ? '' : '/'.$suffix);
}

public function getTestFilesDirectory($suffix = ''): string
{
return $this->getTempDirectory() . '/testfiles' . ($suffix == '' ? '' : '/' . $suffix);
return $this->getTempDirectory().'/testfiles'.($suffix == '' ? '' : '/'.$suffix);
}

public function getTestJpg(): string
{
return $this->getTestFilesDirectory('test.jpg');
}


}