From bc6f948314018fa7ecbd6bda6178fcefeed26e59 Mon Sep 17 00:00:00 2001 From: Mohd Arief Date: Tue, 15 May 2018 10:59:26 +0800 Subject: [PATCH] added unit testing --- app/Http/Controllers/BookingController.php | 36 ++++++---- config/database.php | 15 ++++ phpunit.xml | 1 + routes/api.php | 8 +-- tests/Feature/ExampleTest.php | 21 ------ tests/Unit/ExampleTest.php | 19 ----- tests/Unit/OrderTest.php | 83 ++++++++++++++++++++++ 7 files changed, 124 insertions(+), 59 deletions(-) delete mode 100644 tests/Feature/ExampleTest.php delete mode 100644 tests/Unit/ExampleTest.php create mode 100644 tests/Unit/OrderTest.php diff --git a/app/Http/Controllers/BookingController.php b/app/Http/Controllers/BookingController.php index 58066999..65d802f5 100644 --- a/app/Http/Controllers/BookingController.php +++ b/app/Http/Controllers/BookingController.php @@ -69,19 +69,25 @@ class BookingController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function update(Request $request, $booking) + public function update(Request $request, $book_id) { - // $booking->update($request->all()); - // $this->validate($request, [ - // 'account_name' => 'required', - // 'account_num' => 'required' - // ]); - //Update Post - $booking = Booking::find($booking); - // $booking->account_name = 'hello'; - // $booking->account_num = 'account_num'; - $booking->save(); - return response()->json($booking, 200); + $book_id = Booking::find($book_id); + + //$com_id->id = $request->input('id'); + $book_id->account_name = $request->input('account_name'); + $book_id->account_num = $request->input('account_num'); + $book_id->bank_name = $request->input('bank_name'); + $book_id->bank_branch = $request->input('bank_branch'); + $book_id->company_name = $request->input('company_name'); + $book_id->company_address = $request->input('company_address'); + $book_id->bank_address = $request->input('bank_address'); + $book_id->swift_code = $request->input('swift_code'); + $book_id->cnap = $request->input('cnap'); + $book_id->save(); + + return response()->json(['book_id'=>$book_id],200); + + } /** @@ -90,10 +96,10 @@ class BookingController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function delete(Booking $booking) + public function delete(Booking $book_id) { - $booking->delete($booking); + $book_id->delete($book_id); - return response()->json($booking, 204); + return response()->json($book_id, 204); } } diff --git a/config/database.php b/config/database.php index de4ffe6f..52d3593b 100644 --- a/config/database.php +++ b/config/database.php @@ -54,6 +54,21 @@ return [ 'engine' => null, ], + 'testing' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', 'localhost'), + 'port' => env('DB_PORT', '3306'), + 'database' => 'forunittest', + 'username' => 'root', + 'password' => '', + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'strict' => true, + 'engine' => null, + ], + 'pgsql' => [ 'driver' => 'pgsql', 'host' => env('DB_HOST', '127.0.0.1'), diff --git a/phpunit.xml b/phpunit.xml index 9ee3e734..bb335921 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -27,6 +27,7 @@ + diff --git a/routes/api.php b/routes/api.php index 5d76c21f..f823d80c 100644 --- a/routes/api.php +++ b/routes/api.php @@ -20,13 +20,13 @@ Route::middleware('auth:api')->get('/user', function (Request $request) { /*Route for the booking */ Route::get('/booking', 'BookingController@index'); -Route::get('/booking/{booking}', 'BookingController@show'); +Route::get('/booking/{book_id}', 'BookingController@show'); -Route::post('/booking', 'BookingController@store'); +Route::post('/booking/{book_id}', 'BookingController@store'); -Route::put('/booking/{booking}', 'BookingController@update'); +Route::put('/booking/{book_id}', 'BookingController@update'); -Route::delete('/booking/{booking}', 'BookingController@delete'); +Route::delete('/booking/{book_id}', 'BookingController@delete'); //Route::middleware('auth:api')->get('/user', function (Request $request) { diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index f31e495c..00000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index e9fe19c6..00000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(true); - } -} diff --git a/tests/Unit/OrderTest.php b/tests/Unit/OrderTest.php new file mode 100644 index 00000000..036149b6 --- /dev/null +++ b/tests/Unit/OrderTest.php @@ -0,0 +1,83 @@ +assertTrue(true); + // $response = $this->json('POST', '/api/booking', ['book_id' => '10']); + + // $response + // ->assertStatus(201) + // ->assertJson([ + // //'ff_id' => 'inserted', + // ]); + // } + + public function testGet() + { + $response = $this->get('/api/booking'); + + $response->assertStatus(200); + } + + // public function testPost() + // { + // $response = $this->json('POST', '/api/booking/2', [ + + // 'account_name' => 'kita', + // 'account_num' => '1234', + // 'bank_name' => 'ferdas', + // 'bank_branch' => 'dersa', + // 'company_name' => 'desaq', + // 'company_address' => 'qada', + // 'bank_address' => 'daqa', + // 'swift_code' => '3eds2', + // 'cnap' => 'redah' + + // ]); + + // $response + // ->assertStatus(201); + // } + + // public function testPut() + // { + // $response = $this->json('PUT', '/api/booking/1', [ + + // 'account_name' => 'kaokndfoanf', + // 'account_num' => '1234', + // 'bank_name' => 'ferdas', + // 'bank_branch' => 'dersa', + // 'company_name' => 'desaq', + // 'company_address' => 'qada', + // 'bank_address' => 'daqa', + // 'swift_code' => '3eds2', + // 'cnap' => 'redah' + + // ]); + + // $response + // ->assertStatus(200); + // } + + public function testDelete() + { + $response = $this->json('DELETE', '/api/booking/2'); + + $response->assertStatus(204); + } +}