Skip to content

Commit 0b86518

Browse files
authored
Specify package requirements for module (#3366)
* fixed time calculation. Fixes #3331 * Added RequiresPackage interface and validation to check external package dependencies for modules
1 parent e187c96 commit 0b86518

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Codeception/Module/Redis.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Codeception\Module;
44

5+
use Codeception\Lib\Interfaces\RequiresPackage;
56
use Codeception\Module as CodeceptionModule;
67
use Codeception\TestCase;
78
use Codeception\Exception\ModuleException;
@@ -31,7 +32,7 @@
3132
*
3233
* @author Marc Verney <[email protected]>
3334
*/
34-
class Redis extends CodeceptionModule
35+
class Redis extends CodeceptionModule implements RequiresPackage
3536
{
3637
/**
3738
* {@inheritdoc}
@@ -59,16 +60,18 @@ class Redis extends CodeceptionModule
5960
*/
6061
public $driver;
6162

63+
public function _requires()
64+
{
65+
return ['Predis\Client' => '"predis/predis": "^1.0"'];
66+
}
67+
6268
/**
6369
* Instructions to run after configuration is loaded
6470
*
6571
* @throws ModuleException
6672
*/
6773
public function _initialize()
6874
{
69-
if (!class_exists('Predis\Client')) {
70-
throw new ModuleException($this, 'This module requires Predis library to be installed. Please add "predis/predis": "^1.0" to composer.json');
71-
}
7275
try {
7376
$this->driver = new RedisDriver([
7477
'host' => $this->config['host'],

0 commit comments

Comments
 (0)