PHP Classes

File: tests/EmulatePreparesDisabledTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   EasyDB   tests/EmulatePreparesDisabledTest.php   Download  
File: tests/EmulatePreparesDisabledTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: EasyDB
Simple Database Abstraction Layer around PDO
Author: By
Last change: squishing line length style errors introduced in previous commit
squishing error regarding default values
manually changing to squish "method name is not in camel caps format" style error
single-lining test classes after composer run fix-style
running composer run fix-style
Date: 6 years ago
Size: 1,757 bytes
 

Contents

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

namespace
ParagonIE\EasyDB\Tests;

use
ParagonIE\EasyDB\Factory;
use
PDO;
use
PDOException;

class
EmulatePreparesDisabledTest extends EasyDBTest
{

   
/**
     * @dataProvider goodFactoryCreateArgumentProvider
     * @param $dsn
     * @param null $username
     * @param null $password
     * @param array $options
     */
   
public function testEmulatePreparesDisabled(
       
$expectedDriver,
       
$dsn,
       
$username = null,
       
$password = null,
       
$options = []
    ) {
       
$db = Factory::create($dsn, $username, $password, $options);
       
$recheckWithForcedFalse = false;
        try {
           
$this->assertFalse($db->getPdo()->getAttribute(PDO::ATTR_EMULATE_PREPARES));
           
$recheckWithForcedFalse = true;
        } catch (
PDOException $e) {
           
$this->assertStringEndsWith(
               
': Driver does not support this function: driver does not support that attribute',
               
$e->getMessage()
            );
        }

       
$options[PDO::ATTR_EMULATE_PREPARES] = true;
       
$db = Factory::create($dsn, $username, $password, $options);
        try {
           
$this->assertFalse($db->getPdo()->getAttribute(PDO::ATTR_EMULATE_PREPARES));
        } catch (
PDOException $e) {
           
$this->assertStringEndsWith(
               
': Driver does not support this function: driver does not support that attribute',
               
$e->getMessage()
            );
        }

        if (
$recheckWithForcedFalse) {
           
$options[PDO::ATTR_EMULATE_PREPARES] = false;
           
$db = Factory::create($dsn, $username, $password, $options);
           
$this->assertFalse($db->getPdo()->getAttribute(PDO::ATTR_EMULATE_PREPARES));
        }
    }
}