PHP Classes

File: tests/RunTest.php

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

Contents

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

namespace
ParagonIE\EasyDB\Tests;

use
ParagonIE\EasyDB\EasyDB;

class
RunTest extends ColTest
{
    protected function
goodColArguments()
    {
        return [
            [
               
'SELECT 1 AS foo', 0, [], [['foo' => 1]]
            ],
            [
               
'SELECT 1 AS foo, 2 AS bar', 0, [], [['foo' => 1, 'bar' => 2]]
            ],
            [
               
'SELECT 1 AS foo, 2 AS bar UNION SELECT 3 AS foo, 4 AS bar',
               
0,
                [],
                [[
'foo' => 1, 'bar' => 2], ['foo' => 3, 'bar' => 4]],
            ],
            [
               
'SELECT ? AS foo, ? AS bar UNION SELECT ? AS foo, ? AS bar',
               
0,
                [
1, 2, 3, 4],
                [[
'foo' => 1, 'bar' => 2], ['foo' => 3, 'bar' => 4]],
            ],
        ];
    }


    protected function
getResultForMethod(EasyDB $db, $statement, $offset, $params)
    {
       
$args = $params;
       
array_unshift($args, $statement);

        return
call_user_func_array([$db, 'run'], $args);
    }

   
/**
     * @dataProvider goodColArgumentsProvider
     * @param callable $cb
     * @param string $statement
     * @param int $offset
     * @param array $params
     * @param array $expectedResult
     */
   
public function testMethod(callable $cb, $statement, $offset, $params, $expectedResult)
    {
       
$db = $this->easyDBExpectedFromCallable($cb);

       
$results = $this->getResultForMethod($db, $statement, $offset, $params);

        foreach (
$results as $i => $result) {
           
$this->assertEquals(array_diff_assoc($result, $expectedResult[$i]), []);
        }
    }
}