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 @@