[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
+19 -18
View File
@@ -11,9 +11,10 @@
namespace Predis\Command\Redis;
use PredisTestCase;
use Predis\Client;
use Predis\Command;
use PredisTestCase;
use Predis\Command\CommandInterface;
/**
*
@@ -21,25 +22,25 @@ use PredisTestCase;
abstract class PredisCommandTestCase extends PredisTestCase
{
/**
* Returns the expected command.
* Returns the expected command for tests.
*
* @return Command\CommandInterface|string Instance or FQN of the expected command.
* @return Command\CommandInterface|string Instance or FQCN of the expected command
*/
abstract protected function getExpectedCommand();
abstract protected function getExpectedCommand(): string;
/**
* Returns the expected command ID.
* Returns the expected command ID for tests.
*
* @return string
*/
abstract protected function getExpectedId();
abstract protected function getExpectedId(): string;
/**
* Returns a new command instance.
*
* @return Command\CommandInterface
*/
public function getCommand()
public function getCommand(): Command\CommandInterface
{
$command = $this->getExpectedCommand();
@@ -49,11 +50,11 @@ abstract class PredisCommandTestCase extends PredisTestCase
/**
* Returns a new client instance.
*
* @param bool $flushdb Flush selected database before returning the client.
* @param bool $flushdb Flush selected database before returning the client
*
* @return Client
*/
public function getClient($flushdb = true)
public function getClient(bool $flushdb = true): Client
{
$commands = $this->getCommandFactory();
@@ -69,11 +70,11 @@ abstract class PredisCommandTestCase extends PredisTestCase
}
/**
* Returns wether the command is prefixable or not.
* Verifies if the command implements the prefixable interface.
*
* @return bool
*/
protected function isPrefixable()
protected function isPrefixable(): bool
{
return $this->getCommand() instanceof Command\PrefixableCommandInterface;
}
@@ -81,23 +82,23 @@ abstract class PredisCommandTestCase extends PredisTestCase
/**
* Returns a new command instance with the specified arguments.
*
* @param ... List of arguments for the command.
* @param ... List of arguments for the command
*
* @return CommandInterface
*/
protected function getCommandWithArguments(/* arguments */)
protected function getCommandWithArguments(...$arguments): CommandInterface
{
return $this->getCommandWithArgumentsArray(func_get_args());
return $this->getCommandWithArgumentsArray($arguments);
}
/**
* Returns a new command instance with the specified arguments.
*
* @param array $arguments Arguments for the command.
* @param array $arguments Arguments for the command
*
* @return CommandInterface
*/
protected function getCommandWithArgumentsArray(array $arguments)
protected function getCommandWithArgumentsArray(array $arguments): CommandInterface
{
$command = $this->getCommand();
$command->setArguments($arguments);
@@ -108,7 +109,7 @@ abstract class PredisCommandTestCase extends PredisTestCase
/**
* @group disconnected
*/
public function testCommandId()
public function testCommandId(): void
{
$command = $this->getCommand();
@@ -119,7 +120,7 @@ abstract class PredisCommandTestCase extends PredisTestCase
/**
* @group disconnected
*/
public function testRawArguments()
public function testRawArguments(): void
{
$expected = array('1st', '2nd', '3rd', '4th');