Unverified Commit 1b867e39 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #139 from viralsolani/analysis-qyL1yb

Apply fixes from StyleCI
parents 55b49b3a 14fbfac5
...@@ -2,20 +2,19 @@ ...@@ -2,20 +2,19 @@
namespace App\Repositories\Backend\Blogs; namespace App\Repositories\Backend\Blogs;
use DB; use App\Events\Backend\Blogs\BlogCreated;
use Carbon\Carbon;
use App\Models\Blogs\Blog;
use App\Models\BlogTags\BlogTag;
use App\Http\Utilities\FileUploads;
use App\Exceptions\GeneralException;
use App\Repositories\BaseRepository;
use App\Models\BlogMapTags\BlogMapTag;
use Illuminate\Support\Facades\Storage;
use App\Events\Backend\Blogs\BlogDeleted; use App\Events\Backend\Blogs\BlogDeleted;
use App\Events\Backend\Blogs\BlogUpdated; use App\Events\Backend\Blogs\BlogUpdated;
use App\Events\Backend\Blogs\BlogCreated; use App\Exceptions\GeneralException;
use App\Models\BlogCategories\BlogCategory; use App\Models\BlogCategories\BlogCategory;
use App\Models\BlogMapCategories\BlogMapCategory; use App\Models\BlogMapCategories\BlogMapCategory;
use App\Models\BlogMapTags\BlogMapTag;
use App\Models\Blogs\Blog;
use App\Models\BlogTags\BlogTag;
use App\Repositories\BaseRepository;
use Carbon\Carbon;
use DB;
use Illuminate\Support\Facades\Storage;
/** /**
* Class BlogsRepository. * Class BlogsRepository.
...@@ -38,7 +37,7 @@ class BlogsRepository extends BaseRepository ...@@ -38,7 +37,7 @@ class BlogsRepository extends BaseRepository
public function __construct() public function __construct()
{ {
$this->upload_path = 'img' . DIRECTORY_SEPARATOR . 'blog' . DIRECTORY_SEPARATOR; $this->upload_path = 'img'.DIRECTORY_SEPARATOR.'blog'.DIRECTORY_SEPARATOR;
$this->storage = Storage::disk('public'); $this->storage = Storage::disk('public');
} }
...@@ -229,9 +228,9 @@ class BlogsRepository extends BaseRepository ...@@ -229,9 +228,9 @@ class BlogsRepository extends BaseRepository
$avatar = $input['featured_image']; $avatar = $input['featured_image'];
if (isset($input['featured_image']) && !empty($input['featured_image'])) { if (isset($input['featured_image']) && !empty($input['featured_image'])) {
$fileName = time() . $avatar->getClientOriginalName(); $fileName = time().$avatar->getClientOriginalName();
$this->storage->put($this->upload_path . $fileName, file_get_contents($avatar->getRealPath())); $this->storage->put($this->upload_path.$fileName, file_get_contents($avatar->getRealPath()));
$input = array_merge($input, ['featured_image' => $fileName]); $input = array_merge($input, ['featured_image' => $fileName]);
...@@ -247,7 +246,7 @@ class BlogsRepository extends BaseRepository ...@@ -247,7 +246,7 @@ class BlogsRepository extends BaseRepository
public function deleteOldFile($model) public function deleteOldFile($model)
{ {
$fileName = $model->featured_image; $fileName = $model->featured_image;
return $this->storage->delete($this->upload_path . $fileName); return $this->storage->delete($this->upload_path.$fileName);
} }
} }
<?php <?php
use App\Models\Access\User\User;
use App\Models\Blogs\Blog; use App\Models\Blogs\Blog;
use Faker\Generator as Faker; use Faker\Generator as Faker;
use App\Models\Access\User\User;
$factory->define(Blog::class, function (Faker $faker) { $factory->define(Blog::class, function (Faker $faker) {
$status = [ $status = [
'Published', 'Published',
'Draft', 'Draft',
'InActive', 'InActive',
'Scheduled' 'Scheduled',
]; ];
return [ return [
'name' => $faker->sentence, 'name' => $faker->sentence,
'publish_datetime' => $faker->dateTime(), 'publish_datetime' => $faker->dateTime(),
'featured_image' => 'logo.png', 'featured_image' => 'logo.png',
'content' => $faker->paragraph(3), 'content' => $faker->paragraph(3),
'status' => $status[$faker->numberBetween(0,3)], 'status' => $status[$faker->numberBetween(0, 3)],
'created_by' => function () { 'created_by' => function () {
return factory(User::class)->create()->id; return factory(User::class)->create()->id;
}, },
]; ];
}); });
...@@ -5,8 +5,8 @@ use Faker\Generator as Faker; ...@@ -5,8 +5,8 @@ use Faker\Generator as Faker;
$factory->define(Faq::class, function (Faker $faker) { $factory->define(Faq::class, function (Faker $faker) {
return [ return [
'question' => rtrim($faker->sentence, '.') . '?', 'question' => rtrim($faker->sentence, '.').'?',
'answer' => $faker->paragraph, 'answer' => $faker->paragraph,
'status' => $faker->numberBetween(0,1) 'status' => $faker->numberBetween(0, 1),
]; ];
}); });
<?php <?php
use App\Models\Access\User\User;
use App\Models\Page\Page; use App\Models\Page\Page;
use Faker\Generator as Faker; use Faker\Generator as Faker;
use App\Models\Access\User\User;
$factory->define(Page::class, function (Faker $faker) { $factory->define(Page::class, function (Faker $faker) {
$title = $faker->sentence; $title = $faker->sentence;
...@@ -11,7 +11,7 @@ $factory->define(Page::class, function (Faker $faker) { ...@@ -11,7 +11,7 @@ $factory->define(Page::class, function (Faker $faker) {
'title' => $title, 'title' => $title,
'page_slug' => str_slug($title), 'page_slug' => str_slug($title),
'description' => $faker->paragraph, 'description' => $faker->paragraph,
'created_by' => function () { 'created_by' => function () {
return factory(User::class)->create()->id; return factory(User::class)->create()->id;
}, },
]; ];
......
...@@ -2,13 +2,11 @@ ...@@ -2,13 +2,11 @@
namespace Tests\Feature\Backend; namespace Tests\Feature\Backend;
use Tests\TestCase;
use App\Models\Blogs\Blog; use App\Models\Blogs\Blog;
use App\Models\BlogTags\BlogTag; use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use App\Models\BlogCategories\BlogCategory; use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
class ManageBlogsTest extends TestCase class ManageBlogsTest extends TestCase
{ {
...@@ -27,7 +25,6 @@ class ManageBlogsTest extends TestCase ...@@ -27,7 +25,6 @@ class ManageBlogsTest extends TestCase
$this->blog = create(Blog::class); $this->blog = create(Blog::class);
$this->categories = [$this->faker->word, $this->faker->word]; $this->categories = [$this->faker->word, $this->faker->word];
$this->tags = [$this->faker->word, $this->faker->word]; $this->tags = [$this->faker->word, $this->faker->word];
} }
/** @test */ /** @test */
...@@ -48,21 +45,21 @@ class ManageBlogsTest extends TestCase ...@@ -48,21 +45,21 @@ class ManageBlogsTest extends TestCase
/** @test */ /** @test */
public function a_user_can_create_a_blog() public function a_user_can_create_a_blog()
{ {
$blog = make(Blog::class, [ $blog = make(Blog::class, [
'featured_image' => UploadedFile::fake()->image('logo.jpg'), 'featured_image' => UploadedFile::fake()->image('logo.jpg'),
'categories' => $this->categories, 'categories' => $this->categories,
'tags' => $this->tags 'tags' => $this->tags,
]); ]);
$this->post(route('admin.blogs.store'), $blog->toArray()); $this->post(route('admin.blogs.store'), $blog->toArray());
$this->assertDatabaseHas(config('module.blogs.table'), ['name' => $blog->name, 'status' => $blog->status]); $this->assertDatabaseHas(config('module.blogs.table'), ['name' => $blog->name, 'status' => $blog->status]);
//Assert Tags have been saved //Assert Tags have been saved
$this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $this->tags[0]]); $this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $this->tags[0]]);
$this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $this->tags[1]]); $this->assertDatabaseHas(config('module.blog_tags.table'), ['name' => $this->tags[1]]);
//Assert Categories have been saved //Assert Categories have been saved
$this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $this->categories[0]]); $this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $this->categories[0]]);
$this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $this->categories[1]]); $this->assertDatabaseHas(config('module.blog_categories.table'), ['name' => $this->categories[1]]);
...@@ -108,7 +105,7 @@ class ManageBlogsTest extends TestCase ...@@ -108,7 +105,7 @@ class ManageBlogsTest extends TestCase
public function it_requires_categories_while_creating() public function it_requires_categories_while_creating()
{ {
$blog = $this->makeBlog(['categories' => '']); $blog = $this->makeBlog(['categories' => '']);
$this->post(route('admin.blogs.store'), $blog->toArray()) $this->post(route('admin.blogs.store'), $blog->toArray())
->assertSessionHasErrors('categories'); ->assertSessionHasErrors('categories');
} }
...@@ -127,15 +124,15 @@ class ManageBlogsTest extends TestCase ...@@ -127,15 +124,15 @@ class ManageBlogsTest extends TestCase
{ {
$blog = make(Blog::class, [ $blog = make(Blog::class, [
'featured_image' => UploadedFile::fake()->image('logo.jpg'), 'featured_image' => UploadedFile::fake()->image('logo.jpg'),
'categories' => $this->categories, 'categories' => $this->categories,
'tags' => $this->tags 'tags' => $this->tags,
]); ]);
$this->post(route('admin.blogs.store'), $blog->toArray()); $this->post(route('admin.blogs.store'), $blog->toArray());
$stored_blog = Blog::find(2); $stored_blog = Blog::find(2);
Storage::disk('public')->assertExists('img/blog/' . $stored_blog->featured_image); Storage::disk('public')->assertExists('img/blog/'.$stored_blog->featured_image);
} }
/** @test */ /** @test */
...@@ -159,7 +156,7 @@ class ManageBlogsTest extends TestCase ...@@ -159,7 +156,7 @@ class ManageBlogsTest extends TestCase
$this->patch(route('admin.blogs.update', $this->blog), $this->blog->toArray()) $this->patch(route('admin.blogs.update', $this->blog), $this->blog->toArray())
->assertSessionHasErrors('content'); ->assertSessionHasErrors('content');
} }
/** @test */ /** @test */
public function it_requires_categories_while_updating() public function it_requires_categories_while_updating()
{ {
...@@ -182,17 +179,17 @@ class ManageBlogsTest extends TestCase ...@@ -182,17 +179,17 @@ class ManageBlogsTest extends TestCase
public function a_user_can_update_blog() public function a_user_can_update_blog()
{ {
$blog = make(Blog::class, [ $blog = make(Blog::class, [
'featured_image' => UploadedFile::fake()->image('logo.jpg'), 'featured_image' => UploadedFile::fake()->image('logo.jpg'),
'name' => 'Changed Name', 'name' => 'Changed Name',
'categories' => $this->categories, 'categories' => $this->categories,
'tags' => $this->tags 'tags' => $this->tags,
]); ]);
$this->patch(route('admin.blogs.update', $this->blog), $blog->toArray()); $this->patch(route('admin.blogs.update', $this->blog), $blog->toArray());
$this->assertDatabaseHas(config('module.blogs.table'), ['id' => $this->blog->id, 'name' => 'Changed Name']); $this->assertDatabaseHas(config('module.blogs.table'), ['id' => $this->blog->id, 'name' => 'Changed Name']);
} }
/** @test */ /** @test */
public function a_user_can_delete_a_blog() public function a_user_can_delete_a_blog()
{ {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
namespace Tests\Feature\Backend; namespace Tests\Feature\Backend;
use Tests\TestCase;
use App\Models\Faqs\Faq; use App\Models\Faqs\Faq;
use Tests\TestCase;
class ManageFaqsTest extends TestCase class ManageFaqsTest extends TestCase
{ {
...@@ -43,7 +43,6 @@ class ManageFaqsTest extends TestCase ...@@ -43,7 +43,6 @@ class ManageFaqsTest extends TestCase
->assertSessionHasErrors('question'); ->assertSessionHasErrors('question');
} }
/** @test */ /** @test */
public function it_requires_answer_while_creating() public function it_requires_answer_while_creating()
{ {
...@@ -82,7 +81,7 @@ class ManageFaqsTest extends TestCase ...@@ -82,7 +81,7 @@ class ManageFaqsTest extends TestCase
{ {
$faq = create(Faq::class); $faq = create(Faq::class);
$changed_question = "What is Life?"; $changed_question = 'What is Life?';
$changed_answer = $faq->answer; $changed_answer = $faq->answer;
$this->actingAs($this->admin) $this->actingAs($this->admin)
->patch(route('admin.faqs.update', $faq), ['question' => $changed_question, 'answer' => $changed_answer]); ->patch(route('admin.faqs.update', $faq), ['question' => $changed_question, 'answer' => $changed_answer]);
...@@ -96,7 +95,7 @@ class ManageFaqsTest extends TestCase ...@@ -96,7 +95,7 @@ class ManageFaqsTest extends TestCase
$faq = create(Faq::class); $faq = create(Faq::class);
$this->actingAs($this->admin) $this->actingAs($this->admin)
->delete(route('admin.faqs.destroy' , $faq)); ->delete(route('admin.faqs.destroy', $faq));
$this->assertDatabaseMissing(config('module.faqs.table'), ['id' => $faq->id, 'deleted_at' => null]); $this->assertDatabaseMissing(config('module.faqs.table'), ['id' => $faq->id, 'deleted_at' => null]);
} }
......
...@@ -2,13 +2,12 @@ ...@@ -2,13 +2,12 @@
namespace Tests\Unit\Models; namespace Tests\Unit\Models;
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\Blogs\Blog;
use App\Models\BlogTags\BlogTag;
use App\Models\Access\User\User; use App\Models\Access\User\User;
use App\Models\BlogCategories\BlogCategory; use App\Models\BlogCategories\BlogCategory;
use Illuminate\Foundation\Testing\WithFaker; use App\Models\Blogs\Blog;
use App\Models\BlogTags\BlogTag;
use Carbon\Carbon;
use Tests\TestCase;
class BlogTest extends TestCase class BlogTest extends TestCase
{ {
...@@ -21,8 +20,8 @@ class BlogTest extends TestCase ...@@ -21,8 +20,8 @@ class BlogTest extends TestCase
$category = create(BlogCategory::class); $category = create(BlogCategory::class);
$blog->categories()->sync(array($category->id)); $blog->categories()->sync([$category->id]);
$this->assertInstanceOf(BlogCategory::class, $blog->categories->first()); $this->assertInstanceOf(BlogCategory::class, $blog->categories->first());
$this->assertEquals($category->id, $blog->categories->first()->id); $this->assertEquals($category->id, $blog->categories->first()->id);
...@@ -37,7 +36,7 @@ class BlogTest extends TestCase ...@@ -37,7 +36,7 @@ class BlogTest extends TestCase
$tag = create(BlogTag::class); $tag = create(BlogTag::class);
$blog->tags()->sync(array($tag->id)); $blog->tags()->sync([$tag->id]);
$this->assertInstanceOf(BlogTag::class, $blog->tags->first()); $this->assertInstanceOf(BlogTag::class, $blog->tags->first());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment