LikeWildcardsEscapingTest.php 938 Bytes
Newer Older
1 2
<?php

3
namespace Doctrine\DBAL\Tests\Functional;
4

5
use Doctrine\DBAL\Tests\FunctionalTestCase;
Grégoire Paris's avatar
Grégoire Paris committed
6
use function sprintf;
7

8
final class LikeWildcardsEscapingTest extends FunctionalTestCase
9 10 11
{
    public function testFetchLikeExpressionResult() : void
    {
12
        $string           = '_25% off_ your next purchase \o/ [$̲̅(̲̅5̲̅)̲̅$̲̅] (^̮^)';
13
        $escapeChar       = '!';
Sergei Morozov's avatar
Sergei Morozov committed
14 15
        $databasePlatform = $this->connection->getDatabasePlatform();
        $stmt             = $this->connection->prepare(
16 17 18 19 20 21 22 23 24
            $databasePlatform->getDummySelectSQL(
                sprintf(
                    "(CASE WHEN '%s' LIKE '%s' ESCAPE '%s' THEN 1 ELSE 0 END)",
                    $string,
                    $databasePlatform->escapeStringForLike($string, $escapeChar),
                    $escapeChar
                )
            )
        );
25
        $stmt->execute();
26
        $this->assertTrue((bool) $stmt->fetchColumn());
27 28
    }
}