Skip to content

Commit

Permalink
Bump phpstan/phpstan from 1.11.5 to 1.11.7 (#4090)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Jul 29, 2024
1 parent f654dcc commit 1d43dbb
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 9 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

152 changes: 152 additions & 0 deletions dev/tests/unit/Varien/Db/VarienDbAdapterPdoMysqlTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php
declare(strict_types=1);

namespace OpenMage\Tests\Unit\Core\Helper;

use PHPUnit\Framework\TestCase;
use \Varien_Db_Adapter_Pdo_Mysql;

class VarienDbAdapterPdoMysqlTest extends TestCase
{
private Varien_Db_Adapter_Pdo_Mysql $adapter;

protected function setUp(): void
{
$config = [
'host' => 'localhost',
'username' => 'user',
'password' => 'password',
'dbname' => 'test_db',
'type' => 'pdo_mysql',
'active' => '1',
];

// Create a mock object for Varien_Db_Adapter_Pdo_Mysql
$this->adapter = $this->getMockBuilder(Varien_Db_Adapter_Pdo_Mysql::class)
->disableOriginalConstructor()
->getMock();

// Call the constructor manually with our config
$reflectedAdapter = new \ReflectionClass(Varien_Db_Adapter_Pdo_Mysql::class);
$constructor = $reflectedAdapter->getConstructor();
$constructor->invoke($this->adapter, $config);
}

public function testGetHostInfoWithUnixSocket(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$fakeSocket = '/var/run/mysqld/mysqld.sock';
$hostInfo = $method->invoke($this->adapter, $fakeSocket);

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_UNIX_SOCKET);
$this->assertEquals($hostInfo->getUnixSocket(), $fakeSocket);
$this->assertNull($hostInfo->getHostName());
$this->assertNull($hostInfo->getPort());
}

public function testGetHostInfoWithIpv4Address(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$hostInfo = $method->invoke($this->adapter, '192.168.1.1:3306');

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_IPV4_ADDRESS);
$this->assertEquals('192.168.1.1', $hostInfo->getHostName());
$this->assertEquals('3306', $hostInfo->getPort());
$this->assertNull($hostInfo->getUnixSocket());
}

public function testGetHostInfoWithIpv4AddressWithoutPort(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$hostInfo = $method->invoke($this->adapter, '192.168.1.1');

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_IPV4_ADDRESS);
$this->assertEquals('192.168.1.1', $hostInfo->getHostName());
$this->assertNull($hostInfo->getPort());
$this->assertNull($hostInfo->getUnixSocket());
}

public function testGetHostInfoWithHostname(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$hostInfo = $method->invoke($this->adapter, 'db.example.com:3306');

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_HOSTNAME);
$this->assertEquals('db.example.com', $hostInfo->getHostName());
$this->assertEquals('3306', $hostInfo->getPort());
$this->assertNull($hostInfo->getUnixSocket());
}

public function testGetHostInfoWithHostnameWithoutPort(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$hostInfo = $method->invoke($this->adapter, 'db.example.com');

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_HOSTNAME);
$this->assertEquals('db.example.com', $hostInfo->getHostName());
$this->assertNull($hostInfo->getPort());
$this->assertNull($hostInfo->getUnixSocket());
}

public function testGetHostInfoWithIpv6Address(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$hostInfo = $method->invoke($this->adapter, '[2001:db8::1]:3306');

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_IPV6_ADDRESS);
$this->assertEquals('2001:db8::1', $hostInfo->getHostName());
$this->assertEquals('3306', $hostInfo->getPort());
$this->assertNull($hostInfo->getUnixSocket());
}

public function testGetHostInfoWithIpv6AddressWithoutPort(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$hostInfo = $method->invoke($this->adapter, '2001:db8::1');

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_IPV6_ADDRESS);
$this->assertEquals('2001:db8::1', $hostInfo->getHostName());
$this->assertNull($hostInfo->getPort());
$this->assertNull($hostInfo->getUnixSocket());
}

public function testGetHostInfoWithIpv6AddressWithZoneId(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$hostInfo = $method->invoke($this->adapter, '[fe80::1%eth0]:3306');

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_IPV6_ADDRESS);
$this->assertEquals('fe80::1%eth0', $hostInfo->getHostName());
$this->assertEquals('3306', $hostInfo->getPort());
$this->assertNull($hostInfo->getUnixSocket());
}

public function testGetHostInfoWithIpv6AddressWithZoneIdWithoutPort(): void
{
$method = new \ReflectionMethod(Varien_Db_Adapter_Pdo_Mysql::class, '_getHostInfo');
$method->setAccessible(true);

$hostInfo = $method->invoke($this->adapter, 'fe80::1%eth0');

$this->assertEquals($hostInfo->getAddressType(), Varien_Db_Adapter_Pdo_Mysql::ADDRESS_TYPE_IPV6_ADDRESS);
$this->assertEquals('fe80::1%eth0', $hostInfo->getHostName());
$this->assertNull($hostInfo->getPort());
$this->assertNull($hostInfo->getUnixSocket());
}
}
8 changes: 4 additions & 4 deletions lib/Varien/Db/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,14 @@ protected function _getHostInfo($hostName)
$hostInfo->setAddressType(self::ADDRESS_TYPE_UNIX_SOCKET)
->setUnixSocket($hostName);
} elseif (preg_match('/^\[(([0-9a-f]{1,4})?(:([0-9a-f]{1,4})?){1,}:([0-9a-f]{1,4}))(%[0-9a-z]+)?\](:([0-9]+))?$/i', $hostName, $matches)) {
$hostName = $matches[1] ?? null;
!is_null($hostName) && isset($matches[6]) && ($hostName .= $matches[6]);
$hostName = $matches[1];
$hostName .= $matches[6] ?? '';
$hostInfo->setAddressType(self::ADDRESS_TYPE_IPV6_ADDRESS)
->setHostName($hostName)
->setPort($matches[8] ?? null);
} elseif (preg_match('/^(([0-9a-f]{1,4})?(:([0-9a-f]{1,4})?){1,}:([0-9a-f]{1,4}))(%[0-9a-z]+)?$/i', $hostName, $matches)) {
$hostName = $matches[1] ?? null;
!is_null($hostName) && isset($matches[6]) && ($hostName .= $matches[6]);
$hostName = $matches[1];
$hostName .= $matches[6] ?? '';
$hostInfo->setAddressType(self::ADDRESS_TYPE_IPV6_ADDRESS)
->setHostName($hostName);
} elseif (str_contains($hostName, ':')) {
Expand Down

0 comments on commit 1d43dbb

Please sign in to comment.