PHP Classes

File: tests/CellTest.php

Recommend this page to a friend!
  Packages of Scott Arciszewski   EasyDB   tests/CellTest.php   Download  
File: tests/CellTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: EasyDB
Simple Database Abstraction Layer around PDO
Author: By
Last change: Test Improvements + Mutation Testing (#168)

* Update testing frameworks
* Add infection for mutation tests
* Modernize PHPUnit usage
Date: 2 months ago
Size: 1,950 bytes
 

Contents

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

namespace
ParagonIE\EasyDB\Tests;

use
ParagonIE\EasyDB\EasyDB;
use
ParagonIE\EasyDB\Factory;
use
PHPUnit\Framework\Attributes\CoversClass;
use
PHPUnit\Framework\Attributes\DataProvider;

#[CoversClass(EasyDB::class)]
#[CoversClass(Factory::class)]
class CellTest extends ColTest
{
    public static function
goodColArguments(): array
    {
        return [
            [
               
'SELECT 1 AS foo', 0, [], [1]
            ],
            [
               
'SELECT 1 AS foo, 2 AS bar', 0, [], [1]
            ],
            [
               
'SELECT 1 AS foo, 2 AS bar', 1, [], [1]
            ],
            [
               
'SELECT 1 AS foo, 2 AS bar UNION SELECT 3 AS foo, 4 AS bar', 0, [], [1]
            ],
            [
               
'SELECT 1 AS foo, 2 AS bar UNION SELECT 3 AS foo, 4 AS bar', 1, [], [1]
            ],
            [
               
'SELECT ? AS foo, ? AS bar UNION SELECT ? AS foo, ? AS bar', 0, [1, 2, 3, 4], [1]
            ],
            [
               
'SELECT ? AS foo, ? AS bar UNION SELECT ? AS foo, ? AS bar', 1, [1, 2, 3, 4], [1]
            ]
        ];
    }


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

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

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

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

       
$this->assertEquals([], array_diff_assoc([$result], [$expectedResult[0]]));
    }
}