Skip to content

Commit

Permalink
Update CommentFactory.php (#19)
Browse files Browse the repository at this point in the history
* Update CommentFactory.php

fix CommentFactory :: commentable_type

Error: Class "App\Random\...." not found

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
ngaspari and StyleCIBot authored Jan 23, 2024
1 parent 65cda33 commit 5813cf8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions config/asseco-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* UUIDs as primary keys.
*/
'uuid' => false,
'uuid' => false,

/**
* Timestamp types.
Expand All @@ -30,11 +30,11 @@
* Should the package run the migrations. Set to false if you're publishing
* and changing default migrations.
*/
'run' => true,
'run' => true,
],

'routes' => [
'prefix' => 'api',
'prefix' => 'api',
'middleware' => ['api'],
],
];
4 changes: 2 additions & 2 deletions src/App/Http/Requests/CommentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function authorize()
public function rules()
{
return [
'body' => 'required',
'body' => 'required',
'commentable_type' => 'required|string',
'commentable_id' => 'required',
'commentable_id' => 'required',
];
}

Expand Down
11 changes: 7 additions & 4 deletions src/Database/Factories/CommentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ public function modelName()
*/
public function definition()
{
$commType = env('ASEE_COMMENTABLE_TYPE', $this->faker->word);

$data = [
'body' => $this->faker->sentence(),
'commentable_type' => 'App\\Random\\' . ucfirst($this->faker->word),
'commentable_id' => $this->faker->randomNumber(),
'body' => $this->faker->sentence(),
//'commentable_type' => 'App\\Random\\' . ucfirst($this->faker->word),
'commentable_type' => $commType,
'commentable_id' => $this->faker->randomNumber(),
];

if (config('asseco-comments.migrations.uuid')) {
$data = array_merge($data, [
'commentable_id' => $this->faker->uuid(),
'commentable_id' => $this->faker->uuid(),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Http/Controllers/CommentControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function creates_comment()
$this
->postJson(route('comments.store'), $request)
->assertJsonFragment([
'id' => 1,
'id' => 1,
'body' => $request['body'],
]);

Expand Down

0 comments on commit 5813cf8

Please sign in to comment.