escapeFunction example

$result = '0x' . strtoupper(bin2hex($result));

                break;

            case \is_string($result):
                $result = '\'' . addslashes($result) . '\'';

                break;

            case \is_array($result):
                foreach ($result as &$value) {
                    $value = static::escapeFunction($value);
                }

                $result = implode(', ', $result) ?: 'NULL';

                break;

            case \is_object($result) && method_exists($result, '__toString'):
                $result = addslashes((string) $result->__toString());

                break;

            
$parameters = [
            [],
        ];

        $result = $extension->replaceQueryParameters($query$parameters);
        static::assertEquals('IN (NULL)', $result);
    }

    public function testEscapeBinaryParameter(): void
    {
        $binaryString = pack('H*', '9d40b8c1417f42d099af4782ec4b20b6');
        static::assertEquals('0x9D40B8C1417F42D099AF4782EC4B20B6', DoctrineExtension::escapeFunction($binaryString));
    }

    public function testEscapeStringParameter(): void
    {
        static::assertEquals('\'test string\'', DoctrineExtension::escapeFunction('test string'));
    }

    public function testEscapeArrayParameter(): void
    {
        static::assertEquals('1, NULL, \'test\', foo, NULL', DoctrineExtension::escapeFunction([1, null, 'test', new DummyClass('foo')[]]));
    }

    
Home | Imprint | This part of the site doesn't use cookies.