diff --git a/.DS_Store b/.DS_Store index c3e5a9a..ecbfb07 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index e69de29..b229569 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,82 @@ +# Calculator + +เว็บแอปพลิเคชันเพื่อแสดงตัวอย่างการเขียนกรณีทดสอบ โดยใช้ `Laravel 5.4` และ `PHPUnit` เพื่อการทดสอบ + +## ความต้องการเบื้องต้น +| รายการซอฟต์แวร์ | รุ่นขั้นต่ำ | รุ่นที่แนะนำ | รุ่นที่ใช้พัฒนา | +|---------------|:------:|:--------:|:---------:| +| PHP | >=5.7 | 5.7 | 7 | +| composer | 1.4.2 | 1.4.2 | 1.4.2 | +| phpunit | 5.7 | 5.7 | 6.2.2 | + +## ขั้นตอนการทดสอบ + +1. ดาวน์โหลด `we-inc/calculator` ด้วยคำสั่ง + ```bash + git clone https://github.com/we-inc/calculator + ``` + +1. อัพเดต lib ด้วยคำสั่ง `composer` + ```bash + cd calculator && \ + composer update + ``` + +1. กรณีทดสอบจะอยู่อยู่ภายในโฟลเดอร์ + ``` + + tests + + Features + | + AddControllerTest.php + | + MinusControllerTest.php + + Unit + ``` + +1. สร้างกรณีทดสอบโดยใช้คำสั่งด้านล่าง โดยคำสั่งนี้จะสร้างคลาสซึ่งเป็น Unit Test ชื่อ `SomeTestCaseTest` (โดยที่กรณีทดสอบนั้นต้องลงท้ายชื่อด้วย `Test`) + ```bash + php artisan make:test SomeTestCaseTest + ``` + เพื่อสร้างกรณีทดสอบสำหรับหน้าที่การใช้งานตัวไป และ + + ```bash + php artisan make:test SomeControllerTest --unit + ``` + สำหรับกรณีทดสอบสำหรับคลาสใดคลาสหนึ่ง + +1. ภายในคลาส `SomeTestCaseTest` ที่สร้างขึ้นมานั้น จะมีซอร์สโค้ดดังตัวอย่างด้านล่าง + ```php + assertTrue(true); + } + } + ``` + ด้านในจะปรากฏเมธอด `testExample()` ซึ่งเมธอดที่มีชื่อขึ้นต้นด้วย `test` นั้นจะบรรจุกรณีทดสอบ ซึ่งจะนำมาใช้ทดสอบคุณสมบัติต่าง ๆ ของซอฟต์แวร์ตามที่ต้องการ + +1. ทดสอบซอฟต์แวร์ด้วยกรณีทดสอบที่สร้างขึ้นด้วยคำสั่ง `phpunit` ณ โฟลเดอร์ชั้นบนสุดของโปรเจค + ```php + phpunit + ``` + + เมื่อผลการทดสอบเสร็จสิ้น จะมีผลลัพธ์การดำเนินการแสดงให้ทราบ + +## ข้อมูลเพิ่มเติม + +ข้อมูลเพิ่มเติมสำหรับกรณีทดสอบ +- [Laravel: Getting Started](https://laravel.com/docs/master/testing) +- [Illuminate: TestCase API](https://laravel.com/api/master/Illuminate/Foundation/Testing/TestCase.html) diff --git a/app/.DS_Store b/app/.DS_Store index eea122a..d770ce8 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/Http/.DS_Store b/app/Http/.DS_Store index fc608b1..7aa839d 100644 Binary files a/app/Http/.DS_Store and b/app/Http/.DS_Store differ diff --git a/app/Http/Controllers/AddController.php b/app/Http/Controllers/AddController.php deleted file mode 100644 index 098e1e7..0000000 --- a/app/Http/Controllers/AddController.php +++ /dev/null @@ -1,28 +0,0 @@ - $new, 'route' => $route)); - } - -} diff --git a/app/Http/Controllers/DivideController.php b/app/Http/Controllers/DivideController.php deleted file mode 100644 index 75ee54d..0000000 --- a/app/Http/Controllers/DivideController.php +++ /dev/null @@ -1,28 +0,0 @@ - $new, 'route' => $route)); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/InputController.php b/app/Http/Controllers/InputController.php new file mode 100644 index 0000000..dddf9a1 --- /dev/null +++ b/app/Http/Controllers/InputController.php @@ -0,0 +1,89 @@ +calculate(Input::get('num1'),Input::get('num2')); + } + else{ + $answer = "Numbers are required"; + } + } + + return view('add', array('answer' => $answer)); + } + + public function minus(){ + + $minus = new Minus(); + + $answer = null; + if(Input::has('num1') && Input::has('num2')){ + if(is_numeric(Input::get('num1')) && is_numeric(Input::get('num2'))){ + $answer = $minus->calculate(Input::get('num1'),Input::get('num2')); + } + else{ + $answer = "Numbers are required"; + } + } + + return view('minus', array('answer' => $answer)); + } + + public function multiply(){ + + $multiply = new Multiply(); + + $answer = null; + if(Input::has('num1') && Input::has('num2')){ + if(is_numeric(Input::get('num1')) && is_numeric(Input::get('num2'))){ + $answer = $multiply->calculate(Input::get('num1'),Input::get('num2')); + } + else{ + $answer = "Numbers are required"; + } + } + + return view('multiply', array('answer' => $answer)); + } + + public function divide(){ + + $divide = new Divide(); + + $answer = null; + if(Input::has('num1') && Input::has('num2')){ + if(is_numeric(Input::get('num1')) && is_numeric(Input::get('num2'))){ + if(Input::get('num2') != 0) + $answer = $divide->calculate(Input::get('num1'),Input::get('num2')); + else + $answer = "Cannot divided by zero"; + } + else{ + $answer = "Numbers are required"; + } + } + + return view('divide', array('answer' => $answer)); + } + +} + + +?> \ No newline at end of file diff --git a/app/Http/Controllers/MinusController.php b/app/Http/Controllers/MinusController.php deleted file mode 100644 index e4e93de..0000000 --- a/app/Http/Controllers/MinusController.php +++ /dev/null @@ -1,28 +0,0 @@ - $new, 'route' => $route)); - } - -} \ No newline at end of file diff --git a/app/Http/Controllers/MultiplyController.php b/app/Http/Controllers/MultiplyController.php deleted file mode 100644 index 29928ff..0000000 --- a/app/Http/Controllers/MultiplyController.php +++ /dev/null @@ -1,28 +0,0 @@ - $new, 'route' => $route)); - } - -} \ No newline at end of file diff --git a/app/Module/Add.php b/app/Module/Add.php new file mode 100644 index 0000000..14eaaff --- /dev/null +++ b/app/Module/Add.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/app/Module/Divide.php b/app/Module/Divide.php new file mode 100644 index 0000000..37acc61 --- /dev/null +++ b/app/Module/Divide.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/app/Module/Minus.php b/app/Module/Minus.php new file mode 100644 index 0000000..8cd2b55 --- /dev/null +++ b/app/Module/Minus.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/app/Module/Multiply.php b/app/Module/Multiply.php new file mode 100644 index 0000000..97bcc11 --- /dev/null +++ b/app/Module/Multiply.php @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/composer.lock b/composer.lock index 91e43c9..09fac84 100644 --- a/composer.lock +++ b/composer.lock @@ -237,16 +237,16 @@ }, { "name": "laravel/framework", - "version": "v5.4.31", + "version": "v5.4.32", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "fc1afa6b981cadbe3be8be65b49ca82e3eb9b9c9" + "reference": "b8300578d159199b1195413b67318c79068cd24d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/fc1afa6b981cadbe3be8be65b49ca82e3eb9b9c9", - "reference": "fc1afa6b981cadbe3be8be65b49ca82e3eb9b9c9", + "url": "https://api.github.com/repos/laravel/framework/zipball/b8300578d159199b1195413b67318c79068cd24d", + "reference": "b8300578d159199b1195413b67318c79068cd24d", "shasum": "" }, "require": { @@ -362,7 +362,7 @@ "framework", "laravel" ], - "time": "2017-08-02T15:24:31+00:00" + "time": "2017-08-03T12:59:42+00:00" }, { "name": "laravel/tinker", @@ -483,16 +483,16 @@ }, { "name": "league/flysystem", - "version": "1.0.40", + "version": "1.0.41", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "3828f0b24e2c1918bb362d57a53205d6dc8fde61" + "reference": "f400aa98912c561ba625ea4065031b7a41e5a155" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/3828f0b24e2c1918bb362d57a53205d6dc8fde61", - "reference": "3828f0b24e2c1918bb362d57a53205d6dc8fde61", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/f400aa98912c561ba625ea4065031b7a41e5a155", + "reference": "f400aa98912c561ba625ea4065031b7a41e5a155", "shasum": "" }, "require": { @@ -513,13 +513,13 @@ "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3", "league/flysystem-azure": "Allows you to use Windows Azure Blob storage", "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching", - "league/flysystem-copy": "Allows you to use Copy.com storage", "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem", "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files", "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib", "league/flysystem-webdav": "Allows you to use WebDAV storage", "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter", - "spatie/flysystem-dropbox": "Allows you to use Dropbox storage" + "spatie/flysystem-dropbox": "Allows you to use Dropbox storage", + "srmklive/flysystem-dropbox-v2": "Allows you to use Dropbox storage for PHP 5 applications" }, "type": "library", "extra": { @@ -562,7 +562,7 @@ "sftp", "storage" ], - "time": "2017-04-28T10:15:08+00:00" + "time": "2017-08-06T17:41:04+00:00" }, { "name": "monolog/monolog", @@ -960,16 +960,16 @@ }, { "name": "ramsey/uuid", - "version": "3.6.1", + "version": "3.7.0", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "4ae32dd9ab8860a4bbd750ad269cba7f06f7934e" + "reference": "0ef23d1b10cf1bc576e9d865a7e9c47982c5715e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/4ae32dd9ab8860a4bbd750ad269cba7f06f7934e", - "reference": "4ae32dd9ab8860a4bbd750ad269cba7f06f7934e", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/0ef23d1b10cf1bc576e9d865a7e9c47982c5715e", + "reference": "0ef23d1b10cf1bc576e9d865a7e9c47982c5715e", "shasum": "" }, "require": { @@ -1038,7 +1038,7 @@ "identifier", "uuid" ], - "time": "2017-03-26T20:37:53+00:00" + "time": "2017-08-04T13:39:04+00:00" }, { "name": "swiftmailer/swiftmailer", @@ -2251,22 +2251,22 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "3.2.0", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "46f7e8bb075036c92695b15a1ddb6971c751e585" + "reference": "183824db76118b9dddffc7e522b91fa175f75119" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/46f7e8bb075036c92695b15a1ddb6971c751e585", - "reference": "46f7e8bb075036c92695b15a1ddb6971c751e585", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/183824db76118b9dddffc7e522b91fa175f75119", + "reference": "183824db76118b9dddffc7e522b91fa175f75119", "shasum": "" }, "require": { "php": ">=5.5", "phpdocumentor/reflection-common": "^1.0@dev", - "phpdocumentor/type-resolver": "^0.4.0", + "phpdocumentor/type-resolver": "^0.3.0", "webmozart/assert": "^1.0" }, "require-dev": { @@ -2292,20 +2292,20 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-07-15T11:38:20+00:00" + "time": "2017-08-04T20:55:59+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "0.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/fb3933512008d8162b3cdf9e18dba9309b7c3773", + "reference": "fb3933512008d8162b3cdf9e18dba9309b7c3773", "shasum": "" }, "require": { @@ -2339,7 +2339,7 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "time": "2017-06-03T08:32:36+00:00" }, { "name": "phpspec/prophecy", diff --git a/public/asset/equal-symbol.png b/public/asset/equal-symbol.png new file mode 100644 index 0000000..47125af Binary files /dev/null and b/public/asset/equal-symbol.png differ diff --git a/resources/views/add.blade.php b/resources/views/add.blade.php index a08cb7d..cd3a1eb 100644 --- a/resources/views/add.blade.php +++ b/resources/views/add.blade.php @@ -75,14 +75,10 @@
Add (บวก)
- {{ Form::open(array('action'=> 'AddController@calculate','method'=> 'POST')) }} + {{ Form::open(array('action'=> 'InputController@add','method'=> 'POST')) }}
- @if ($ans !== null) - - @else - @endif

+

@@ -91,27 +87,20 @@
- +
- {{ Form::close() }}
-
- + -
-
- - -
-
- x -
-
- / +
+

{{ $answer }}

- +
+
diff --git a/resources/views/divide.blade.php b/resources/views/divide.blade.php index 4168f66..ee6f69e 100644 --- a/resources/views/divide.blade.php +++ b/resources/views/divide.blade.php @@ -75,14 +75,10 @@
Divide (หาร)
- {{ Form::open(array('action'=> 'DivideController@calculate','method'=> 'POST')) }} + {{ Form::open(array('action'=> 'InputController@divide','method'=> 'POST')) }}
- @if ($ans !== null) - - @else - @endif

/

@@ -91,27 +87,20 @@
- +
- {{ Form::close() }}
-
- + -
-
- - -
-
- x -
-
- / +
+

{{ $answer }}

- +
+
diff --git a/resources/views/minus.blade.php b/resources/views/minus.blade.php index ca56703..7f93edf 100644 --- a/resources/views/minus.blade.php +++ b/resources/views/minus.blade.php @@ -75,14 +75,10 @@
Minus (ลบ)
- {{ Form::open(array('action'=> 'MinusController@calculate','method'=> 'POST')) }} + {{ Form::open(array('action'=> 'InputController@minus','method'=> 'POST')) }}
- @if ($ans !== null) - - @else - @endif

-

@@ -91,27 +87,20 @@
- +
-
- {{ Form::close() }} +
-
- + -
-
- - -
-
- x -
-
- / +
+

{{ $answer }}

- +
+
diff --git a/resources/views/multiply.blade.php b/resources/views/multiply.blade.php index 202b06d..ce6dfab 100644 --- a/resources/views/multiply.blade.php +++ b/resources/views/multiply.blade.php @@ -75,14 +75,10 @@
Multiply (คูณ)
- {{ Form::open(array('action'=> 'MultiplyController@calculate','method'=> 'POST')) }} + {{ Form::open(array('action'=> 'InputController@multiply','method'=> 'POST')) }}
- @if ($ans !== null) - - @else - @endif

x

@@ -91,27 +87,20 @@
- +
- {{ Form::close() }}
-
- + -
-
- - -
-
- x -
-
- / +
+

{{ $answer }}

- +
+
diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 369d0f1..eadda77 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -83,12 +83,10 @@ diff --git a/routes/web.php b/routes/web.php index 9824d8f..ce6902f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,12 +13,12 @@ Route::get('/', function () { return view('welcome'); -}); +})->name('home'); -Route::match(['get','post'],'add/{ans?}','AddController@calculate')->name('add'); +Route::match(['get','post'],'add','InputController@add')->name('add'); -Route::match(['get','post'],'minus/{ans?}','MinusController@calculate')->name('minus'); +Route::match(['get','post'],'minus','InputController@minus')->name('minus'); -Route::match(['get','post'],'multiply/{ans?}','MultiplyController@calculate')->name('multiply'); +Route::match(['get','post'],'multiply','InputController@multiply')->name('multiply'); -Route::match(['get','post'],'divide/{ans?}','DivideController@calculate')->name('divide'); \ No newline at end of file +Route::match(['get','post'],'divide','InputController@divide')->name('divide'); \ No newline at end of file diff --git a/tests/Feature/AddControllerTest.php b/tests/Feature/AddControllerTest.php new file mode 100644 index 0000000..dcf0912 --- /dev/null +++ b/tests/Feature/AddControllerTest.php @@ -0,0 +1,92 @@ +get('/add'); + + $response->assertStatus(200) + ->assertSee('Add (บวก)') + ; + } + + public function testAnswerShouldDisplay() + { + $response = $this->post('/add', ['num1' => 1, 'num2' => 2]); + + $response->assertStatus(200) + ->assertSee('3') + ; + } + + public function testAnswerShouldReceiveFormAnotherView() + { + $response = $this->post('/add', ['num1' => 5, 'num2' => 0]); + + $response->assertStatus(200) + ->assertSee('5') + ; + } + + public function testCharacterShouldDisplayWarningMessage() + { + $response = $this->post('/add', ['num1' => 4, 'num2' => 'a']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/add', ['num1' => 'a', 'num2' => 'b']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + } + + public function testFloatShouldBeAdded() + { + $response = $this->post('/add', ['num1' => 3.2, 'num2' => 1.8]); + + $response->assertStatus(200) + ->assertSee('5') + ; + + $response = $this->post('/add', ['num1' => 3, 'num2' => 1.0]); + $response->assertStatus(200) + ->assertSee('4') + ; + + $response = $this->post('/add', ['num1' => 3.0, 'num2' => 1]); + $response->assertStatus(200) + ->assertSee('4') + ; + + $response = $this->post('/add', ['num1' => 0.0, 'num2' => 0.0]); + $response->assertStatus(200) + ->assertSee('0') + ; + } + + public function testNegativeShouldBeAdd() + { + $response = $this->post('/add', ['num1' => 1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee('0') + ; + + $response = $this->post('/add', ['num1' => 1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee('0') + ; + } + +} diff --git a/tests/Feature/DivideControllerTest.php b/tests/Feature/DivideControllerTest.php new file mode 100644 index 0000000..b10da5e --- /dev/null +++ b/tests/Feature/DivideControllerTest.php @@ -0,0 +1,97 @@ +get('/divide'); + + $response->assertStatus(200) + ->assertSee('Divide (หาร)') + ; + } + + public function testAnswerShouldDisplay() + { + $response = $this->post('/divide', ['num1' => 1, 'num2' => 2]); + + $response->assertStatus(200) + ->assertSee('0.5') + ; + } + + public function testAnswerShouldReceiveFormAnotherView() + { + $response = $this->post('/divide', ['num1' => 5, 'num2' => 5]); + + $response->assertStatus(200) + ->assertSee('1') + ; + } + + public function testCharacterShouldDisplayWarningMessage() + { + $response = $this->post('/divide', ['num1' => 4, 'num2' => 'a']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/divide', ['num1' => 'a', 'num2' => 'b']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + } + + public function testFloatShouldBeDivided() + { + $response = $this->post('/divide', ['num1' => 3, 'num2' => 1.5]); + + $response->assertStatus(200) + ->assertSee('2') + ; + + $response = $this->post('/divide', ['num1' => 1, 'num2' => 0.5]); + $response->assertStatus(200) + ->assertSee('2') + ; + + $response = $this->post('/divide', ['num1' => 3.0, 'num2' => 2]); + $response->assertStatus(200) + ->assertSee('1.5') + ; + + $response = $this->post('/divide', ['num1' => 10, 'num2' => 2.5]); + $response->assertStatus(200) + ->assertSee('4') + ; + } + + public function testNegativeShouldBeDivided() + { + $response = $this->post('/divide', ['num1' => -1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee('1') + ; + + $response = $this->post('/divide', ['num1' => 2, 'num2' => -4]); + $response->assertStatus(200) + ->assertSee('-0.5') + ; + } + + public function testZeroShouldNotBeDivider(){ + $response = $this->post('/divide', ['num1' => 40, 'num2' => 0]); + $response->assertStatus(200) + ->assertSee('Cannot divided by zero') + ; + } +} diff --git a/tests/Feature/MinusControllerTest.php b/tests/Feature/MinusControllerTest.php new file mode 100644 index 0000000..e9aa978 --- /dev/null +++ b/tests/Feature/MinusControllerTest.php @@ -0,0 +1,99 @@ +get('/minus'); + + $response->assertStatus(200) + ->assertSee('Minus (ลบ)') + ; + + } + + public function testMinusAnswerShouldDisplay() + { + $response = $this->post('/minus', ['num1' => 1, 'num2' => 1]); + + $response->assertStatus(200) + ->assertSee('0') + ; + } + + public function testAnswerShouldReceiveFormAnotherView() + { + $response = $this->post('/minus', ['num1' => 0, 'num2' => 0]); + + $response->assertStatus(200) + ->assertSee('0') + ; + } + + public function testCharacterShouldDisplayWarningMessage() + { + $response = $this->post('/minus', ['num1' => 1, 'num2' => 'a']); + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/minus', ['num1' => 'a', 'num2' => 1]); + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/minus', ['num1' => 'a', 'num2' => 'b']); + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + } + + public function testFloatShouldBeMinus() + { + $response = $this->post('/minus', ['num1' => 3.2, 'num2' => 1.2]); + $response->assertStatus(200) + ->assertSee('2') + ; + + $response = $this->post('/minus', ['num1' => 3, 'num2' => 1.0]); + $response->assertStatus(200) + ->assertSee('2') + ; + + $response = $this->post('/minus', ['num1' => 3.0, 'num2' => 1]); + $response->assertStatus(200) + ->assertSee('2') + ; + + $response = $this->post('/minus', ['num1' => 0.0, 'num2' => 0.0]); + $response->assertStatus(200) + ->assertSee('0') + ; + } + + public function testNegativeShouldBeMinus() + { + $response = $this->post('/minus', ['num1' => 1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee('2') + ; + + $response = $this->post('/minus', ['num1' => -1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee('0') + ; + + $response = $this->post('/minus', ['num1' => -1, 'num2' => 2]); + $response->assertStatus(200) + ->assertSee('-3') + ; + } +} diff --git a/tests/Feature/MultiplyControllerTest.php b/tests/Feature/MultiplyControllerTest.php new file mode 100644 index 0000000..a953d0a --- /dev/null +++ b/tests/Feature/MultiplyControllerTest.php @@ -0,0 +1,90 @@ +get('/multiply'); + + $response->assertStatus(200) + ->assertSee('Multiply (คูณ)') + ; + } + + public function testAnswerShouldDisplay() + { + $response = $this->post('/multiply', ['num1' => 1, 'num2' => 2]); + + $response->assertStatus(200) + ->assertSee('2') + ; + } + + public function testAnswerShouldReceiveFormAnotherView() + { + $response = $this->post('/multiply', ['num1' => 5, 'num2' => 0]); + + $response->assertStatus(200) + ->assertSee('0') + ; + } + + public function testCharacterShouldDisplayWarningMessage() + { + $response = $this->post('/multiply', ['num1' => 4, 'num2' => 'a']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + + $response = $this->post('/multiply', ['num1' => 'a', 'num2' => 'b']); + + $response->assertStatus(200) + ->assertSee('Numbers are required') + ; + } + + public function testFloatShouldBeMultiplied() + { + $response = $this->post('/multiply', ['num1' => 2.0, 'num2' => 2.2]); + + $response->assertStatus(200) + ->assertSee('4.4') + ; + + $response = $this->post('/multiply', ['num1' => 3, 'num2' => 1.0]); + $response->assertStatus(200) + ->assertSee('3') + ; + + $response = $this->post('/multiply', ['num1' => 3.0, 'num2' => 2]); + $response->assertStatus(200) + ->assertSee('6') + ; + + $response = $this->post('/multiply', ['num1' => 1.5, 'num2' => 10]); + $response->assertStatus(200) + ->assertSee('15') + ; + } + + public function testNegativeShouldBeMultiplied() + { + $response = $this->post('/multiply', ['num1' => -1, 'num2' => -1]); + $response->assertStatus(200) + ->assertSee('1') + ; + + $response = $this->post('/multiply', ['num1' => 2, 'num2' => -4]); + $response->assertStatus(200) + ->assertSee('-8') + ; + } +} diff --git a/tests/Feature/SomeTestCaseTest.php b/tests/Feature/SomeTestCaseTest.php new file mode 100644 index 0000000..2eb34f1 --- /dev/null +++ b/tests/Feature/SomeTestCaseTest.php @@ -0,0 +1,21 @@ +assertTrue(true); + } +} diff --git a/tests/Unit/SomeControllerTest.php b/tests/Unit/SomeControllerTest.php new file mode 100644 index 0000000..29d3af4 --- /dev/null +++ b/tests/Unit/SomeControllerTest.php @@ -0,0 +1,20 @@ +assertTrue(true); + } +}