Skip to content

Commit 2501a5e

Browse files
authored
Fix: Skipping pgsql tests In Swoole >= 6.0 (#6743)
1 parent 402aa86 commit 2501a5e

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

tests/Cases/DatabasePostgresBuilderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Hyperf\Database\Schema\Schema;
2424
use Hyperf\DbConnection\Db;
2525
use HyperfTest\Database\PgSQL\Stubs\ContainerStub;
26+
use HyperfTest\Database\PgSQL\Stubs\SwooleVersionStub;
2627
use Mockery as m;
2728
use PHPUnit\Framework\Attributes\CoversNothing;
2829
use PHPUnit\Framework\TestCase;
@@ -43,6 +44,7 @@ protected function tearDown(): void
4344

4445
public function testCreateDatabase()
4546
{
47+
SwooleVersionStub::skipV6();
4648
$grammar = new PostgresGrammar();
4749

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

5961
public function testDropDatabaseIfExists()
6062
{
63+
SwooleVersionStub::skipV6();
6164
$grammar = new PostgresGrammar();
6265

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

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

111115
public function testWhereFullTextForReal()
112116
{
117+
SwooleVersionStub::skipV6();
113118
$container = ContainerStub::getContainer();
114119
$container->shouldReceive('get')->with(Db::class)->andReturn(new Db($container));
115120

tests/Cases/PostgreSqlSwooleExtConnectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Hyperf\Database\Schema\Schema;
2424
use Hyperf\Support\Filesystem\Filesystem;
2525
use HyperfTest\Database\PgSQL\Stubs\ContainerStub;
26+
use HyperfTest\Database\PgSQL\Stubs\SwooleVersionStub;
2627
use Mockery;
2728
use PHPUnit\Framework\Attributes\CoversNothing;
2829
use PHPUnit\Framework\TestCase;
@@ -39,6 +40,7 @@ class PostgreSqlSwooleExtConnectionTest extends TestCase
3940

4041
public function setUp(): void
4142
{
43+
SwooleVersionStub::skipV6();
4244
$resolver = ContainerStub::getContainer()->get(ConnectionResolverInterface::class);
4345

4446
$this->migrator = new Migrator(

tests/DBAL/ConnectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Hyperf\Database\PgSQL\DBAL\Connection;
1616
use Hyperf\Database\PgSQL\DBAL\Result;
1717
use Hyperf\Database\PgSQL\DBAL\Statement;
18+
use HyperfTest\Database\PgSQL\Stubs\SwooleVersionStub;
1819
use PHPUnit\Framework\Attributes\CoversNothing;
1920
use PHPUnit\Framework\TestCase;
2021
use Swoole\Coroutine\PostgreSQL;
@@ -30,6 +31,7 @@ class ConnectionTest extends TestCase
3031

3132
public function setUp(): void
3233
{
34+
SwooleVersionStub::skipV6();
3335
$pgsql = new PostgreSQL();
3436
$connected = $pgsql->connect('host=127.0.0.1 port=5432 dbname=postgres user=postgres password=postgres');
3537
if (! $connected) {

tests/Stubs/ContainerStub.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public static function getContainer()
3838
Connection::resolverFor('pgsql-swoole', static function ($connection, $database, $prefix, $config) {
3939
return new PostgreSqlSwooleExtConnection($connection, $database, $prefix, $config);
4040
});
41-
4241
$connection = $connector->make([
4342
'driver' => 'pgsql-swoole',
4443
'host' => '127.0.0.1',

tests/Stubs/SwooleVersionStub.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact group@hyperf.io
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
13+
namespace HyperfTest\Database\PgSQL\Stubs;
14+
15+
use PHPUnit\Framework\Assert;
16+
17+
class SwooleVersionStub
18+
{
19+
public static function skipV6(): void
20+
{
21+
if (self::isV6()) {
22+
Assert::markTestSkipped('The test is not compatible with swoole 6.0.0 or later.');
23+
}
24+
}
25+
26+
public static function isV6(): bool
27+
{
28+
return version_compare(swoole_version(), '6.x', '>=');
29+
}
30+
}

0 commit comments

Comments
 (0)