Skip to content

Commit 1b867e3

Browse files
authored
Merge pull request #139 from viralsolani/analysis-qyL1yb
Apply fixes from StyleCI
2 parents 55b49b3 + 14fbfac commit 1b867e3

File tree

7 files changed

+53
-61
lines changed

7 files changed

+53
-61
lines changed

app/Repositories/Backend/Blogs/BlogsRepository.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,19 @@
22

33
namespace App\Repositories\Backend\Blogs;
44

5-
use DB;
6-
use Carbon\Carbon;
7-
use App\Models\Blogs\Blog;
8-
use App\Models\BlogTags\BlogTag;
9-
use App\Http\Utilities\FileUploads;
10-
use App\Exceptions\GeneralException;
11-
use App\Repositories\BaseRepository;
12-
use App\Models\BlogMapTags\BlogMapTag;
13-
use Illuminate\Support\Facades\Storage;
5+
use App\Events\Backend\Blogs\BlogCreated;
146
use App\Events\Backend\Blogs\BlogDeleted;
157
use App\Events\Backend\Blogs\BlogUpdated;
16-
use App\Events\Backend\Blogs\BlogCreated;
8+
use App\Exceptions\GeneralException;
179
use App\Models\BlogCategories\BlogCategory;
1810
use App\Models\BlogMapCategories\BlogMapCategory;
11+
use App\Models\BlogMapTags\BlogMapTag;
12+
use App\Models\Blogs\Blog;
13+
use App\Models\BlogTags\BlogTag;
14+
use App\Repositories\BaseRepository;
15+
use Carbon\Carbon;
16+
use DB;
17+
use Illuminate\Support\Facades\Storage;
1918

2019
/**
2120
* Class BlogsRepository.
@@ -38,7 +37,7 @@ class BlogsRepository extends BaseRepository
3837

3938
public function __construct()
4039
{
41-
$this->upload_path = 'img' . DIRECTORY_SEPARATOR . 'blog' . DIRECTORY_SEPARATOR;
40+
$this->upload_path = 'img'.DIRECTORY_SEPARATOR.'blog'.DIRECTORY_SEPARATOR;
4241
$this->storage = Storage::disk('public');
4342
}
4443

@@ -229,9 +228,9 @@ public function uploadImage($input)
229228
$avatar = $input['featured_image'];
230229

231230
if (isset($input['featured_image']) && !empty($input['featured_image'])) {
232-
$fileName = time() . $avatar->getClientOriginalName();
231+
$fileName = time().$avatar->getClientOriginalName();
233232

234-
$this->storage->put($this->upload_path . $fileName, file_get_contents($avatar->getRealPath()));
233+
$this->storage->put($this->upload_path.$fileName, file_get_contents($avatar->getRealPath()));
235234

236235
$input = array_merge($input, ['featured_image' => $fileName]);
237236

@@ -247,7 +246,7 @@ public function uploadImage($input)
247246
public function deleteOldFile($model)
248247
{
249248
$fileName = $model->featured_image;
250-
251-
return $this->storage->delete($this->upload_path . $fileName);
249+
250+
return $this->storage->delete($this->upload_path.$fileName);
252251
}
253252
}

database/factories/BlogFactory.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
<?php
22

3+
use App\Models\Access\User\User;
34
use App\Models\Blogs\Blog;
45
use Faker\Generator as Faker;
5-
use App\Models\Access\User\User;
66

77
$factory->define(Blog::class, function (Faker $faker) {
8-
98
$status = [
109
'Published',
1110
'Draft',
1211
'InActive',
13-
'Scheduled'
12+
'Scheduled',
1413
];
15-
14+
1615
return [
17-
'name' => $faker->sentence,
16+
'name' => $faker->sentence,
1817
'publish_datetime' => $faker->dateTime(),
19-
'featured_image' => 'logo.png',
20-
'content' => $faker->paragraph(3),
21-
'status' => $status[$faker->numberBetween(0,3)],
22-
'created_by' => function () {
18+
'featured_image' => 'logo.png',
19+
'content' => $faker->paragraph(3),
20+
'status' => $status[$faker->numberBetween(0, 3)],
21+
'created_by' => function () {
2322
return factory(User::class)->create()->id;
2423
},
2524
];
2625
});
27-

database/factories/FaqFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
$factory->define(Faq::class, function (Faker $faker) {
77
return [
8-
'question' => rtrim($faker->sentence, '.') . '?',
8+
'question' => rtrim($faker->sentence, '.').'?',
99
'answer' => $faker->paragraph,
10-
'status' => $faker->numberBetween(0,1)
10+
'status' => $faker->numberBetween(0, 1),
1111
];
1212
});

database/factories/PageFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3+
use App\Models\Access\User\User;
34
use App\Models\Page\Page;
45
use Faker\Generator as Faker;
5-
use App\Models\Access\User\User;
66

77
$factory->define(Page::class, function (Faker $faker) {
88
$title = $faker->sentence;
@@ -11,7 +11,7 @@
1111
'title' => $title,
1212
'page_slug' => str_slug($title),
1313
'description' => $faker->paragraph,
14-
'created_by' => function () {
14+
'created_by' => function () {
1515
return factory(User::class)->create()->id;
1616
},
1717
];

tests/Feature/Backend/ManageBlogsTest.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
namespace Tests\Feature\Backend;
44

5-
use Tests\TestCase;
65
use App\Models\Blogs\Blog;
7-
use App\Models\BlogTags\BlogTag;
6+
use Illuminate\Foundation\Testing\WithFaker;
87
use Illuminate\Http\UploadedFile;
98
use Illuminate\Support\Facades\Storage;
10-
use App\Models\BlogCategories\BlogCategory;
11-
use Illuminate\Foundation\Testing\WithFaker;
9+
use Tests\TestCase;
1210

1311
class ManageBlogsTest extends TestCase
1412
{
@@ -27,7 +25,6 @@ public function setUp()
2725
$this->blog = create(Blog::class);
2826
$this->categories = [$this->faker->word, $this->faker->word];
2927
$this->tags = [$this->faker->word, $this->faker->word];
30-
3128
}
3229

3330
/** @test */
@@ -48,21 +45,21 @@ public function a_user_can_view_blogs_index_page()
4845

4946
/** @test */
5047
public function a_user_can_create_a_blog()
51-
{
48+
{
5249
$blog = make(Blog::class, [
5350
'featured_image' => UploadedFile::fake()->image('logo.jpg'),
54-
'categories' => $this->categories,
55-
'tags' => $this->tags
51+
'categories' => $this->categories,
52+
'tags' => $this->tags,
5653
]);
5754

5855
$this->post(route('admin.blogs.store'), $blog->toArray());
5956

6057
$this->assertDatabaseHas(config('module.blogs.table'), ['name' => $blog->name, 'status' => $blog->status]);
61-
58+
6259
//Assert Tags have been saved
6360
$this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $this->tags[0]]);
6461
$this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $this->tags[1]]);
65-
62+
6663
//Assert Categories have been saved
6764
$this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $this->categories[0]]);
6865
$this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $this->categories[1]]);
@@ -108,7 +105,7 @@ public function it_requires_featured_image_while_creating()
108105
public function it_requires_categories_while_creating()
109106
{
110107
$blog = $this->makeBlog(['categories' => '']);
111-
108+
112109
$this->post(route('admin.blogs.store'), $blog->toArray())
113110
->assertSessionHasErrors('categories');
114111
}
@@ -127,15 +124,15 @@ public function it_can_store_featured_image()
127124
{
128125
$blog = make(Blog::class, [
129126
'featured_image' => UploadedFile::fake()->image('logo.jpg'),
130-
'categories' => $this->categories,
131-
'tags' => $this->tags
127+
'categories' => $this->categories,
128+
'tags' => $this->tags,
132129
]);
133130

134131
$this->post(route('admin.blogs.store'), $blog->toArray());
135132

136133
$stored_blog = Blog::find(2);
137134

138-
Storage::disk('public')->assertExists('img/blog/' . $stored_blog->featured_image);
135+
Storage::disk('public')->assertExists('img/blog/'.$stored_blog->featured_image);
139136
}
140137

141138
/** @test */
@@ -159,7 +156,7 @@ public function it_requires_content_while_updating()
159156
$this->patch(route('admin.blogs.update', $this->blog), $this->blog->toArray())
160157
->assertSessionHasErrors('content');
161158
}
162-
159+
163160
/** @test */
164161
public function it_requires_categories_while_updating()
165162
{
@@ -182,17 +179,17 @@ public function it_requires_tags_while_updating()
182179
public function a_user_can_update_blog()
183180
{
184181
$blog = make(Blog::class, [
185-
'featured_image' => UploadedFile::fake()->image('logo.jpg'),
186-
'name' => 'Changed Name',
187-
'categories' => $this->categories,
188-
'tags' => $this->tags
182+
'featured_image' => UploadedFile::fake()->image('logo.jpg'),
183+
'name' => 'Changed Name',
184+
'categories' => $this->categories,
185+
'tags' => $this->tags,
189186
]);
190187

191188
$this->patch(route('admin.blogs.update', $this->blog), $blog->toArray());
192189

193190
$this->assertDatabaseHas(config('module.blogs.table'), ['id' => $this->blog->id, 'name' => 'Changed Name']);
194191
}
195-
192+
196193
/** @test */
197194
public function a_user_can_delete_a_blog()
198195
{

tests/Feature/Backend/ManageFaqsTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Tests\Feature\Backend;
44

5-
use Tests\TestCase;
65
use App\Models\Faqs\Faq;
6+
use Tests\TestCase;
77

88
class ManageFaqsTest extends TestCase
99
{
@@ -43,7 +43,6 @@ public function it_requires_question_while_creating()
4343
->assertSessionHasErrors('question');
4444
}
4545

46-
4746
/** @test */
4847
public function it_requires_answer_while_creating()
4948
{
@@ -82,7 +81,7 @@ public function a_user_can_update_faq()
8281
{
8382
$faq = create(Faq::class);
8483

85-
$changed_question = "What is Life?";
84+
$changed_question = 'What is Life?';
8685
$changed_answer = $faq->answer;
8786
$this->actingAs($this->admin)
8887
->patch(route('admin.faqs.update', $faq), ['question' => $changed_question, 'answer' => $changed_answer]);
@@ -96,7 +95,7 @@ public function a_user_can_delete_faq()
9695
$faq = create(Faq::class);
9796

9897
$this->actingAs($this->admin)
99-
->delete(route('admin.faqs.destroy' , $faq));
98+
->delete(route('admin.faqs.destroy', $faq));
10099

101100
$this->assertDatabaseMissing(config('module.faqs.table'), ['id' => $faq->id, 'deleted_at' => null]);
102101
}

tests/Unit/Models/BlogTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace Tests\Unit\Models;
44

5-
use Carbon\Carbon;
6-
use Tests\TestCase;
7-
use App\Models\Blogs\Blog;
8-
use App\Models\BlogTags\BlogTag;
95
use App\Models\Access\User\User;
106
use App\Models\BlogCategories\BlogCategory;
11-
use Illuminate\Foundation\Testing\WithFaker;
7+
use App\Models\Blogs\Blog;
8+
use App\Models\BlogTags\BlogTag;
9+
use Carbon\Carbon;
10+
use Tests\TestCase;
1211

1312
class BlogTest extends TestCase
1413
{
@@ -21,8 +20,8 @@ public function it_has_categories()
2120

2221
$category = create(BlogCategory::class);
2322

24-
$blog->categories()->sync(array($category->id));
25-
23+
$blog->categories()->sync([$category->id]);
24+
2625
$this->assertInstanceOf(BlogCategory::class, $blog->categories->first());
2726

2827
$this->assertEquals($category->id, $blog->categories->first()->id);
@@ -37,7 +36,7 @@ public function it_has_tags()
3736

3837
$tag = create(BlogTag::class);
3938

40-
$blog->tags()->sync(array($tag->id));
39+
$blog->tags()->sync([$tag->id]);
4140

4241
$this->assertInstanceOf(BlogTag::class, $blog->tags->first());
4342

0 commit comments

Comments
 (0)