Browse Source

Update Api Controller and Feature Test generator

tags/1.1.2
Nafies Luthfi 8 years ago
parent
commit
196c33bc67
  1. 12
      src/stubs/controller.api.stub
  2. 19
      src/stubs/test-feature-api.stub
  3. 12
      tests/Generators/Api/ApiControllerGeneratorTest.php
  4. 38
      tests/Generators/Api/ApiFeatureTestGeneratorTest.php

12
src/stubs/controller.api.stub

@ -43,7 +43,10 @@ class MastersController extends Controller
$singleMstr = Master::create($newMaster);
return $singleMstr;
return response()->json([
'message' => __('master.created'),
'data' => $singleMstr,
], 201);
}
/**
@ -77,7 +80,10 @@ class MastersController extends Controller
$singleMstr->update($request->only('name', 'description'));
return $singleMstr;
return response()->json([
'message' => __('master.updated'),
'data' => $singleMstr,
]);
}
/**
@ -96,7 +102,7 @@ class MastersController extends Controller
]);
if (request('master_id') == $singleMstr->id && $singleMstr->delete()) {
return response()->json('master deleted.', 204);
return response()->json(['message' => __('master.deleted')]);
}
return response()->json('Unprocessable Entity.', 422);

19
src/stubs/test-feature-api.stub

@ -40,7 +40,12 @@ class ManageMastersTest extends TestCase
'description' => 'Master 1 description',
]);
$this->seeJson(['name' => 'Master 1 name']);
$this->seeStatusCode(201);
$this->seeJson([
'message' => __('master.created'),
'name' => 'Master 1 name',
'description' => 'Master 1 description',
]);
}
/** @test */
@ -74,7 +79,12 @@ class ManageMastersTest extends TestCase
'description' => 'Master 1 description',
]);
$this->seeJson(['name' => 'Master 1 name']);
$this->seeStatusCode(200);
$this->seeJson([
'message' => __('master.updated'),
'name' => 'Master 1 name',
'description' => 'Master 1 description',
]);
}
/** @test */
@ -92,5 +102,10 @@ class ManageMastersTest extends TestCase
$this->dontSeeInDatabase('masters', [
'id' => $singleMstr->id,
]);
$this->seeStatusCode(200);
$this->seeJson([
'message' => __('master.deleted'),
]);
}
}

12
tests/Generators/Api/ApiControllerGeneratorTest.php

@ -57,7 +57,10 @@ class {$this->plural_model_name}Controller extends Controller
\${$this->single_model_var_name} = {$this->model_name}::create(\$new{$this->model_name});
return \${$this->single_model_var_name};
return response()->json([
'message' => __('{$this->lang_name}.created'),
'data' => \${$this->single_model_var_name},
], 201);
}
/**
@ -91,7 +94,10 @@ class {$this->plural_model_name}Controller extends Controller
\${$this->single_model_var_name}->update(\$request->only('name', 'description'));
return \${$this->single_model_var_name};
return response()->json([
'message' => __('{$this->lang_name}.updated'),
'data' => \${$this->single_model_var_name},
]);
}
/**
@ -110,7 +116,7 @@ class {$this->plural_model_name}Controller extends Controller
]);
if (request('{$this->lang_name}_id') == \${$this->single_model_var_name}->id && \${$this->single_model_var_name}->delete()) {
return response()->json('{$this->lang_name} deleted.', 204);
return response()->json(['message' => __('{$this->lang_name}.deleted')]);
}
return response()->json('Unprocessable Entity.', 422);

38
tests/Generators/Api/ApiFeatureTestGeneratorTest.php

@ -54,7 +54,12 @@ class Manage{$this->plural_model_name}Test extends TestCase
'description' => '{$this->model_name} 1 description',
]);
\$this->seeJson(['name' => '{$this->model_name} 1 name']);
\$this->seeStatusCode(201);
\$this->seeJson([
'message' => __('{$this->lang_name}.created'),
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
]);
}
/** @test */
@ -88,7 +93,12 @@ class Manage{$this->plural_model_name}Test extends TestCase
'description' => '{$this->model_name} 1 description',
]);
\$this->seeJson(['name' => '{$this->model_name} 1 name']);
\$this->seeStatusCode(200);
\$this->seeJson([
'message' => __('{$this->lang_name}.updated'),
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
]);
}
/** @test */
@ -106,6 +116,11 @@ class Manage{$this->plural_model_name}Test extends TestCase
\$this->dontSeeInDatabase('{$this->table_name}', [
'id' => \${$this->single_model_var_name}->id,
]);
\$this->seeStatusCode(200);
\$this->seeJson([
'message' => __('{$this->lang_name}.deleted'),
]);
}
}
";
@ -163,7 +178,12 @@ class Manage{$this->plural_model_name}Test extends TestCase
'description' => '{$this->model_name} 1 description',
]);
\$this->seeJson(['name' => '{$this->model_name} 1 name']);
\$this->seeStatusCode(201);
\$this->seeJson([
'message' => __('{$this->lang_name}.created'),
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
]);
}
/** @test */
@ -197,7 +217,12 @@ class Manage{$this->plural_model_name}Test extends TestCase
'description' => '{$this->model_name} 1 description',
]);
\$this->seeJson(['name' => '{$this->model_name} 1 name']);
\$this->seeStatusCode(200);
\$this->seeJson([
'message' => __('{$this->lang_name}.updated'),
'name' => '{$this->model_name} 1 name',
'description' => '{$this->model_name} 1 description',
]);
}
/** @test */
@ -215,6 +240,11 @@ class Manage{$this->plural_model_name}Test extends TestCase
\$this->dontSeeInDatabase('{$this->table_name}', [
'id' => \${$this->single_model_var_name}->id,
]);
\$this->seeStatusCode(200);
\$this->seeJson([
'message' => __('{$this->lang_name}.deleted'),
]);
}
}
";

Loading…
Cancel
Save