Skip to content

Commit

Permalink
fix: Uncaught Error: Cannot unset readonly property Pheanstalk\Socket…
Browse files Browse the repository at this point in the history
…\SocketSocket::$socket in SocketSocket.php on line 138 (#258)

* make socket property non read-only to fix error: Uncaught Error: Cannot unset readonly property Pheanstalk\Socket\SocketSocket::$socket in SocketSocket.php on line 138

* add test case for disconnect -> dispatchCommand not throwing errors

* [fix-disconnect-error] change from abstract class to trait

* [fix-disconnect-error] fix code style error

---------

Co-authored-by: Anna Damm <anna.damm@check24.de>
  • Loading branch information
AnnaDamm and annadamm-check24 committed Nov 23, 2023
1 parent d98d10d commit bee66a8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Socket/SocketSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
final class SocketSocket implements SocketInterface
{
private readonly null|\Socket $socket;
private null|\Socket $socket;

public function __construct(
string $host,
Expand Down
33 changes: 33 additions & 0 deletions tests/Integration/ConstructWithConnectionObjectTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Pheanstalk\Tests\Integration;

use Pheanstalk\Command\UseCommand;
use Pheanstalk\Connection;
use Pheanstalk\Pheanstalk;
use Pheanstalk\Values\TubeName;

/**
* @psalm-require-extends PheanstalkTestBase
*/
trait ConstructWithConnectionObjectTests
{
public function testDispatchCommandAfterDisconnect(): void
{
$this->expectNotToPerformAssertions();
$connection = $this->getConnection();
$connection->connect();
$connection->disconnect();

$connection->dispatchCommand(new UseCommand(new TubeName('tube5')));
}

protected function getPheanstalk(): Pheanstalk
{
return new Pheanstalk($this->getConnection());
}

abstract protected function getConnection(): Connection;
}
7 changes: 4 additions & 3 deletions tests/Integration/SocketPheanstalkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Pheanstalk\Tests\Integration;

use Pheanstalk\Connection;
use Pheanstalk\Pheanstalk;
use Pheanstalk\SocketFactory;
use Pheanstalk\Values\SocketImplementation;
use Pheanstalk\Values\Timeout;
Expand All @@ -18,8 +17,10 @@
*/
final class SocketPheanstalkTest extends PheanstalkTestBase
{
protected function getPheanstalk(): Pheanstalk
use ConstructWithConnectionObjectTests;

protected function getConnection(): Connection
{
return new Pheanstalk(new Connection(new SocketFactory($this->getHost(), 11300, SocketImplementation::SOCKET, connectTimeout: new Timeout(1))));
return new Connection(new SocketFactory($this->getHost(), 11300, SocketImplementation::SOCKET, connectTimeout: new Timeout(1)));
}
}
7 changes: 4 additions & 3 deletions tests/Integration/SocketUnixPheanstalkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Pheanstalk\Tests\Integration;

use Pheanstalk\Connection;
use Pheanstalk\Pheanstalk;
use Pheanstalk\SocketFactory;
use Pheanstalk\Values\SocketImplementation;
use Pheanstalk\Values\Timeout;
Expand All @@ -18,8 +17,10 @@
*/
final class SocketUnixPheanstalkTest extends PheanstalkTestBase
{
protected function getPheanstalk(): Pheanstalk
use ConstructWithConnectionObjectTests;

protected function getConnection(): Connection
{
return new Pheanstalk(new Connection(new SocketFactory($this->getHost(), implementation: SocketImplementation::SOCKET, connectTimeout: new Timeout(1))));
return new Connection(new SocketFactory($this->getHost(), implementation: SocketImplementation::SOCKET, connectTimeout: new Timeout(1)));
}
}
7 changes: 4 additions & 3 deletions tests/Integration/StreamPheanstalkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Pheanstalk\Tests\Integration;

use Pheanstalk\Connection;
use Pheanstalk\Pheanstalk;
use Pheanstalk\SocketFactory;
use Pheanstalk\Values\SocketImplementation;
use Pheanstalk\Values\Timeout;
Expand All @@ -19,8 +18,10 @@
*/
final class StreamPheanstalkTest extends PheanstalkTestBase
{
protected function getPheanstalk(): Pheanstalk
use ConstructWithConnectionObjectTests;

protected function getConnection(): Connection
{
return new Pheanstalk(new Connection(new SocketFactory($this->getHost(), implementation: SocketImplementation::STREAM, connectTimeout: new Timeout(1))));
return new Connection(new SocketFactory($this->getHost(), implementation: SocketImplementation::STREAM, connectTimeout: new Timeout(1)));
}
}
7 changes: 4 additions & 3 deletions tests/Integration/StreamUnixPheanstalkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Pheanstalk\Tests\Integration;

use Pheanstalk\Connection;
use Pheanstalk\Pheanstalk;
use Pheanstalk\SocketFactory;
use Pheanstalk\Values\SocketImplementation;
use Pheanstalk\Values\Timeout;
Expand All @@ -19,8 +18,10 @@
*/
final class StreamUnixPheanstalkTest extends PheanstalkTestBase
{
protected function getPheanstalk(): Pheanstalk
use ConstructWithConnectionObjectTests;

protected function getConnection(): Connection
{
return new Pheanstalk(new Connection(new SocketFactory($this->getHost(), implementation: SocketImplementation::STREAM, connectTimeout: new Timeout(1))));
return new Connection(new SocketFactory($this->getHost(), implementation: SocketImplementation::STREAM, connectTimeout: new Timeout(1)));
}
}

0 comments on commit bee66a8

Please sign in to comment.