PHP Classes

File: tests/EscapeLikeTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   EasyDB   tests/EscapeLikeTest.php   Download  
File: tests/EscapeLikeTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: EasyDB
Simple Database Abstraction Layer around PDO
Author: By
Last change: Merge pull request #32 from paragonie/feature/insert-query-builder

Add method to build an INSERT query
Merge pull request #27 from paragonie/fix/psr2-compat

Comply with PSR-2 code style
Date: 7 years ago
Size: 1,628 bytes
 

Contents

Class file image Download
<?php
declare (strict_types=1);

namespace
ParagonIE\EasyDB\Tests;

use
ParagonIE\EasyDB\EasyDB;
use
PDO;

class
EscapeLikeTest extends EasyDBTest
{
    public function
dataValues()
    {
        return [
           
// input, expected
           
['plain', 'plain'],
            [
'%single', '\\%single'],
            [
'%double%', '\\%double\\%'],
            [
'_under_score_', '\\_under\\_score\\_'],
            [
'%mix_ed', '\\%mix\\_ed'],
            [
'\\%escaped?', '\\\\\\%escaped?'],
        ];
    }

   
/**
     * @dataProvider dataValues
     */
   
public function testEscapeLike($input, $expected)
    {
       
// This defines sqlite, but mysql and postgres share the same rules
       
$easydb = new EasyDB($this->getMockPDO(), 'sqlite');

       
$output = $easydb->escapeLikeValue($input);

       
$this->assertSame($expected, $output);
    }

    public function
dataMSSQLValues()
    {
        return
array_merge($this->dataValues(), [
           
// input, expected
           
['[range]', '\\[range\\]'],
            [
'[^negated]', '\\[^negated\\]'],
        ]);
    }
   
/**
     * @dataProvider dataMSSQLValues
     */
   
public function testMSSQLEscapeLike($input, $expected)
    {
       
$easydb = new EasyDB($this->getMockPDO(), 'mssql');

       
$output = $easydb->escapeLikeValue($input);

       
$this->assertSame($expected, $output);
    }

    private function
getMockPDO(): PDO
   
{
       
$mock = $this->getMockBuilder(PDO::class)
            ->
disableOriginalConstructor()
            ->
getMock();

       
$mock->method('setAttribute')->willReturn(true);

        return
$mock;
    }
}