-
Notifications
You must be signed in to change notification settings - Fork 59
[ThuLT][U2]Do homework #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| 'option_coupon' => $input['option_coupon'], | ||
| ], $request->rules()); | ||
|
|
||
| $this->assertTrue($validator->fails()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
những cái nào có trong config thì nên dùng trong config e nhé
| 'case2', | ||
| 'freeTimeForMovie' | ||
| ]); | ||
| $response->assertSessionMissing('order'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cái này để test cho phần nào e nhỉ
| $this->calculateMock | ||
| ->shouldReceive('calculate') | ||
| ->with($input['bill'], $input['has_watch']) | ||
| ->andReturn(240); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tương tự bài 5 e nhé
|
|
||
| class CheckoutServiceTest extends TestCase | ||
| { | ||
| protected $calendarServiceMock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cái này dùng làm gì đây e
| /** | ||
| * @dataProvider provider_test_calculate_shipping_fee | ||
| */ | ||
| public function test_calculate($input, $order) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tương tự bài 5
| $this->assertEquals($result, $discount); | ||
| } | ||
|
|
||
| public function provider_test_alculate_discount() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ở đâ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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Đ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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ở đâ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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ở đâ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 (*)