1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MaksimM\CompositePrimaryKeys\Tests; |
4
|
|
|
|
5
|
|
|
use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestBinaryRoleHex; |
6
|
|
|
|
7
|
|
|
class SingleKeyBinaryModelHexTest extends CompositeKeyBaseUnit |
8
|
|
|
{ |
9
|
|
|
protected function getEnvironmentSetUp($app) |
10
|
|
|
{ |
11
|
|
|
$app['config']->set('database.default', 'testing'); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
/** @test */ |
15
|
|
|
public function automaticBinaryKeysOnCreation() |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var TestBinaryRoleHex |
19
|
|
|
*/ |
20
|
|
|
$model = TestBinaryRoleHex::create(['name' => 'Zoo']); |
21
|
|
|
$this->assertNotNull($model->role_id); |
|
|
|
|
22
|
|
|
$this->assertInstanceOf(TestBinaryRoleHex::class, $model); |
23
|
|
|
|
24
|
|
|
return $model; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** @test */ |
28
|
|
|
public function validateManyModelLookup() |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var TestBinaryRoleHex |
32
|
|
|
*/ |
33
|
|
|
$model = TestBinaryRoleHex::findMany([md5(1)])->first(); |
34
|
|
|
$this->assertNotNull($model); |
35
|
|
|
$this->assertInstanceOf(TestBinaryRoleHex::class, $model); |
36
|
|
|
|
37
|
|
|
return $model; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** @test */ |
41
|
|
|
public function validateSingleModelLookup() |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* @var TestBinaryRoleHex |
45
|
|
|
*/ |
46
|
|
|
$model = TestBinaryRoleHex::find(md5(1)); |
47
|
|
|
$this->assertNotNull($model); |
48
|
|
|
$this->assertInstanceOf(TestBinaryRoleHex::class, $model); |
49
|
|
|
|
50
|
|
|
return $model; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** @test |
54
|
|
|
* @depends validateSingleModelLookup |
55
|
|
|
*/ |
56
|
|
|
public function validateSingleModelLookupModel(TestBinaryRoleHex $model) |
57
|
|
|
{ |
58
|
|
|
$this->assertEquals('Foo', $model->name); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** @test |
62
|
|
|
* @depends validateSingleModelLookup |
63
|
|
|
*/ |
64
|
|
|
public function validateSingleModelUpdate(TestBinaryRoleHex $model) |
65
|
|
|
{ |
66
|
|
|
$model->update([ |
67
|
|
|
'name' => 'FooBar', |
68
|
|
|
]); |
69
|
|
|
$model->refresh(); |
70
|
|
|
$this->assertEquals('FooBar', $model->name); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** @test |
74
|
|
|
* @depends validateSingleModelLookup |
75
|
|
|
*/ |
76
|
|
|
public function validateEagerRelations(TestBinaryRoleHex $model) |
77
|
|
|
{ |
78
|
|
|
$model->loadMissing(['users', 'hex_users']); |
79
|
|
|
$this->assertNotNull($model->toArray()['users']); |
80
|
|
|
$this->assertNotNull($model->toArray()['hex_users']); |
81
|
|
|
$this->assertNotNull($model->users); |
|
|
|
|
82
|
|
|
$this->assertNotNull($model->hex_users); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** @test |
86
|
|
|
*/ |
87
|
|
|
public function validateLazyEagerRelations() |
88
|
|
|
{ |
89
|
|
|
$model = TestBinaryRoleHex::find(md5(1)); |
90
|
|
|
$this->assertNotNull($model->users); |
|
|
|
|
91
|
|
|
$this->assertNotNull($model->hex_users); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|