PHP Classes

File: tests/SingleTestThenExistsTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   EasyDB   tests/SingleTestThenExistsTest.php   Download  
File: tests/SingleTestThenExistsTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: EasyDB
Simple Database Abstraction Layer around PDO
Author: By
Last change: 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: 2,324 bytes
 

Contents

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

namespace
ParagonIE\EasyDB\Tests;

use
ParagonIE\EasyDB\EasyDB;

class
SingleTestThenExistsTest extends EasyDBWriteTest
{
    protected function
getResultForMethod(EasyDB $db, $statement, $params)
    {
       
$args = $params;
       
array_unshift($args, $statement);
        return
call_user_func_array([$db, 'exists'], $args);
    }

   
/**
     * @dataProvider goodFactoryCreateArgument2EasyDBInsertManyProvider
     * @depends ParagonIE\EasyDB\Tests\Is1DArrayThenDeleteReadOnlyTest::testDeleteThrowsException
     * @depends ParagonIE\EasyDB\Tests\Is1DArrayThenDeleteReadOnlyTest::testDeleteTableNameEmptyThrowsException
     * @depends ParagonIE\EasyDB\Tests\Is1DArrayThenDeleteReadOnlyTest::testDeleteTableNameInvalidThrowsException
     * @depends ParagonIE\EasyDB\Tests\Is1DArrayThenDeleteReadOnlyTest::testDeleteConditionsReturnsNull
     * @depends ParagonIE\EasyDB\Tests\InsertManyTest::testInsertMany
     * @depends ParagonIE\EasyDB\Tests\SingleTest::testMethod
     * @param callable $cb
     * @param array $insertMany
     */
   
public function testExists(callable $cb, array $insertMany)
    {
       
$db = $this->easyDBExpectedFromCallable($cb);
       
$this->assertFalse(
           
$db->exists('SELECT COUNT(*) FROM irrelevant_but_valid_tablename')
        );
       
$db->insertMany('irrelevant_but_valid_tablename', $insertMany);
       
$this->assertTrue(
           
$db->exists('SELECT COUNT(*) FROM irrelevant_but_valid_tablename')
        );
        foreach (
$insertMany as $insertVal) {
           
$this->assertTrue(
               
$this->getResultForMethod(
                   
$db,
                   
'SELECT COUNT(*) FROM irrelevant_but_valid_tablename WHERE foo = ?',
                   
array_values($insertVal)
                )
            );
           
$db->delete('irrelevant_but_valid_tablename', $insertVal);
           
$this->assertFalse(
               
$this->getResultForMethod(
                   
$db,
                   
'SELECT COUNT(*) FROM irrelevant_but_valid_tablename WHERE foo = ?',
                   
array_values($insertVal)
                )
            );
        }
       
$this->assertFalse(
           
$db->exists('SELECT COUNT(*) FROM irrelevant_but_valid_tablename')
        );
    }
}