added unit testing

This commit is contained in:
Zain Fauzan Rofie Azizi
2018-05-04 16:13:51 +08:00
parent a08c107ef7
commit 19f97d0662
10 changed files with 189 additions and 129 deletions
@@ -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');
+15
View File
@@ -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',
@@ -0,0 +1,18 @@
<?php
use Faker\Generator as Faker;
$factory->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,
];
});
+1 -1
View File
@@ -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),
];
});
+1 -1
View File
@@ -27,6 +27,6 @@
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
@@ -1,95 +1,92 @@
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
<title>Laravel</title>
<!-- Styles -->
<style>
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Raleway', sans-serif;
font-weight: 100;
height: 100vh;
margin: 0;
}
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
.full-height {
height: 100vh;
}
<!-- Styles -->
<style>
html,
body {
background-color: #fff;
color: #636b6f;
font-family: 'Raleway', sans-serif;
font-weight: 100;
height: 100vh;
margin: 0;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.full-height {
height: 100vh;
}
.position-ref {
position: relative;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.position-ref {
position: relative;
}
.content {
text-align: center;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.title {
font-size: 84px;
}
.content {
text-align: center;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 12px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.title {
font-size: 84px;
}
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@auth
<a href="{{ url('/home') }}">Home</a>
@else
<a href="{{ route('login') }}">Login</a>
<a href="{{ route('register') }}">Register</a>
@endauth
</div>
@endif
.links>a {
color: #636b6f;
padding: 0 25px;
font-size: 12px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
<div class="content">
<div class="title m-b-md">
Laravel
</div>
.m-b-md {
margin-bottom: 30px;
}
</style>
</head>
<body>
<div class="flex-center position-ref full-height">
@if (Route::has('login'))
<div class="top-right links">
@auth
<a href="{{ url('/home') }}">Home</a>
@else
<a href="{{ route('login') }}">Login</a>
<a href="{{ route('register') }}">Register</a>
@endauth
</div>
@endif
<div class="content">
<div class="title m-b-md">
<p2>Laravel</p2>
</div>
</div>
</div>
</body>
<div class="links">
<a href="https://laravel.com/docs">Documentation</a>
<a href="https://laracasts.com">Laracasts</a>
<a href="https://laravel-news.com">News</a>
<a href="https://forge.laravel.com">Forge</a>
<a href="https://github.com/laravel/laravel">GitHub</a>
</div>
</div>
</div>
</body>
</html>
-4
View File
@@ -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');
-21
View File
@@ -1,21 +0,0 @@
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
namespace Tests\Unit\Deliveryinfo;
namespace Test\API;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
class DeliveryinfoTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testGET()
{
$response = $this->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);
}
}
-19
View File
@@ -1,19 +0,0 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$this->assertTrue(true);
}
}