PHP Classes

File: tests/Is1DArrayTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   EasyDB   tests/Is1DArrayTest.php   Download  
File: tests/Is1DArrayTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: EasyDB
Simple Database Abstraction Layer around PDO
Author: By
Last change: Refactoring

- Change exceptions to extend the same base class
- Update code style to avoid \\ prefixes (use imports instead)
Date: 1 year ago
Size: 2,524 bytes
 

Contents

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

namespace
ParagonIE\EasyDB\Tests;

use
InvalidArgumentException;
use
ParagonIE\EasyDB\Exception\MustBeOneDimensionalArray;
use
ParagonIE\EasyDB\Factory;

class
Is1DArrayTest extends EasyDBTest
{

   
/**
     * @dataProvider goodFactoryCreateArgumentProvider
     * @param $dsn
     * @param null $username
     * @param null $password
     * @param array $options
     */
   
public function testIs1DArray($expectedDriver, $dsn, $username = null, $password = null, $options = [])
    {
       
$db = Factory::create($dsn, $username, $password, $options);
       
$this->assertTrue($db->is1DArray([]));
       
$this->assertFalse($db->is1DArray([[]]));
       
$this->assertFalse($db->is1DArray([[], []]));
       
$this->assertTrue($db->is1DArray([1]));
       
$this->assertFalse($db->is1DArray([[1]]));
       
$this->assertFalse($db->is1DArray([[1], [2]]));
    }

   
/**
     * @dataProvider goodFactoryCreateArgumentProvider
     * @depends testIs1DArray
     * @param $dsn
     * @param null $username
     * @param null $password
     * @param array $options
     */
   
public function testColumnThrowsException($expectedDriver, $dsn, $username = null, $password = null, $options = [])
    {
       
$db = Factory::create($dsn, $username, $password, $options);
       
$this->expectException(MustBeOneDimensionalArray::class);
       
$db->column('SELECT "column"', [[1]]);
    }

   
/**
     * @dataProvider goodFactoryCreateArgumentProvider
     * @depends testIs1DArray
     * @param $dsn
     * @param null $username
     * @param null $password
     * @param array $options
     */
   
public function testSafeQueryThrowsException(
       
$expectedDriver,
       
$dsn,
       
$username = null,
       
$password = null,
       
$options = []
    ) {
       
$db = Factory::create($dsn, $username, $password, $options);
       
$this->expectException(MustBeOneDimensionalArray::class);
       
$db->safeQuery('SELECT ?', [[1]]);
    }

   
/**
     * @dataProvider goodFactoryCreateArgumentProvider
     * @depends testIs1DArray
     * @param $dsn
     * @param null $username
     * @param null $password
     * @param array $options
     */
   
public function testSingleThrowsException($expectedDriver, $dsn, $username = null, $password = null, $options = [])
    {
       
$db = Factory::create($dsn, $username, $password, $options);
       
$this->expectException(MustBeOneDimensionalArray::class);
       
$db->single('SELECT "column"', [[1]]);
    }
}