Skip to content

Commit

Permalink
Fix: Skipping pgsql tests In Swoole >= 6.0 (#6743)
Browse files Browse the repository at this point in the history
  • Loading branch information
zds-s authored May 10, 2024
1 parent 402aa86 commit 2501a5e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/Cases/DatabasePostgresBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Hyperf\Database\Schema\Schema;
use Hyperf\DbConnection\Db;
use HyperfTest\Database\PgSQL\Stubs\ContainerStub;
use HyperfTest\Database\PgSQL\Stubs\SwooleVersionStub;
use Mockery as m;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand All @@ -43,6 +44,7 @@ protected function tearDown(): void

public function testCreateDatabase()
{
SwooleVersionStub::skipV6();
$grammar = new PostgresGrammar();

$connection = m::mock(Connection::class);
Expand All @@ -58,6 +60,7 @@ public function testCreateDatabase()

public function testDropDatabaseIfExists()
{
SwooleVersionStub::skipV6();
$grammar = new PostgresGrammar();

$connection = m::mock(Connection::class);
Expand All @@ -72,6 +75,7 @@ public function testDropDatabaseIfExists()

public function testWhereFullText()
{
SwooleVersionStub::skipV6();
$builder = $this->getPostgresBuilderWithProcessor();
$builder->select('*')->from('users')->whereFullText('body', 'Hello World');
$this->assertSame('select * from "users" where (to_tsvector(\'english\', "body")) @@ plainto_tsquery(\'english\', ?)', $builder->toSql());
Expand Down Expand Up @@ -110,6 +114,7 @@ public function testWhereFullText()

public function testWhereFullTextForReal()
{
SwooleVersionStub::skipV6();
$container = ContainerStub::getContainer();
$container->shouldReceive('get')->with(Db::class)->andReturn(new Db($container));

Expand Down
2 changes: 2 additions & 0 deletions tests/Cases/PostgreSqlSwooleExtConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Hyperf\Database\Schema\Schema;
use Hyperf\Support\Filesystem\Filesystem;
use HyperfTest\Database\PgSQL\Stubs\ContainerStub;
use HyperfTest\Database\PgSQL\Stubs\SwooleVersionStub;
use Mockery;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
Expand All @@ -39,6 +40,7 @@ class PostgreSqlSwooleExtConnectionTest extends TestCase

public function setUp(): void
{
SwooleVersionStub::skipV6();
$resolver = ContainerStub::getContainer()->get(ConnectionResolverInterface::class);

$this->migrator = new Migrator(
Expand Down
2 changes: 2 additions & 0 deletions tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Hyperf\Database\PgSQL\DBAL\Connection;
use Hyperf\Database\PgSQL\DBAL\Result;
use Hyperf\Database\PgSQL\DBAL\Statement;
use HyperfTest\Database\PgSQL\Stubs\SwooleVersionStub;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\TestCase;
use Swoole\Coroutine\PostgreSQL;
Expand All @@ -30,6 +31,7 @@ class ConnectionTest extends TestCase

public function setUp(): void
{
SwooleVersionStub::skipV6();
$pgsql = new PostgreSQL();
$connected = $pgsql->connect('host=127.0.0.1 port=5432 dbname=postgres user=postgres password=postgres');
if (! $connected) {
Expand Down
1 change: 0 additions & 1 deletion tests/Stubs/ContainerStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static function getContainer()
Connection::resolverFor('pgsql-swoole', static function ($connection, $database, $prefix, $config) {
return new PostgreSqlSwooleExtConnection($connection, $database, $prefix, $config);
});

$connection = $connector->make([
'driver' => 'pgsql-swoole',
'host' => '127.0.0.1',
Expand Down
30 changes: 30 additions & 0 deletions tests/Stubs/SwooleVersionStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/

namespace HyperfTest\Database\PgSQL\Stubs;

use PHPUnit\Framework\Assert;

class SwooleVersionStub
{
public static function skipV6(): void
{
if (self::isV6()) {
Assert::markTestSkipped('The test is not compatible with swoole 6.0.0 or later.');
}
}

public static function isV6(): bool
{
return version_compare(swoole_version(), '6.x', '>=');
}
}

0 comments on commit 2501a5e

Please sign in to comment.