1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Modules\Example\Tests; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Console\Kernel; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
use Modules\Core\Enums\StatusCodeEnum; |
8
|
|
|
use Modules\Example\Database\Seeders\ExampleTableSeederTableSeeder; |
9
|
|
|
use Illuminate\Foundation\Testing\TestCase; |
10
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase; |
11
|
|
|
|
12
|
|
|
class ExampleTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
use RefreshDatabase; |
|
|
|
|
15
|
|
|
|
16
|
|
|
private $baseUri = 'api/v1/'; |
17
|
|
|
private $resource = 'examples'; |
18
|
|
|
private $uri; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Creates the application. |
22
|
|
|
* |
23
|
|
|
* @return \Illuminate\Foundation\Application |
24
|
|
|
*/ |
25
|
|
|
public function createApplication() |
26
|
|
|
{ |
27
|
|
|
$app = require __DIR__.'/../../../bootstrap/app.php'; |
28
|
|
|
|
29
|
|
|
$app->make(Kernel::class)->bootstrap(); |
30
|
|
|
|
31
|
|
|
return $app; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
$this->uri = $this->baseUri.Str::plural($this->resource); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testIndex() |
40
|
|
|
{ |
41
|
|
|
$this->get("{$this->uri}")->assertStatus(StatusCodeEnum::HTTP_OK); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testStore() |
45
|
|
|
{ |
46
|
|
|
$this->post("{$this->uri}", ['name' => 'demo', 'value' => 'hello world']) |
47
|
|
|
->assertStatus(StatusCodeEnum::HTTP_CREATED); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testShow() |
51
|
|
|
{ |
52
|
|
|
$this->seed(ExampleTableSeederTableSeeder::class); |
53
|
|
|
|
54
|
|
|
$this->get("{$this->uri}/1")->assertStatus(StatusCodeEnum::HTTP_OK); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testUpdate() |
58
|
|
|
{ |
59
|
|
|
$this->seed(ExampleTableSeederTableSeeder::class); |
60
|
|
|
|
61
|
|
|
$this->put("{$this->uri}/1", ['value' => 'Hello World'])->assertStatus(StatusCodeEnum::HTTP_RESET_CONTENT); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testDestroy() |
65
|
|
|
{ |
66
|
|
|
$this->seed(ExampleTableSeederTableSeeder::class); |
67
|
|
|
|
68
|
|
|
$this->delete("{$this->uri}/1")->assertStatus(StatusCodeEnum::HTTP_NO_CONTENT); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|