[ThuLT][U2]Do homework - #22
Conversation
eb1e2f3 to
bc2ce0f
Compare
| 'option_coupon' => $input['option_coupon'], | ||
| ], $request->rules()); | ||
|
|
||
| $this->assertTrue($validator->fails()); |
There was a problem hiding this comment.
Nếu được e nên break ra cụ thể hơn xem fail vì sao , do sai trường nào e nhé
Chứ để thế này chung chung quá
| { | ||
| $result = $this->service->handleDiscount($detailOrder); | ||
|
|
||
| $this->assertEquals($discount, $result); |
There was a problem hiding this comment.
Viết kiểu dataProvider cũng hay nhưng a nghĩ Unitest bản chất nó là tài liệu của dev, mình viết ngắn gọn thế này thì không nêu rõ ra được xem nó đang ra case nào , và người sau vào đọc sẽ khá mệt
chưa kể bản thân mình sau đọc lại cũng thấy rất khó hiểu e nhé
| ], | ||
| [ | ||
| 'price' => 1000, | ||
| 'discount_pizza' => 'Khuyến mại pizza thứ 2', |
There was a problem hiding this comment.
những cái nào có trong config thì nên dùng trong config e nhé
| 'case2', | ||
| 'freeTimeForMovie' | ||
| ]); | ||
| $response->assertSessionMissing('order'); |
| $this->calculateMock | ||
| ->shouldReceive('calculate') | ||
| ->with($input['bill'], $input['has_watch']) | ||
| ->andReturn(240); |
There was a problem hiding this comment.
240 nên đưa vào 1 biến nào đó e nhé
vì còn sử dụng bên dưới nữa
| 'has_watch' => $input['has_watch'], | ||
| ], $request->rules()); | ||
|
|
||
| $this->assertTrue($validator->fails()); |
|
|
||
| class CheckoutServiceTest extends TestCase | ||
| { | ||
| protected $calendarServiceMock; |
| /** | ||
| * @dataProvider provider_test_calculate_shipping_fee | ||
| */ | ||
| public function test_calculate($input, $order) |
| $this->assertEquals($result, $discount); | ||
| } | ||
|
|
||
| public function provider_test_alculate_discount() |
There was a problem hiding this comment.
Ở đây chị thiếu miss mất 1 case.
Giả sử các trường hợp dưới đây không tồn tại thì ra sao?
$totalProducts[Product::CRAVAT_TYPE]
$totalProducts[Product::OTHER_TYPE]
$totalProducts[Product::WHITE_SHIRT_TYPE]
| { | ||
| $url = action([CalendarController::class, 'index']); | ||
|
|
||
| $this->calendarServiceMock->shouldReceive('getDateClass')->andReturn('text-dark'); |
There was a problem hiding this comment.
Đoạn mock này mình không nên chỉ shouldReceive và andReturn luôn.
Mình nên làm để biết thêm là cái method getDateClass gọi bao nhiêu lần và những tham số truyền vào là gì
| $this->assertEquals($discount, $result); | ||
| } | ||
|
|
||
| public function provider_test_handle_discount() |
There was a problem hiding this comment.
Trong provider này nên thêm có 1 case nữa check độ chính xác tới 2 chữ số thập phân vì cái round nó có thêm tham số thứ 2 là 2
$infoBill['price'] = round(($detailOrder['price'] * 80) / 100, 2);
Cái này nice to have 😄
| $this->assertEquals($time, $result); | ||
| } | ||
|
|
||
| public function provider_test_calculate() |
There was a problem hiding this comment.
Ở đây sẽ có 1 case, là giả sử không truyền vào has_watch thì kết quả sẽ ra sao.
Tất nhiên là không truyền vào has_watch thì default nó là false thì nó sẽ trùng 1 trong các số test của mình. Nhưng về cơ bản thì vẫn phải có case là không truyền vào cái gì cả
| $this->assertEquals($order['shipping_fee'], $result['shipping_fee']); | ||
| } | ||
|
|
||
| public function provider_test_calculate_shipping_fee() |
There was a problem hiding this comment.
Ở đây phải quan tâm tới case là
$order['amount'] == Checkout::FREE_SHIPPING_AMOUNT thì có lấy $shippingFee = 0 hay không nữa
Purpose/Notes
Do Home work Ex3->Ex7
Screenshot
Checklist (*)