1313use PHPUnit \Framework \Attributes \CoversMethod ;
1414use PHPUnit \Framework \TestCase ;
1515
16- use function getmypid ;
17- use function shell_exec ;
18-
1916#[CoversMethod(Adapter::class, 'getCurrentSchema ' )]
2017#[CoversMethod(AdapterInterface::class, '__construct ' )]
2118#[CoversMethod(SchemaAwareInterface::class, 'getCurrentSchema ' )]
@@ -44,7 +41,7 @@ public function testGetCurrentSchema(): void
4441
4542 public function testDriverDisconnectAfterQuoteWithPlatform (): void
4643 {
47- // $isTcpConnection = $this->isTcpConnection();
44+ $ isTcpConnection = $ this ->isTcpConnection ();
4845
4946 /** @var AdapterInterface $adapter */
5047 $ adapter = $ this ->getAdapter ([
@@ -53,55 +50,36 @@ public function testDriverDisconnectAfterQuoteWithPlatform(): void
5350 ],
5451 ]);
5552 $ adapter ->getDriver ()->getConnection ()->connect ();
56-
5753 self ::assertTrue ($ adapter ->getDriver ()->getConnection ()->isConnected ());
58- // if ($isTcpConnection) {
59- // self::assertTrue($this->isConnectedTcp ());
60- // }
54+ if ($ isTcpConnection ) {
55+ self ::assertTrue ($ adapter -> getDriver ()-> getConnection ()-> isConnected ());
56+ }
6157
6258 $ adapter ->getDriver ()->getConnection ()->disconnect ();
63-
6459 self ::assertFalse ($ adapter ->getDriver ()->getConnection ()->isConnected ());
65- // if ($isTcpConnection) {
66- // self::assertFalse($this->isConnectedTcp ());
67- // }
60+ if ($ isTcpConnection ) {
61+ self ::assertFalse ($ adapter -> getDriver ()-> getConnection ()-> isConnected ());
62+ }
6863
6964 $ adapter ->getDriver ()->getConnection ()->connect ();
70-
7165 self ::assertTrue ($ adapter ->getDriver ()->getConnection ()->isConnected ());
72- // if ($isTcpConnection) {
73- // self::assertTrue($this->isConnectedTcp ());
74- // }
66+ if ($ isTcpConnection ) {
67+ self ::assertTrue ($ adapter -> getDriver ()-> getConnection ()-> isConnected ());
68+ }
7569
7670 $ adapter ->getPlatform ()->quoteValue ('test ' );
7771
7872 $ adapter ->getDriver ()->getConnection ()->disconnect ();
7973
8074 self ::assertFalse ($ adapter ->getDriver ()->getConnection ()->isConnected ());
81- // if ($isTcpConnection) {
82- // self::assertFalse($this->isConnectedTcp());
83- // }
84- }
85-
86- protected function isConnectedTcp (): bool
87- {
88- $ mypid = getmypid ();
89- /** @var array $config */
90- $ config = $ this ->getConfig ();
91- /** @var array $dbConfig */
92- $ dbConfig = $ config ['db ' ] ?? [];
93- /** @var array $connectionConfig */
94- $ connectionConfig = $ dbConfig ['connection ' ] ?? [];
95- /** @var string $dbPort */
96- $ dbPort = (string ) $ connectionConfig ['port ' ] ?? '3306 ' ;
97- /** @psalm-suppress ForbiddenCode - running lsof */
98- $ lsof = shell_exec ("lsof -i -P -n | grep $ dbPort | grep $ mypid " );
99-
100- return $ lsof !== null ;
75+ if ($ isTcpConnection ) {
76+ self ::assertFalse ($ adapter ->getDriver ()->getConnection ()->isConnected ());
77+ }
10178 }
10279
10380 protected function isTcpConnection (): bool
10481 {
105- return $ this ->getHostname () !== 'localhost ' ;
82+ $ hostName = $ this ->getHostname ();
83+ return $ hostName !== 'localhost ' && $ hostName !== '127.0.0.1 ' ;
10684 }
10785}
0 commit comments