From 1d43dbb49e40027b7e8185db10f22b695843ccb5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:18:11 +0100 Subject: [PATCH] Bump phpstan/phpstan from 1.11.5 to 1.11.7 (#4090) --- composer.lock | 10 +- .../Varien/Db/VarienDbAdapterPdoMysqlTest.php | 152 ++++++++++++++++++ lib/Varien/Db/Adapter/Pdo/Mysql.php | 8 +- 3 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 dev/tests/unit/Varien/Db/VarienDbAdapterPdoMysqlTest.php diff --git a/composer.lock b/composer.lock index 26594ac3076..8fdf520b2b4 100644 --- a/composer.lock +++ b/composer.lock @@ -3486,16 +3486,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.11.5", + "version": "1.11.7", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "490f0ae1c92b082f154681d7849aee776a7c1443" + "reference": "52d2bbfdcae7f895915629e4694e9497d0f8e28d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/490f0ae1c92b082f154681d7849aee776a7c1443", - "reference": "490f0ae1c92b082f154681d7849aee776a7c1443", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/52d2bbfdcae7f895915629e4694e9497d0f8e28d", + "reference": "52d2bbfdcae7f895915629e4694e9497d0f8e28d", "shasum": "" }, "require": { @@ -3540,7 +3540,7 @@ "type": "github" } ], - "time": "2024-06-17T15:10:54+00:00" + "time": "2024-07-06T11:17:41+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/dev/tests/unit/Varien/Db/VarienDbAdapterPdoMysqlTest.php b/dev/tests/unit/Varien/Db/VarienDbAdapterPdoMysqlTest.php new file mode 100644 index 00000000000..0d36667c07d --- /dev/null +++ b/dev/tests/unit/Varien/Db/VarienDbAdapterPdoMysqlTest.php @@ -0,0 +1,152 @@ + '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()); + } +} \ No newline at end of file diff --git a/lib/Varien/Db/Adapter/Pdo/Mysql.php b/lib/Varien/Db/Adapter/Pdo/Mysql.php index 74856120922..93412dad7c6 100644 --- a/lib/Varien/Db/Adapter/Pdo/Mysql.php +++ b/lib/Varien/Db/Adapter/Pdo/Mysql.php @@ -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, ':')) {