Skip to content

Commit

Permalink
Test Field
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Apr 24, 2022
1 parent b140edf commit 9588831
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Result/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function setTypeName() : void
\MYSQLI_TYPE_FLOAT => 'float',
\MYSQLI_TYPE_GEOMETRY => 'geometry',
\MYSQLI_TYPE_INT24 => 'int24',
\MYSQLI_TYPE_INTERVAL => 'interval', // @phpstan-ignore-line
//\MYSQLI_TYPE_INTERVAL => 'interval',
\MYSQLI_TYPE_JSON => 'json',
\MYSQLI_TYPE_LONG => 'long',
\MYSQLI_TYPE_LONG_BLOB => 'long_blob',
Expand All @@ -132,7 +132,7 @@ protected function setTypeName() : void
\MYSQLI_TYPE_STRING => 'string',
\MYSQLI_TYPE_TIME => 'time',
\MYSQLI_TYPE_TIMESTAMP => 'timestamp',
\MYSQLI_TYPE_TINY => 'tiny', // @phpstan-ignore-line
//\MYSQLI_TYPE_TINY => 'tiny',
\MYSQLI_TYPE_TINY_BLOB => 'tiny_blob',
\MYSQLI_TYPE_VAR_STRING => 'var_string',
\MYSQLI_TYPE_YEAR => 'year',
Expand Down
71 changes: 71 additions & 0 deletions tests/Result/FieldTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php declare(strict_types=1);
/*
* This file is part of Aplus Framework Database Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests\Database\Result;

use Framework\Database\Result\Field;
use PHPUnit\Framework\TestCase;

final class FieldTest extends TestCase
{
/**
* @return array<array<mixed>>
*/
public function typeProvider() : array
{
return [
[\MYSQLI_TYPE_BIT, 'bit'],
[\MYSQLI_TYPE_BLOB, 'blob'],
[\MYSQLI_TYPE_CHAR, 'char'],
[\MYSQLI_TYPE_DATE, 'date'],
[\MYSQLI_TYPE_DATETIME, 'datetime'],
[\MYSQLI_TYPE_DECIMAL, 'decimal'],
[\MYSQLI_TYPE_DOUBLE, 'double'],
[\MYSQLI_TYPE_ENUM, 'enum'],
[\MYSQLI_TYPE_FLOAT, 'float'],
[\MYSQLI_TYPE_GEOMETRY, 'geometry'],
[\MYSQLI_TYPE_INT24, 'int24'],
//[\MYSQLI_TYPE_INTERVAL, 'interval'],
[\MYSQLI_TYPE_JSON, 'json'],
[\MYSQLI_TYPE_LONG, 'long'],
[\MYSQLI_TYPE_LONG_BLOB, 'long_blob'],
[\MYSQLI_TYPE_LONGLONG, 'longlong'],
[\MYSQLI_TYPE_MEDIUM_BLOB, 'medium_blob'],
[\MYSQLI_TYPE_NEWDATE, 'newdate'],
[\MYSQLI_TYPE_NEWDECIMAL, 'newdecimal'],
[\MYSQLI_TYPE_NULL, 'null'],
[\MYSQLI_TYPE_SET, 'set'],
[\MYSQLI_TYPE_SHORT, 'short'],
[\MYSQLI_TYPE_STRING, 'string'],
[\MYSQLI_TYPE_TIME, 'time'],
[\MYSQLI_TYPE_TIMESTAMP, 'timestamp'],
//[\MYSQLI_TYPE_TINY, 'tiny'],
[\MYSQLI_TYPE_TINY_BLOB, 'tiny_blob'],
[\MYSQLI_TYPE_VAR_STRING, 'var_string'],
[\MYSQLI_TYPE_YEAR, 'year'],
[-1, null],
];
}

/**
* @param int $type
* @param string|null $typeName
*
* @dataProvider typeProvider
*/
public function testType(int $type, ?string $typeName) : void
{
$object = new \stdClass();
$object->flags = $type;
$object->type = $type;
$field = new Field($object);
self::assertSame($type, $field->type);
self::assertSame($typeName, $field->typeName);
}
}

0 comments on commit 9588831

Please sign in to comment.