From 19f97d066256fd0a6c2fc90d7e1e7464aa2e47ca Mon Sep 17 00:00:00 2001 From: Zain Fauzan Rofie Azizi Date: Fri, 4 May 2018 16:13:51 +0800 Subject: [PATCH] added unit testing --- .../Controllers/DeliveryInfoController.php | 10 +- config/database.php | 15 ++ database/factories/DeliveryinfoFactory.php | 18 ++ database/factories/UserFactory.php | 2 +- phpunit.xml | 2 +- .../company/deliveryinfo/index.blade.php | 155 +++++++++--------- routes/api.php | 4 - tests/Feature/ExampleTest.php | 21 --- tests/Unit/DeliveryinfoTest.php | 72 ++++++++ tests/Unit/ExampleTest.php | 19 --- 10 files changed, 189 insertions(+), 129 deletions(-) create mode 100644 database/factories/DeliveryinfoFactory.php delete mode 100644 tests/Feature/ExampleTest.php create mode 100644 tests/Unit/DeliveryinfoTest.php delete mode 100644 tests/Unit/ExampleTest.php diff --git a/app/Http/Controllers/DeliveryInfoController.php b/app/Http/Controllers/DeliveryInfoController.php index efc686f..7602f62 100644 --- a/app/Http/Controllers/DeliveryInfoController.php +++ b/app/Http/Controllers/DeliveryInfoController.php @@ -48,10 +48,12 @@ class DeliveryinfoController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function show($id) + public function show(Deliveryinfo $com_id) { - $com_id = deliveryinfo::find($com_id); - return response()->json($com_id, 200); + $deliveryinfo = deliveryinfo::find($com_id); + return response()->json($deliveryinfo, 200); + + // return $delievryinfo; } /** @@ -76,7 +78,7 @@ class DeliveryinfoController extends Controller { $com_id = Deliveryinfo::find($com_id); - $com_id->id = $request->input('id'); + //$com_id->id = $request->input('id'); $com_id->branch = $request->input('branch'); $com_id->deli_info = $request->input('deli_info'); $com_id->address = $request->input('address'); diff --git a/config/database.php b/config/database.php index cab5d06..f949103 100644 --- a/config/database.php +++ b/config/database.php @@ -53,6 +53,21 @@ return [ 'strict' => true, 'engine' => null, ], + + 'testing' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', '127.0.0.1'), + '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', diff --git a/database/factories/DeliveryinfoFactory.php b/database/factories/DeliveryinfoFactory.php new file mode 100644 index 0000000..3a4c0fb --- /dev/null +++ b/database/factories/DeliveryinfoFactory.php @@ -0,0 +1,18 @@ +define(App\Deliveryinfo::class, function (Faker $faker) { + return [ + 'id' => $faker, + 'branch' => $faker->text, + 'deli_info' => $faker->sentence, + 'address' => $faker->text, + 'city' => $faker->text, + 'postcode' => $faker->text, + 'state' => $faker->text, + 'country' => $faker->text, + 'contact_person' => $faker->name, + 'contact_person_no' => $faker->text, + ]; +}); diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index facf233..399bc8d 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -17,7 +17,7 @@ $factory->define(App\User::class, function (Faker $faker) { return [ 'name' => $faker->name, 'email' => $faker->unique()->safeEmail, - 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret + 'password' => bcrypt(str_random(10)), // secret 'remember_token' => str_random(10), ]; }); diff --git a/phpunit.xml b/phpunit.xml index 9ee3e73..e4ebad6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -27,6 +27,6 @@ - + diff --git a/resources/views/company/deliveryinfo/index.blade.php b/resources/views/company/deliveryinfo/index.blade.php index f04b50f..9b14d2a 100644 --- a/resources/views/company/deliveryinfo/index.blade.php +++ b/resources/views/company/deliveryinfo/index.blade.php @@ -1,95 +1,92 @@ - - - - - Laravel + + + + - - + Laravel - - - - -
- @if (Route::has('login')) - - @endif + .links>a { + color: #636b6f; + padding: 0 25px; + font-size: 12px; + font-weight: 600; + letter-spacing: .1rem; + text-decoration: none; + text-transform: uppercase; + } -
-
- Laravel -
+ .m-b-md { + margin-bottom: 30px; + } + + + + +
+ @if (Route::has('login')) + + @endif + +
+
+ Laravel +
+ +
+
+ - -
-
- \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 119d095..5b3050e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -13,10 +13,6 @@ use Illuminate\Http\Request; | */ -Route::middleware('auth:api')->get('/user', function (Request $request) { - return $request->user(); -}); - /* Routes for the DeliveryInfo in profile*/ Route::get('/company/deliveryinfo','DeliveryinfoController@index'); Route::get('/company/{com_id}/deliveryinfo','DeliveryinfoController@show'); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index f31e495..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Unit/DeliveryinfoTest.php b/tests/Unit/DeliveryinfoTest.php new file mode 100644 index 0000000..93c193b --- /dev/null +++ b/tests/Unit/DeliveryinfoTest.php @@ -0,0 +1,72 @@ +json('GET', '/api/company/deliveryinfo'); + + $response->assertStatus(200); + } + + // public function testPOST() + // { + // $response = $this->json('POST', '/api/company/com_id/deliveryinfo', [ + + // 'branch' => 'Testing', + // 'deli_info' => 'Testing', + // 'address' => 'Testing', + // 'city' => 'Testing', + // 'postcode' => '12345', + // 'state' => 'Testing', + // 'country' => 'Testing', + // 'contact_person' => 'Testing', + // 'contact_person_no' => '12345', + + // ]); + + // $response->assertStatus(201); + // } + + // public function testDELETE() + // { + // $response = $this->json('DELETE', '/api/company/4/deliveryinfo'); + + // $response->assertStatus(204); + // } + + public function testPUT() + { + + + $response = $this->json('PUT', '/api/company/1/deliveryinfo', [ + + //'id' => '1', + 'branch' => 'Ci', + 'deli_info' => 'Testing', + 'address' => 'Testing', + 'city' => 'Test', + 'postcode' => '12345', + 'state' => 'Testing', + 'country' => 'Testing', + 'contact_person' => 'Testing', + 'contact_person_no' => '12345' + + ]); + + $response->assertStatus(200); + } +} diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index e9fe19c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(true); - } -}