Skip to content

Commit 2ac1164

Browse files
committed
update all test to change class based factory call
1 parent 7dc8fe2 commit 2ac1164

13 files changed

+135
-133
lines changed

database/factories/RatingFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RatingFactory extends Factory
2424
public function definition()
2525
{
2626
return [
27-
'title' => $this->faker->words(),
27+
'title' => $this->faker->word,
2828
'description' => $this->faker->paragraph(),
2929
'rating' => $this->faker->numberBetween(1, 5),
3030
'product_id' => Product::factory(),

phpunit.xml

+2
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@
3333
<server name="MAIL_DRIVER" value="array"/>
3434
<server name="QUEUE_CONNECTION" value="sync"/>
3535
<server name="SESSION_DRIVER" value="array"/>
36+
<server name="RAZORPAY_KEY" value="rzp_test_KEEckJG9hEhHFN"/>
37+
<server name="RAZORPAY_PRIVATE" value="uqd7cEmdMpyfTOcY1m3XTDSe"/>
3638
</php>
3739
</phpunit>

tests/Feature/AddProductsTest.php

+22-22
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ class AddProductsTest extends TestCase
1313
use RefreshDatabase;
1414

1515
/**
16-
* @test
17-
*/
16+
* @test
17+
*/
1818
public function guests_may_not_add_products()
1919
{
2020
$this->get(route('products.create'))
21-
->assertRedirect('/admin/login');
21+
->assertRedirect('/admin/login');
2222

2323
$this->post('/admin/products')
24-
->assertRedirect('/admin/login');
24+
->assertRedirect('/admin/login');
2525
}
2626

2727
/**
28-
* @test
29-
*/
28+
* @test
29+
*/
3030
public function an_authenticated_admin_can_add_new_products()
3131
{
32-
$this->actingAs(factory(Admin::class)->create(), 'admin');
32+
$this->actingAs(Admin::factory()->create(), 'admin');
3333

34-
$product = factory(Product::class)->make();
34+
$product = Product::factory()->make();
3535

3636
$productWithImage = array_merge($product->toArray(), ['image' => UploadedFile::fake()->image('avatar.jpg', 200, 350)->size(100)]);
3737

@@ -43,46 +43,46 @@ public function an_authenticated_admin_can_add_new_products()
4343
}
4444

4545
/**
46-
* @test
47-
*/
46+
* @test
47+
*/
4848
public function a_product_requires_a_name()
4949
{
5050
$this->createProduct(['name' => null])
51-
->assertSessionHasErrors('name');
51+
->assertSessionHasErrors('name');
5252
}
5353

5454
/**
55-
* @test
56-
*/
55+
* @test
56+
*/
5757
public function a_product_requires_a_details()
5858
{
5959
$this->createProduct(['details' => null])
60-
->assertSessionHasErrors('details');
60+
->assertSessionHasErrors('details');
6161
}
6262

6363
/**
64-
* @test
65-
*/
64+
* @test
65+
*/
6666
public function a_product_requires_a_price()
6767
{
6868
$this->createProduct(['price' => null])
69-
->assertSessionHasErrors('price');
69+
->assertSessionHasErrors('price');
7070
}
7171

7272
/**
73-
* @test
74-
*/
73+
* @test
74+
*/
7575
public function a_product_requires_a_numeric_price()
7676
{
7777
$this->createProduct(['price' => 'not a num'])
78-
->assertSessionHasErrors('price');
78+
->assertSessionHasErrors('price');
7979
}
8080

8181
public function createProduct($overrides = [])
8282
{
83-
$this->withExceptionHandling()->actingAs(factory(Admin::class)->create(), 'admin');
83+
$this->withExceptionHandling()->actingAs(Admin::factory()->create(), 'admin');
8484

85-
$product = factory(Product::class)->make($overrides);
85+
$product = Product::factory()->make($overrides);
8686

8787
return $this->post('/admin/products', $product->toArray());
8888
}

tests/Feature/Auth/AdminAuthenticationTest.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@
1010

1111
class AdminAuthenticationTest extends TestCase
1212
{
13-
use RefreshDatabase,WithFaker;
13+
use RefreshDatabase, WithFaker;
1414

1515
/**
16-
* @test
17-
*/
16+
* @test
17+
*/
1818
public function user_can_not_access_admin_dashboard()
1919
{
20-
$this->actingAs(factory(User::class)->create());
20+
$this->actingAs(User::factory()->create());
2121

2222
$this->get('/admin')->assertRedirect('/admin/login');
2323
}
2424

2525
/**
26-
* @test
27-
*/
26+
* @test
27+
*/
2828
public function authenticated_admin_can_access_admin_dashboard()
2929
{
30-
$this->actingAs(factory(Admin::class)->create(), 'admin');
30+
$this->actingAs(Admin::factory()->create(), 'admin');
3131

3232
$this->get('/admin')->assertStatus(200);
3333
}
3434

3535
/**
36-
* @test
37-
*/
36+
* @test
37+
*/
3838
public function admin_can_login_with_valid_credentials()
3939
{
40-
$admin = factory(Admin::class)->create();
40+
$admin = Admin::factory()->create();
4141

4242
$this->post('/admin/login', [
4343
'email' => $admin->email,
@@ -46,8 +46,8 @@ public function admin_can_login_with_valid_credentials()
4646
}
4747

4848
/**
49-
* @test
50-
*/
49+
* @test
50+
*/
5151
public function admin_can_not_login_with_invalid_credentials()
5252
{
5353
$response = $this->json('POST', 'admin/login', [
@@ -60,13 +60,13 @@ public function admin_can_not_login_with_invalid_credentials()
6060
}
6161

6262
/**
63-
* @test
64-
* @dataProvider clientFormValidationProvider
65-
*/
63+
* @test
64+
* @dataProvider clientFormValidationProvider
65+
*/
6666
public function required_inputs_are_required_to_login($formInput, $formInputValue)
6767
{
6868
$this->post('admin/login', [$formInput => $formInputValue])
69-
->assertSessionHasErrors($formInput);
69+
->assertSessionHasErrors($formInput);
7070

7171
$response = $this->json('POST', 'admin/login', [
7272
$formInput => $formInputValue,

tests/Feature/CartMangementTest.php

+23-23
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class CartMangementTest extends TestCase
1313
use RefreshDatabase;
1414

1515
/**
16-
* @test
17-
*/
16+
* @test
17+
*/
1818
public function user_can_add_products_to_cart()
1919
{
20-
$this->actingAs(factory(User::class)->create());
21-
$product = factory(Product::class)->create();
20+
$this->actingAs(User::factory()->create());
21+
$product = Product::factory()->create();
2222

2323
$this->post('/cart/' . $product->slug);
2424

@@ -27,12 +27,12 @@ public function user_can_add_products_to_cart()
2727
}
2828

2929
/**
30-
* @test
31-
*/
30+
* @test
31+
*/
3232
public function item_does_not_added_to_cart_if_stock_is_not_available()
3333
{
34-
$this->actingAs(factory(User::class)->create());
35-
$product = factory(Product::class)->create(['quantity' => 0]);
34+
$this->actingAs(User::factory()->create());
35+
$product = Product::factory()->create(['quantity' => 0]);
3636

3737
$this->assertCount(0, Cart::content());
3838

@@ -42,11 +42,11 @@ public function item_does_not_added_to_cart_if_stock_is_not_available()
4242
}
4343

4444
/**
45-
* @test
46-
*/
45+
* @test
46+
*/
4747
public function message_is_flashed_if_dupliactes_is_added()
4848
{
49-
$product = factory(Product::class)->create();
49+
$product = Product::factory()->create();
5050

5151
$this->post('/cart/' . $product->slug);
5252

@@ -58,12 +58,12 @@ public function message_is_flashed_if_dupliactes_is_added()
5858
}
5959

6060
/**
61-
* @test
62-
*/
61+
* @test
62+
*/
6363
public function cart_items_quantity_could_be_updated()
6464
{
65-
$this->actingAs(factory(User::class)->create());
66-
$product = factory(Product::class)->create();
65+
$this->actingAs(User::factory()->create());
66+
$product = Product::factory()->create();
6767

6868
$this->post('/cart/' . $product->slug);
6969
$this->assertEquals(1, Cart::content()->first()->qty);
@@ -73,12 +73,12 @@ public function cart_items_quantity_could_be_updated()
7373
}
7474

7575
/**
76-
* @test
77-
*/
76+
* @test
77+
*/
7878
public function it_requires_numeric_quantity_to_update_cart()
7979
{
80-
$this->actingAs(factory(User::class)->create());
81-
$product = factory(Product::class)->create();
80+
$this->actingAs(User::factory()->create());
81+
$product = Product::factory()->create();
8282

8383
$this->post('/cart/' . $product->slug);
8484
$this->assertEquals(1, Cart::content()->first()->qty);
@@ -89,12 +89,12 @@ public function it_requires_numeric_quantity_to_update_cart()
8989
}
9090

9191
/**
92-
* @test
93-
*/
92+
* @test
93+
*/
9494
public function user_can_remove_product_from_cart()
9595
{
96-
$this->actingAs(factory(User::class)->create());
97-
$product = factory(Product::class)->create();
96+
$this->actingAs(User::factory()->create());
97+
$product = Product::factory()->create();
9898

9999
$this->post('/cart/' . $product->slug);
100100
$this->assertCount(1, Cart::content());

tests/Feature/CategoriesTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010

1111
class CategoriesTest extends TestCase
1212
{
13-
use RefreshDatabase,WithFaker;
13+
use RefreshDatabase, WithFaker;
1414

1515
/**
16-
* @test
17-
*/
16+
* @test
17+
*/
1818
public function admin_can_add_new_category()
1919
{
20-
$this->actingAs(factory(Admin::class)->create(),'admin');
20+
$this->actingAs(Admin::factory()->create(), 'admin');
2121
$this->post(route('admin.categories.store'), [
2222
'name' => 'laptops'
2323
]);
24-
24+
2525
// Check for no duplicates
2626
$this->post(route('admin.categories.store'), [
2727
'name' => 'Laptops'

tests/Feature/CheckoutTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class CheckoutTest extends TestCase
1313
use RefreshDatabase;
1414

1515
/**
16-
* @test
17-
*/
16+
* @test
17+
*/
1818
public function authenticated_user_can_checkout()
1919
{
20-
$this->actingAs(factory(User::class)->create());
20+
$this->actingAs(User::factory()->create());
2121

22-
$product = factory(Product::class)->create();
22+
$product = Product::factory()->create();
2323

2424
$this->post("/cart/$product->slug");
2525

@@ -32,8 +32,8 @@ public function authenticated_user_can_checkout()
3232
}
3333

3434
/**
35-
* @test
36-
*/
35+
* @test
36+
*/
3737
public function unauthenticated_user_can_not_checkout()
3838
{
3939
$this->get('/checkout')->assertRedirect('/login');

tests/Feature/ProductViewTest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ class ProductViewTest extends TestCase
1111
use RefreshDatabase;
1212

1313
/**
14-
* @test
15-
*/
14+
* @test
15+
*/
1616
public function a_user_can_view_product()
1717
{
18-
$product = factory(Product::class)->create();
18+
$product = Product::factory()->create();
1919

2020
$this->get(route('products.view', $product))
21-
->assertSee($product->name)
22-
->assertSee($product->details)
23-
->assertSee($product->price);
21+
->assertSee($product->name)
22+
->assertSee($product->details)
23+
->assertSee($product->price);
2424
}
2525
}

0 commit comments

Comments
 (0)