mirror of
https://github.com/kevin-DL/commander_league_api.git
synced 2026-01-11 18:44:32 +00:00
Game formats
- Created the formats tables/migrations - Created the controller to retrieve the formats
This commit is contained in:
6
.env.testing
Normal file
6
.env.testing
Normal file
@@ -0,0 +1,6 @@
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=commanderleagueapi_test
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
19
app/Http/Controllers/FormatsController.php
Normal file
19
app/Http/Controllers/FormatsController.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Model\Format;
|
||||
|
||||
class FormatsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$formats = Format::all();
|
||||
return response()->json(['data' => $formats->toArray()], 200);
|
||||
}
|
||||
}
|
||||
9
app/Model/Format.php
Normal file
9
app/Model/Format.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
class Format extends \Illuminate\Database\Eloquent\Model
|
||||
{
|
||||
protected $fillable = ['name'];
|
||||
protected $hidden = ['created_at', 'updated_at'];
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
|
||||
use App\Model\Format;
|
||||
use App\User;
|
||||
use Faker\Generator as Faker;
|
||||
|
||||
@@ -22,3 +23,9 @@ $factory->define(User::class, function (Faker $faker) {
|
||||
'email' => $faker->email,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(Format::class, function (Faker $faker){
|
||||
return [
|
||||
'name' => $faker->name
|
||||
];
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateFormatsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('formats', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('formats');
|
||||
}
|
||||
}
|
||||
@@ -12,5 +12,8 @@ class DatabaseSeeder extends Seeder
|
||||
public function run()
|
||||
{
|
||||
// $this->call('UsersTableSeeder');
|
||||
$this->call([
|
||||
FormatSeeder::class
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
17
database/seeds/FormatSeeder.php
Normal file
17
database/seeds/FormatSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class FormatSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
\App\Model\Format::create(['name' => 'Commander']);
|
||||
\App\Model\Format::create(['name' => 'Brawl']);
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,9 @@
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
<env name="CACHE_DRIVER" value="array"/>
|
||||
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||
<env name="DB_CONNECTION" value="mysql"/>
|
||||
<env name="DB_HOST" value="127.0.0.1"/>
|
||||
<env name="DB_PORT" value="3306"/>
|
||||
<env name="DB_DATABASE" value="commanderleagueapi_test"/>
|
||||
</php>
|
||||
</phpunit>
|
||||
|
||||
@@ -15,3 +15,5 @@
|
||||
$router->get('/', function () use ($router) {
|
||||
return $router->app->version();
|
||||
});
|
||||
|
||||
$router->get('/formats', ['uses' => 'FormatsController@index', 'as' => 'formats.list']);
|
||||
|
||||
20
tests/Http/Controllers/FormatsControllerTest.php
Normal file
20
tests/Http/Controllers/FormatsControllerTest.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\FormatsController;
|
||||
use App\Model\Format;
|
||||
use Laravel\Lumen\Testing\DatabaseMigrations;
|
||||
use TestCase;
|
||||
|
||||
class FormatsControllerTest extends TestCase
|
||||
{
|
||||
use DatabaseMigrations;
|
||||
|
||||
public function testGetTheFormats()
|
||||
{
|
||||
$formats = factory(Format::class, 5)->create();
|
||||
$this->json('GET', route('formats.list'))->seeStatusCode(200)->seeJson($formats->all());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user