Skip to content

Conversation

@thult-1460
Copy link

Purpose/Notes

Do Home work Ex3->Ex7

Screenshot

image

Checklist (*)

  • Pull request has been self-reviewed
  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All CI builds passed successfully (all builds are green)

@thult-1460 thult-1460 changed the title Do homework [ThuLT][U2]Do homework May 20, 2021
'option_coupon' => $input['option_coupon'],
], $request->rules());

$this->assertTrue($validator->fails());

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);

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',

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');

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);

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());

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;

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)

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()
Copy link

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');
Copy link

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ỉ shouldReceiveandReturn 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()
Copy link

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()
Copy link

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()
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants