PHP Classes

File: tests/InsertManyTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   EasyDB   tests/InsertManyTest.php   Download  
File: tests/InsertManyTest.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,618 bytes
 

Contents

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

namespace
ParagonIE\EasyDB\Tests;

use
InvalidArgumentException;
use
ParagonIE\EasyDB\Exception\InvalidIdentifier;
use
ParagonIE\EasyDB\Exception\MustBeOneDimensionalArray;
use
PDOException;

class
InsertManyTest extends EasyDBWriteTest
{

   
/**
     * @dataProvider goodFactoryCreateArgument2EasyDBProvider
     * @param callable $cb
     */
   
public function testInsertManyNoFieldsThrowsException(callable $cb)
    {
       
$db = $this->easyDBExpectedFromCallable($cb);
       
$this->expectException(InvalidArgumentException::class);
       
$this->assertFalse($db->insertMany('irrelevant_but_valid_tablename', []));
    }

   
/**
     * @dataProvider goodFactoryCreateArgument2EasyDBProvider
     * @param callable $cb
     */
   
public function testInsertManyNoFieldsThrowsPdoException(callable $cb)
    {
       
$db = $this->easyDBExpectedFromCallable($cb);
       
$this->expectException(PDOException::class);
       
$db->insertMany('irrelevant_but_valid_tablename', [[], [1]]);
    }

   
/**
     * @dataProvider goodFactoryCreateArgument2EasyDBProvider
     * @param callable $cb
     */
   
public function testInsertManyArgTableThrowsException(callable $cb)
    {
       
$db = $this->easyDBExpectedFromCallable($cb);
       
$this->expectException(InvalidIdentifier::class);
       
$db->insertMany('', [['foo' => 1], ['foo' => 2]]);
    }

   
/**
     * @dataProvider goodFactoryCreateArgument2EasyDBProvider
     * @param callable $cb
     */
   
public function testInsertManyArgMapKeysThrowsException(callable $cb)
    {
       
$db = $this->easyDBExpectedFromCallable($cb);
       
$this->expectException(InvalidIdentifier::class);
       
$db->insertMany('irrelevant_but_valid_tablename', [['1foo' => 1]]);
    }

   
/**
     * @dataProvider goodFactoryCreateArgument2EasyDBProvider
     * @param callable $cb
     */
   
public function testInsertManyArgMapIs1DArrayThrowsException(callable $cb)
    {
       
$db = $this->easyDBExpectedFromCallable($cb);
       
$this->expectException(MustBeOneDimensionalArray::class);
       
$db->insertMany('irrelevant_but_valid_tablename', [['foo' => [1]]]);
    }

   
/**
     * @dataProvider goodFactoryCreateArgument2EasyDBProvider
     * @param callable $cb
     */
   
public function testInsertMany(callable $cb)
    {
       
$db = $this->easyDBExpectedFromCallable($cb);
       
$db->insertMany('irrelevant_but_valid_tablename', [['foo' => '1'], ['foo' => '2']]);
       
$this->assertEquals(
           
$db->single('SELECT COUNT(*) FROM irrelevant_but_valid_tablename'),
           
2
       
);
    }
}