|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: okaufmann |
|
5
|
|
|
* Date: 28.10.2016 |
|
6
|
|
|
* Time: 01:23. |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace App\Tests\Api; |
|
9
|
|
|
|
|
10
|
|
|
use App\Tests\AbstractTestCase; |
|
11
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations; |
|
12
|
|
|
|
|
13
|
|
|
abstract class AbstractApiTestCase extends AbstractTestCase |
|
14
|
|
|
{ |
|
15
|
|
|
use DatabaseMigrations; |
|
16
|
|
|
|
|
17
|
|
|
protected $apiUri = '/services.php'; |
|
18
|
|
|
protected $guid = '{D6A33C24-DE43-D62C-A609-EF5138F33F30}'; |
|
19
|
|
|
protected $success = 'Operation has succeeded'; |
|
20
|
|
|
|
|
21
|
|
|
protected function buildUrl(string $url, array $data) : string |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
$data['guid'] = $this->guid; |
|
24
|
|
|
$paramString = http_build_query($data); |
|
25
|
|
|
|
|
26
|
|
|
return $this->apiUri.'?'.$paramString; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
protected function seeSuccess() |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->seeStatusCode(200) |
|
32
|
|
|
->see($this->success); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Assert that a given where condition does not matches a soft deleted record |
|
37
|
|
|
* From: http://stackoverflow.com/questions/33117746/laravel-unit-testing-how-to-seeindatabase-soft-deleted-row |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $table |
|
40
|
|
|
* @param array $data |
|
41
|
|
|
* @param string $connection |
|
42
|
|
|
* @return $this |
|
43
|
|
|
*/ |
|
44
|
|
View Code Duplication |
protected function seeIsNotSoftDeletedInDatabase($table, array $data, $connection = null) |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
$database = $this->app->make('db'); |
|
47
|
|
|
|
|
48
|
|
|
$connection = $connection ?: $database->getDefaultConnection(); |
|
49
|
|
|
|
|
50
|
|
|
$count = $database->connection($connection) |
|
51
|
|
|
->table($table) |
|
52
|
|
|
->where($data) |
|
53
|
|
|
->whereNull('deleted_at') |
|
54
|
|
|
->count(); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertGreaterThan(0, $count, sprintf( |
|
57
|
|
|
'Found unexpected records in database table [%s] that matched attributes [%s].', $table, json_encode($data) |
|
58
|
|
|
)); |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Assert that a given where condition matches a soft deleted record |
|
65
|
|
|
* From: http://stackoverflow.com/questions/33117746/laravel-unit-testing-how-to-seeindatabase-soft-deleted-row |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $table |
|
68
|
|
|
* @param array $data |
|
69
|
|
|
* @param string $connection |
|
70
|
|
|
* @return $this |
|
71
|
|
|
*/ |
|
72
|
|
View Code Duplication |
protected function seeIsSoftDeletedInDatabase($table, array $data, $connection = null) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
$database = $this->app->make('db'); |
|
75
|
|
|
|
|
76
|
|
|
$connection = $connection ?: $database->getDefaultConnection(); |
|
77
|
|
|
|
|
78
|
|
|
$count = $database->connection($connection) |
|
79
|
|
|
->table($table) |
|
80
|
|
|
->where($data) |
|
81
|
|
|
->whereNotNull('deleted_at') |
|
82
|
|
|
->count(); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertGreaterThan(0, $count, sprintf( |
|
85
|
|
|
'Found unexpected records in database table [%s] that matched attributes [%s].', $table, json_encode($data) |
|
86
|
|
|
)); |
|
87
|
|
|
|
|
88
|
|
|
return $this; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.