Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Sherlockboy/laravel-unit-testing

Repository files navigation

PHPUnit example

Task description

You have products database:

Product code Name Price
FR1 Fruit Tea 3ドル.11
SR1 Strawberries 5ドル.00
CF1 Coffee 11ドル.23
  1. CEO wants that if you buy at least one tea, next should be free.
  2. CTO wants low prices, so that, if you buy 3 or more strawberries price should drop to 4ドル.50.

Your code should be flexible, because CTO and CEO often changes the rules.

The service should look like this:

$ch = new Checkout($pricing_rules);
$co->scan($item1);
$co->scan($item2);
$price = $ch->total();

Implement a checkout system that fulfils these requirements.

Test data

Basket: FR1,SR1,FR1,FR1,CF1
Total price expected: 22ドル.45

Basket: FR1,FR1
Total price expected: 3ドル.11

Basket: SR1,SR1,FR1,SR1
Total price expected: 16ドル.61

About

Unit Testing, Exception Handling example in Laravel

Topics

Resources

Stars

Watchers

Forks

AltStyle によって変換されたページ (->オリジナル) /