NativeInTest::testNativeIn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\ORM\Query;
6
7
use Ecodev\Felix\ORM\Query\NativeIn;
8
use EcodevTests\Felix\Traits\TestWithTypes;
9
use PHPUnit\Framework\TestCase;
10
11
class NativeInTest extends TestCase
12
{
13
    use TestWithTypes;
14
15
    /**
16
     * @dataProvider providerNativeIn
17
     */
18
    public function testNativeIn(string $dql, string $expected): void
19
    {
20
        $query = $this->entityManager->createQuery($dql);
21
        $actual = $query->getSQL();
22
23
        self::assertSame($expected, $actual);
24
    }
25
26
    public static function providerNativeIn(): iterable
27
    {
28
        yield 'normal with string' => [
29
            'SELECT u.id FROM EcodevTests\Felix\Blog\Model\User u WHERE ' . NativeIn::dql('u.id', "SELECT '123'"),
30
            "SELECT u0_.id AS id_0 FROM user u0_ WHERE u0_.id IN (SELECT '123') = 1",
31
        ];
32
33
        yield 'normal with escape' => [
34
            'SELECT c.id FROM EcodevTests\Felix\Blog\Model\User c WHERE ' . NativeIn::dql('c.id', "SELECT '1\t2\n3'"),
35
            "SELECT u0_.id AS id_0 FROM user u0_ WHERE u0_.id IN (SELECT '1\t2\n3') = 1",
36
        ];
37
        yield 'normal with double string' => [
38
            'SELECT c.id FROM EcodevTests\Felix\Blog\Model\User c WHERE ' . NativeIn::dql('c.id', 'SELECT "123"'),
39
            'SELECT u0_.id AS id_0 FROM user u0_ WHERE u0_.id IN (SELECT "123") = 1',
40
        ];
41
        yield 'negative with string' => [
42
            'SELECT u.id FROM EcodevTests\Felix\Blog\Model\User u WHERE ' . NativeIn::dql('u.id', "SELECT '123'", true),
43
            "SELECT u0_.id AS id_0 FROM user u0_ WHERE u0_.id NOT IN (SELECT '123') = 1",
44
        ];
45
        yield 'complex' => [
46
            'SELECT u.id FROM EcodevTests\Felix\Blog\Model\User u WHERE ' . NativeIn::dql('u.id', 'SELECT post.user_id FROM post'),
47
            'SELECT u0_.id AS id_0 FROM user u0_ WHERE u0_.id IN (SELECT post.user_id FROM post) = 1',
48
        ];
49
        yield 'multiline' => [
50
            'SELECT u.id FROM EcodevTests\Felix\Blog\Model\User u WHERE ' . NativeIn::dql(
51
                'u.id',
52
                <<<SQL
53
                    SELECT post.user_id
54
                    FROM post
55
                    SQL
56
            ),
57
            <<<SQL
58
                SELECT u0_.id AS id_0 FROM user u0_ WHERE u0_.id IN (SELECT post.user_id
59
                FROM post) = 1
60
                SQL,
61
        ];
62
        yield 'alias' => [
63
            'SELECT u.id AS my_alias FROM EcodevTests\Felix\Blog\Model\User u WHERE ' . NativeIn::dql('my_alias', "SELECT '123'"),
64
            "SELECT u0_.id AS id_0 FROM user u0_ WHERE id_0 IN (SELECT '123') = 1",
65
66
        ];
67
    }
68
}
69