Passed
Push — main ( 7d9f09...bbfba8 )
by Peter
02:36
created

LockTest::toStringProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\MySQL\Clause;
6
7
use PHPUnit\Framework\TestCase;
8
9
class LockTest extends TestCase
10
{
11
    /**
12
     * @return array[]
13
     */
14
    public function toStringProvider(): array
15
    {
16
        return [
17
            [null, [], null, Lock::LOCK_IN_SHARE_MODE],
18
            [Lock::LOCK_IN_SHARE_MODE, [], null, Lock::LOCK_IN_SHARE_MODE],
19
            [Lock::FOR_UPDATE, [], null, 'FOR UPDATE'],
20
            [Lock::FOR_SHARE, [], null, 'FOR SHARE'],
21
            [Lock::FOR_UPDATE, [], Lock::MODIFIER_NOWAIT, "FOR UPDATE NOWAIT"],
22
            [Lock::FOR_SHARE, [], Lock::MODIFIER_SKIP_LOCKED, "FOR SHARE SKIP LOCKED"],
23
            [Lock::FOR_UPDATE, ['foo', 'bar'], null, "FOR UPDATE OF foo, bar"],
24
            [Lock::FOR_SHARE, ['foo', 'bar'], Lock::MODIFIER_NOWAIT, "FOR SHARE OF foo, bar NOWAIT"],
25
        ];
26
    }
27
28
    /**
29
     * @dataProvider toStringProvider
30
     *
31
     * @param string|null $for
32
     * @param array       $tables
33
     * @param string|null $modifier
34
     * @param string      $expectedSql
35
     */
36
    public function testToString(?string $for, array $tables, ?string $modifier, string $expectedSql)
37
    {
38
        $lock = new Lock($for, $tables, $modifier);
39
        $sql  = (string)$lock;
40
41
        $this->assertSame($expectedSql, $sql);
42
    }
43
44
    /**
45
     * @return array[]
46
     */
47
    public function constructValidationProvider(): array
48
    {
49
        return [
50
            'invalid for'                => ['foo', [], null],
51
            'invalid modifier'           => [Lock::FOR_SHARE, [], 'foo'],
52
        ];
53
    }
54
55
    /**
56
     * @dataProvider constructValidationProvider
57
     *
58
     * @suppress     PhanNoopNew
59
     *
60
     * @param string|null $for
61
     * @param array       $tables
62
     * @param string|null $modifier
63
     */
64
    public function testConstructValidation(?string $for, array $tables, ?string $modifier)
65
    {
66
        $this->expectException(\InvalidArgumentException::class);
67
68
        new Lock($for, $tables, $modifier);
69
    }
70
}
71