Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Tests\Unit\MartinGeorgiev\Doctrine\DBAL\Types;

use Doctrine\DBAL\Types\ConversionException;
use MartinGeorgiev\Doctrine\DBAL\Types\BaseFloatArray;
use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidFloatArrayItemForPHPException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -64,7 +64,7 @@ abstract public static function provideValidTransformations(): array;
#[Test]
public function throws_domain_exception_when_invalid_array_item_value(): void
{
$this->expectException(ConversionException::class);
$this->expectException(InvalidFloatArrayItemForPHPException::class);
$this->expectExceptionMessage('cannot be transformed to valid PHP float');

$this->fixture->transformArrayItemForPHP('1.e234');
Expand Down
33 changes: 33 additions & 0 deletions tests/Unit/MartinGeorgiev/Doctrine/DBAL/Types/PointArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,37 @@ public function returns_empty_array_for_non_standard_postgres_array_format(): vo
self::assertEquals([], $result1);
self::assertEquals([], $result2);
}

#[Test]
public function transform_array_item_for_php_returns_null_for_null(): void
{
$this->assertNull($this->fixture->transformArrayItemForPHP(null));
}

#[Test]
#[DataProvider('provideInvalidTypes')]
public function transform_array_item_for_php_throws_for_invalid_type(mixed $value): void
{
$this->expectException(InvalidPointArrayItemForPHPException::class);
$this->fixture->transformArrayItemForPHP($value);
}

#[Test]
#[DataProvider('provideInvalidTypes')]
public function transform_postgres_array_to_php_array_returns_empty_for_invalid_format(mixed $value): void
{
$reflectionObject = new \ReflectionObject($this->fixture);
$reflectionMethod = $reflectionObject->getMethod('transformPostgresArrayToPHPArray');
$reflectionMethod->setAccessible(true);
$this->assertSame([], $reflectionMethod->invoke($this->fixture, $value));
}

public static function provideInvalidTypes(): array
{
return [
[123],
['not-a-point-instance'],
['{invalid}'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\AST\Node;
use Doctrine\ORM\Query\Parser;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseVariadicFunction;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\InvalidArgumentForVariadicFunctionException;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Exception\ParserException;
use PHPUnit\Framework\Attributes\Test;

Expand Down Expand Up @@ -38,4 +40,70 @@ public function throws_an_exception_when_lexer_is_not_populated_with_a_lookahead
$reflectionMethod->setAccessible(true);
$reflectionMethod->invoke($baseVariadicFunction, $parser, 'ArithmeticPrimary');
}

#[Test]
public function throws_exception_when_argument_count_is_too_low(): void
{
$function = new class('TEST') extends BaseVariadicFunction {
protected function getFunctionName(): string
{
return 'TEST';
}

protected function getNodeMappingPattern(): array
{
return ['StringPrimary'];
}

protected function getMinArgumentCount(): int
{
return 2;
}

protected function getMaxArgumentCount(): int
{
return 3;
}
};
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$reflectionClass = new \ReflectionClass($function);
$reflectionMethod = $reflectionClass->getMethod('validateArguments');
$reflectionMethod->setAccessible(true);

$node = $this->createMock(Node::class);
$reflectionMethod->invoke($function, $node); // No arguments
}

#[Test]
public function throws_exception_when_argument_count_is_too_high(): void
{
$function = new class('TEST') extends BaseVariadicFunction {
protected function getFunctionName(): string
{
return 'TEST';
}

protected function getNodeMappingPattern(): array
{
return ['StringPrimary'];
}

protected function getMinArgumentCount(): int
{
return 1;
}

protected function getMaxArgumentCount(): int
{
return 2;
}
};
$this->expectException(InvalidArgumentForVariadicFunctionException::class);
$reflectionClass = new \ReflectionClass($function);
$reflectionMethod = $reflectionClass->getMethod('validateArguments');
$reflectionMethod->setAccessible(true);

$node = $this->createMock(Node::class);
$reflectionMethod->invoke($function, $node, $node, $node);
}
}
Loading