Passed
Push — master ( b3d466...4214a1 )
by Maksim
02:07
created

OtherQueriesTest::validateKeyExclusion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace MaksimM\CompositePrimaryKeys\Tests;
4
5
use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestUser;
6
7
class OtherQueriesTest extends CompositeKeyBaseUnit
8
{
9
    /** @test */
10
    public function validateKeyExclusion()
11
    {
12
        /**
13
         * @var TestUser
14
         */
15
        $model = TestUser::whereKeyNot([
16
            'user_id'         => 1,
17
            'organization_id' => 100,
18
        ])
19
            ->where('user_id',1)
20
            ->first();
21
        $this->assertNotNull($model);
22
        $this->assertInstanceOf(TestUser::class, $model);
23
24
        return $model;
25
    }
26
27
    /** @test
28
     *  @depends  validateSingleModelLookup
29
     */
30
    public function validateSingleModelLookupModel(TestUser $model)
31
    {
32
        $this->assertEquals(1, $model->user_id);
33
        $this->assertEquals(101, $model->organization_id);
34
        $this->assertEquals('Bar', $model->name);
35
    }
36
37
    /**
38
     * @test
39
     */
40
    public function validateDeleteModel()
41
    {
42
        /**
43
         * @var TestUser
44
         */
45
        TestUser::find([
46
            'user_id'         => 1,
47
            'organization_id' => 100,
48
        ])->delete();
49
50
        $this->assertNull(TestUser::find([
51
            'user_id'         => 1,
52
            'organization_id' => 100,
53
        ]));
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function validateDeleteWithoutFetching()
60
    {
61
        /**
62
         * @var TestUser
63
         */
64
        TestUser::whereKey([
65
            'user_id'         => 1,
66
            'organization_id' => 100,
67
        ])->delete();
68
69
        $this->assertNull(TestUser::find([
70
            'user_id'         => 1,
71
            'organization_id' => 100,
72
        ]));
73
    }
74
75
}
76