[tests] Start improving test suite.

- Make use of more typehints for function parameters
- Make use of typehints for function return values
- Use @var where needed to give proper hints to IDEs and avoid warnings
- Replace MockObject::setMethods() with addMethods() and onlyMethods()
- Rewording of some phpdocs
This commit is contained in:
Daniele Alessandri
2020-08-28 18:59:10 +02:00
parent c2ede30394
commit 36c9bb047e
236 changed files with 2887 additions and 2454 deletions
@@ -11,6 +11,7 @@
namespace Predis\Connection;
use PHPUnit\Framework\MockObject\MockObject;
use Predis\Command\RawCommand;
use Predis\Response\Error as ErrorResponse;
@@ -19,21 +20,28 @@ use Predis\Response\Error as ErrorResponse;
*/
class StreamConnectionTest extends PredisConnectionTestCase
{
const CONNECTION_CLASS = 'Predis\Connection\StreamConnection';
/**
* @inheritDoc
*/
public function getConnectionClass(): string
{
return 'Predis\Connection\StreamConnection';
}
/**
* @group disconnected
*/
public function testThrowsExceptionOnInitializationCommandFailure()
public function testThrowsExceptionOnInitializationCommandFailure(): void
{
$this->expectException('Predis\Connection\ConnectionException');
$this->expectExceptionMessage("`SELECT` failed: ERR invalid DB index [tcp://127.0.0.1:6379]");
$cmdSelect = RawCommand::create('SELECT', '1000');
/** @var NodeConnectionInterface|MockObject */
$connection = $this
->getMockBuilder(static::CONNECTION_CLASS)
->setMethods(array('executeCommand', 'createResource'))
->getMockBuilder($this->getConnectionClass())
->onlyMethods(array('executeCommand', 'createResource'))
->setConstructorArgs(array(new Parameters()))
->getMock();
$connection
@@ -57,7 +65,7 @@ class StreamConnectionTest extends PredisConnectionTestCase
* @group connected
* @requires PHP 5.4
*/
public function testPersistentParameterWithFalseLikeValues()
public function testPersistentParameterWithFalseLikeValues(): void
{
$connection1 = $this->createConnectionWithParams(array('persistent' => 0));
$this->assertNonPersistentConnection($connection1);
@@ -76,7 +84,7 @@ class StreamConnectionTest extends PredisConnectionTestCase
* @group connected
* @requires PHP 5.4
*/
public function testPersistentParameterWithTrueLikeValues()
public function testPersistentParameterWithTrueLikeValues(): void
{
$connection1 = $this->createConnectionWithParams(array('persistent' => 1));
$this->assertPersistentConnection($connection1);
@@ -97,7 +105,7 @@ class StreamConnectionTest extends PredisConnectionTestCase
* @group connected
* @requires PHP 5.4
*/
public function testPersistentConnectionsToSameNodeShareResource()
public function testPersistentConnectionsToSameNodeShareResource(): void
{
$connection1 = $this->createConnectionWithParams(array('persistent' => true));
$connection2 = $this->createConnectionWithParams(array('persistent' => true));
@@ -114,7 +122,7 @@ class StreamConnectionTest extends PredisConnectionTestCase
* @group connected
* @requires PHP 5.4
*/
public function testPersistentConnectionsToSameNodeDoNotShareResourceUsingDifferentPersistentID()
public function testPersistentConnectionsToSameNodeDoNotShareResourceUsingDifferentPersistentID(): void
{
$connection1 = $this->createConnectionWithParams(array('persistent' => 'conn1'));
$connection2 = $this->createConnectionWithParams(array('persistent' => 'conn2'));