Issues (64)

tests/MissingKeysTest.php (2 issues)

1
<?php
2
3
namespace MaksimM\CompositePrimaryKeys\Tests;
4
5
use Illuminate\Database\Eloquent\Collection;
6
use MaksimM\CompositePrimaryKeys\Exceptions\MissingPrimaryKeyValueException;
7
use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestUser;
8
9
class MissingKeysTest extends CompositeKeyBaseUnit
10
{
11
    /** @test */
12
    public function validateSingleModelLookup()
13
    {
14
        try {
15
            /**
16
             * @var TestUser
17
             */
18
            $model = TestUser::find(
0 ignored issues
show
The assignment to $model is dead and can be removed.
Loading history...
19
                [
20
                    'user_id' => 1,
21
                ]
22
            );
23
        } catch (MissingPrimaryKeyValueException $missingPrimaryKeyValueException) {
24
            $this->assertEquals('organization_id', $missingPrimaryKeyValueException->getMissedValuePrimaryKey());
25
        }
26
        $this->assertFalse($this->doesNotPerformAssertions());
27
    }
28
29
    /** @test */
30
    public function validateMultipleModelLookup()
31
    {
32
        try {
33
            /**
34
             * @var Collection|TestUser[]
35
             */
36
            $models = TestUser::find([[
0 ignored issues
show
The assignment to $models is dead and can be removed.
Loading history...
37
                'organization_id' => 100,
38
            ], [
39
                'user_id'         => 2,
40
                'organization_id' => 100,
41
            ]]);
42
        } catch (MissingPrimaryKeyValueException $missingPrimaryKeyValueException) {
43
            $this->assertEquals('user_id', $missingPrimaryKeyValueException->getMissedValuePrimaryKey());
44
        }
45
        $this->assertFalse($this->doesNotPerformAssertions());
46
    }
47
}
48