Skip to content

Commit e081f99

Browse files
Merge pull request #44 from stefanak-michal/issue/41_php8
update phpunit to connection abstract class. Update Socket to php8.
2 parents 2bc991a + d456158 commit e081f99

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/connection/Socket.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Socket extends AConnection
1616
{
1717

1818
/**
19-
* @var resource
19+
* @var resource|object|bool
2020
*/
21-
private $socket;
21+
private $socket = false;
2222

2323
/**
2424
* Create socket connection
@@ -32,7 +32,7 @@ public function connect(): bool
3232
}
3333

3434
$this->socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
35-
if (!is_resource($this->socket)) {
35+
if ($this->socket === false) {
3636
throw new ConnectException('Cannot create socket');
3737
}
3838

@@ -61,7 +61,7 @@ public function connect(): bool
6161
*/
6262
public function write(string $buffer)
6363
{
64-
if (!is_resource($this->socket)) {
64+
if ($this->socket === false) {
6565
throw new ConnectException('Not initialized socket');
6666
}
6767

@@ -93,7 +93,7 @@ public function read(int $length = 2048): string
9393
{
9494
$output = '';
9595

96-
if (!is_resource($this->socket)) {
96+
if ($this->socket === false) {
9797
throw new ConnectException('Not initialized socket');
9898
}
9999

@@ -117,7 +117,7 @@ public function read(int $length = 2048): string
117117
*/
118118
public function disconnect()
119119
{
120-
if (is_resource($this->socket)) {
120+
if ($this->socket !== false) {
121121
@socket_shutdown($this->socket);
122122
@socket_close($this->socket);
123123
}

tests/ATest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Bolt\tests;
44

55
use PHPUnit\Framework\TestCase;
6-
use Bolt\connection\IConnection;
6+
use Bolt\connection\AConnection;
77

88
/**
99
* Class ATest
@@ -33,15 +33,15 @@ abstract class ATest extends TestCase
3333

3434
/**
3535
* Mock Socket class with "write" and "read" methods
36-
* @return IConnection
36+
* @return AConnection
3737
*/
3838
protected function mockConnection()
3939
{
4040
$mockBuilder = $this
41-
->getMockBuilder(IConnection::class)
41+
->getMockBuilder(AConnection::class)
4242
->disableOriginalConstructor();
4343
call_user_func([$mockBuilder, method_exists($mockBuilder, 'onlyMethods') ? 'onlyMethods' : 'setMethods'], ['__construct', 'write', 'read', 'connect', 'disconnect']);
44-
/** @var IConnection $connection */
44+
/** @var AConnection $connection */
4545
$connection = $mockBuilder->getMock();
4646

4747
$connection
@@ -98,9 +98,9 @@ public function readCallback(): string
9898
}
9999

100100
/**
101-
* Reset mockup IConnetion variables
101+
* Reset mockup AConnetion variables
102102
*/
103-
protected function setUp()
103+
protected function setUp(): void
104104
{
105105
self::$readIndex = 0;
106106
self::$readArray = [];

0 commit comments

Comments
 (0)