Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pvsaintpe committed May 1, 2024
1 parent 422e83d commit 2c37e6e
Show file tree
Hide file tree
Showing 25 changed files with 241 additions and 859 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ jobs:
operating_system:
- ubuntu-latest
php_versions:
- '8.0'
- '8.1'
- '8.2'
- '8.3'
fail-fast: false
env:
Expand Down Expand Up @@ -85,27 +82,21 @@ jobs:
exclude_group: ['WithSchema']
experimental: [false]
operating_system: [ubuntu-latest]
postgres: ['10', '11', '12', '13']
php_versions: ['8.0']
phpunit_command: [--help]
postgres: ['10', '11', '12', '13', '14']
php_versions: ['8.3']
phpunit_command: [-c phpunit.xml --migrate-configuration]
include:
- operating_system: 'ubuntu-latest'
php_versions: '8.1'
postgres: '14'
coverage: false
experimental: false
phpunit_command: -c phpunit.xml --migrate-configuration
- operating_system: 'ubuntu-latest'
php_versions: '8.2'
php_versions: '8.3'
postgres: '15'
coverage: false
experimental: false
experimental: true
phpunit_command: -c phpunit.xml --migrate-configuration
- operating_system: 'ubuntu-latest'
php_versions: '8.2'
php_versions: '8.4'
postgres: '16'
coverage: false
experimental: false
experimental: true
phpunit_command: -c phpunit.xml --migrate-configuration
runs-on: '${{ matrix.operating_system }}'
services:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
.ecs_cache
phpunit.xml
.phpunit.result.cache
.phpunit.cache
composer.lock
/build
14 changes: 14 additions & 0 deletions .run/Functional.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Functional" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<CommandLine parameters="-d memory_limit=-1">
<PhpTestInterpreterSettings>
<option name="interpreterName" value="PHP 8.3" />
</PhpTestInterpreterSettings>
<envs>
<env name="XDEBUG.MODE" value="coverage" />
</envs>
</CommandLine>
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml" directory="$PROJECT_DIR$/tests/Functional" use_alternative_configuration_file="true" />
<method v="2" />
</configuration>
</component>
14 changes: 14 additions & 0 deletions .run/Tests .run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Tests " type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<CommandLine parameters="-d memory_limit=-1">
<PhpTestInterpreterSettings>
<option name="interpreterName" value="PHP 8.3" />
</PhpTestInterpreterSettings>
<envs>
<env name="XDEBUG.MODE" value="coverage" />
</envs>
</CommandLine>
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml" directory="$PROJECT_DIR$/tests" use_alternative_configuration_file="true" />
<method v="2" />
</configuration>
</component>
14 changes: 14 additions & 0 deletions .run/Unit.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Unit" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
<CommandLine parameters="-d memory_limit=-1">
<PhpTestInterpreterSettings>
<option name="interpreterName" value="PHP 8.3" />
</PhpTestInterpreterSettings>
<envs>
<env name="XDEBUG.MODE" value="coverage" />
</envs>
</CommandLine>
<TestRunner configuration_file="$PROJECT_DIR$/phpunit.xml" directory="$PROJECT_DIR$/tests/Unit" use_alternative_configuration_file="true" />
<method v="2" />
</configuration>
</component>
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
},
"require": {
"ext-pdo": "*",
"php": "^8.0|^8.1|^8.2|^8.3",
"doctrine/dbal": "^2.9|^3.0",
"laravel/framework": "^8.0|^9.0|^10.0|^11.0"
"php": "^8.3|^8.4",
"doctrine/dbal": "3.6.*",
"laravel/framework": "^11.0"
},
"require-dev": {
"umbrellio/code-style-php": "^1.0",
"orchestra/testbench": "^3.5|^4.0|^5.0|^6.0|^7.0|^8.0|^9.0",
"php-coveralls/php-coveralls": "^2.1|^2.7",
"codeception/codeception": "^3.0|^4.0|^5.0",
"phpunit/phpunit": "^9.6|^10.0"
"orchestra/testbench": "^9.0",
"php-coveralls/php-coveralls": "^2.7",
"codeception/codeception": "^5.0",
"phpunit/phpunit": "^11.0"
},
"scripts": {
"lint": [
Expand Down
38 changes: 38 additions & 0 deletions phpunit.xml.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage processUncoveredFiles="true" pathCoverage="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./src/.meta.php</file>
</exclude>
<report>
<clover outputFile="build/logs/clover.xml" />
</report>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
<ini name="error_reporting" value="-1" />
<var name="db_type" value="pdo_pgsql"/>
<var name="db_host" value="127.0.0.1" />
<var name="db_username" value="postgres" />
<var name="db_password" value="" />
<var name="db_database" value="testing" />
<var name="db_port" value="5432"/>
</php>
<testsuites>
<testsuite name="Test suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
</phpunit>
44 changes: 24 additions & 20 deletions src/PostgresConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

use DateTimeInterface;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Illuminate\Database\PostgresConnection as BasePostgresConnection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Traits\Macroable;
use PDO;
use Umbrellio\Postgres\Extensions\AbstractExtension;
use Umbrellio\Postgres\Extensions\Exceptions\ExtensionInvalidException;
use Umbrellio\Postgres\Schema\Builder;
use Umbrellio\Postgres\Schema\Grammars\PostgresGrammar;
use Umbrellio\Postgres\Schema\Subscribers\SchemaAlterTableChangeColumnSubscriber;
use Umbrellio\Postgres\Schema\Types\NumericType;
use Umbrellio\Postgres\Schema\Types\TsRangeType;
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
Expand Down Expand Up @@ -68,9 +68,13 @@ public function useDefaultPostProcessor(): void

public function getDoctrineConnection(): Connection
{
$doctrineConnection = parent::getDoctrineConnection();
$this->overrideDoctrineBehavior($doctrineConnection);
return $doctrineConnection;
return DriverManager::getConnection($this->getConfig());
}

public function getDatabasePlatform(): AbstractPlatform
{
return $this->getDoctrineConnection()
->getDatabasePlatform();
}

public function bindValues($statement, $bindings)
Expand Down Expand Up @@ -124,7 +128,13 @@ protected function getDefaultSchemaGrammar()
private function registerInitialTypes(): void
{
foreach ($this->initialTypes as $type => $typeClass) {
DB::registerDoctrineType($typeClass, $type, $type);
if (! Type::hasType($type)) {
Type::addType($type, $typeClass);
} else {
$this
->getDatabasePlatform()
->registerDoctrineTypeMapping($typeClass, $type);
}
}
}

Expand All @@ -137,20 +147,14 @@ private function registerExtensions(): void
/** @var AbstractExtension $extension */
$extension::register();
foreach ($extension::getTypes() as $type => $typeClass) {
DB::registerDoctrineType($typeClass, $type, $type);
if (! Type::hasType($type)) {
Type::addType($type, $typeClass);
} else {
$this
->getDatabasePlatform()
->registerDoctrineTypeMapping($typeClass, $type);
}
}
});
}

private function overrideDoctrineBehavior(Connection $connection): Connection
{
$eventManager = $connection->getEventManager();
if (! $eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) {
$eventManager->addEventSubscriber(new SchemaAlterTableChangeColumnSubscriber());
}
$connection
->getDatabasePlatform()
->setEventManager($eventManager);
return $connection;
}
}
5 changes: 4 additions & 1 deletion src/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Umbrellio\Postgres\Schema;

use Doctrine\DBAL\DriverManager;
use Illuminate\Database\Schema\Blueprint as BaseBlueprint;
use Illuminate\Database\Schema\ColumnDefinition;
use Illuminate\Support\Facades\Schema;
Expand Down Expand Up @@ -167,7 +168,9 @@ public function daterange(string $column): Fluent

protected function getSchemaManager()
{
return Schema::getConnection()->getDoctrineSchemaManager();
$connection = Schema::getConnection();
$doctrineConnection = DriverManager::getConnection($connection->getConfig());
return $doctrineConnection->getSchemaManager();
}

private function addExtendedCommand(string $fluent, string $name, array $parameters = []): Fluent
Expand Down
10 changes: 5 additions & 5 deletions src/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function compileDetachPartition(Blueprint $blueprint, Fluent $command): s
);
}

public function compileCreateView(/** @scrutinizer ignore-unused */ Blueprint $blueprint, Fluent $command): string
public function compileCreateView(Blueprint $blueprint, Fluent $command): string
{
$materialize = $command->get('materialize') ? 'materialized' : '';
return implode(' ', array_filter([
Expand All @@ -63,7 +63,7 @@ public function compileCreateView(/** @scrutinizer ignore-unused */ Blueprint $b
]));
}

public function compileDropView(/** @scrutinizer ignore-unused */ Blueprint $blueprint, Fluent $command): string
public function compileDropView(Blueprint $blueprint, Fluent $command): string
{
return 'drop view ' . $this->wrapTable($command->get('view'));
}
Expand Down Expand Up @@ -133,17 +133,17 @@ protected function typeNumeric(Fluent $column): string
return $type;
}

protected function typeTsrange(/** @scrutinizer ignore-unused */ Fluent $column): string
protected function typeTsrange(Fluent $column): string
{
return TsRangeType::TYPE_NAME;
}

protected function typeTstzrange(/** @scrutinizer ignore-unused */ Fluent $column): string
protected function typeTstzrange(Fluent $column): string
{
return TsTzRangeType::TYPE_NAME;
}

protected function typeDaterange(/** @scrutinizer ignore-unused */ Fluent $column): string
protected function typeDaterange(Fluent $column): string
{
return DateRangeType::TYPE_NAME;
}
Expand Down
Loading

0 comments on commit 2c37e6e

Please sign in to comment.