<?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
);
}
}
|