Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

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

use PHPUnit\Framework\Attributes\Test;

abstract class ArrayTypeTestCase extends TestCase
{
#[Test]
public function can_handle_empty_array(): void
{
$typeName = $this->getTypeName();
$columnType = $this->getPostgresTypeName();

$this->runTypeTest($typeName, $columnType, []);
}

#[Test]
public function can_handle_null_values(): void
{
$typeName = $this->getTypeName();
$columnType = $this->getPostgresTypeName();

$this->runTypeTest($typeName, $columnType, null);
}

/**
* Data-driven test for array values.
* Subclasses should add #[DataProvider('provideValidTransformations')].
*/
public function can_handle_array_values(string $testName, array $arrayValue): void
{
$typeName = $this->getTypeName();
$columnType = $this->getPostgresTypeName();

$this->runTypeTest($typeName, $columnType, $arrayValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

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

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

class BigIntArrayTypeTest extends ArrayTypeTestCase
{
protected function getTypeName(): string
{
return 'bigint[]';
}

protected function getPostgresTypeName(): string
{
return 'BIGINT[]';
}

#[DataProvider('provideValidTransformations')]
#[Test]
public function can_handle_array_values(string $testName, array $arrayValue): void
{
parent::can_handle_array_values($testName, $arrayValue);
}

/**
* @return array<string, array{string, array<int, int>}>
*/
public static function provideValidTransformations(): array
{
return [
'simple bigint array' => ['simple bigint array', [9223372036854775807, 1, -9223372036854775807]],
'bigint array with zeros' => ['bigint array with zeros', [0, 0, 0, 1, 0]],
'bigint array with large numbers' => ['bigint array with large numbers', [1000000000000, 2000000000000, 3000000000000]],
'bigint array with negative numbers' => ['bigint array with negative numbers', [-1000000000000, -2000000000000, -3000000000000]],
'bigint array with PHP max and min integer constants' => ['bigint array with PHP max and min integer constants', [PHP_INT_MAX, PHP_INT_MIN, 0]],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

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

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

class BooleanArrayTypeTest extends ArrayTypeTestCase
{
protected function getTypeName(): string
{
return 'bool[]';
}

protected function getPostgresTypeName(): string
{
return 'BOOL[]';
}

#[DataProvider('provideValidTransformations')]
#[Test]
public function can_handle_array_values(string $testName, array $arrayValue): void
{
parent::can_handle_array_values($testName, $arrayValue);
}

/**
* @return array<string, array{string, array<int, bool>}>
*/
public static function provideValidTransformations(): array
{
return [
'simple boolean array' => ['simple boolean array', [true, false, true]],
'boolean array with all true' => ['boolean array with all true', [true, true, true]],
'boolean array with all false' => ['boolean array with all false', [false, false, false]],
'boolean array mixed' => ['boolean array mixed', [true, false, true, false, true]],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

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

use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidCidrArrayItemForPHPException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

class CidrArrayTypeTest extends ArrayTypeTestCase
{
protected function getTypeName(): string
{
return 'cidr[]';
}

protected function getPostgresTypeName(): string
{
return 'CIDR[]';
}

#[DataProvider('provideValidTransformations')]
#[Test]
public function can_handle_array_values(string $testName, array $arrayValue): void
{
parent::can_handle_array_values($testName, $arrayValue);
}

/**
* @return array<string, array{string, array<int, string>}>
*/
public static function provideValidTransformations(): array
{
return [
'simple cidr array' => ['simple cidr array', ['192.168.1.0/24', '10.0.0.0/8']],
'cidr array with IPv6' => ['cidr array with IPv6', ['2001:db8::/32', '2001:db8::/64']],
'cidr array with mixed networks' => ['cidr array with mixed networks', [
'192.168.1.0/24',
'172.16.0.0/16',
'10.0.0.0/8',
'2001:db8::/32',
]],
'cidr array with single hosts' => ['cidr array with single hosts', [
'192.168.1.1/32',
'10.0.0.1/32',
'2001:db8::1/128',
]],
'empty cidr array' => ['empty cidr array', []],
];
}

#[Test]
public function can_handle_invalid_networks(): void
{
$this->expectException(InvalidCidrArrayItemForPHPException::class);

$typeName = $this->getTypeName();
$columnType = $this->getPostgresTypeName();

$this->runTypeTest($typeName, $columnType, ['invalid-network', '192.168.1.0/24']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

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

use MartinGeorgiev\Doctrine\DBAL\Types\Exceptions\InvalidCidrForPHPException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;

class CidrTypeTest extends ScalarTypeTestCase
{
protected function getTypeName(): string
{
return 'cidr';
}

protected function getPostgresTypeName(): string
{
return 'CIDR';
}

#[DataProvider('provideValidTransformations')]
#[Test]
public function can_transform_from_php_value(string $testValue): void
{
$typeName = $this->getTypeName();
$columnType = $this->getPostgresTypeName();

$this->runTypeTest($typeName, $columnType, $testValue);
}

/**
* @return array<string, array{string}>
*/
public static function provideValidTransformations(): array
{
return [
'IPv4 CIDR' => ['192.168.1.0/24'],
'IPv4 CIDR /8' => ['10.0.0.0/8'],
'IPv4 CIDR /16' => ['172.16.0.0/16'],
'IPv6 CIDR' => ['2001:db8::/32'],
'IPv6 CIDR /64' => ['2001:db8::/64'],
'IPv6 CIDR /128' => ['2001:db8::1/128'],
];
}

#[Test]
public function can_handle_invalid_networks(): void
{
$this->expectException(InvalidCidrForPHPException::class);

$typeName = $this->getTypeName();
$columnType = $this->getPostgresTypeName();

$this->runTypeTest($typeName, $columnType, 'invalid-network');
}
}
Loading
Loading