Skip to content

Commit

Permalink
adds tests for RedisArray options
Browse files Browse the repository at this point in the history
In order to test whether RedisArray options are correctly passed, use
uopz extension which allows to stub the constructor of PHP objects so we
can test the parameter passing without dependency-injection and factory
hell. It also keeps the API compatible because otherwise we would have
to pass e. g. factory.
  • Loading branch information
Soenke Ruempler committed May 31, 2014
1 parent 4746934 commit cf0cc32
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/Stash/Test/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ protected function setUp()
}
}

protected function getFreshDriver()
protected function getFreshDriver(array $options = null)
{
$driverClass = $this->driverClass;
$options = $this->getOptions();

if ($options === null) {
$options = $this->getOptions();
}

if (!$driverClass::isAvailable()) {
return false;
Expand Down
46 changes: 46 additions & 0 deletions tests/Stash/Test/Driver/RedisArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,50 @@ public function itShouldConstructARedisArray()

$this->assertInstanceOf('\RedisArray', $redisArray);
}

/**
* @test
*/
public function itShouldPassOptionsToRedisArray()
{
$redisArrayOptions = array(
"previous" => "something",
"function" => function ($key) { return $key; },
"distributor" => function ($key) { return 0; },
"index" => "something",
"autorehash" => "something",
"pconnect" => "something",
"retry_interval" => "something",
"lazy_connect" => "something",
"connect_timeout" => "something",
);

$driverOptions = array_merge(
$this->getOptions(),
$redisArrayOptions
);

if (!extension_loaded('uopz')) {
$this->markTestSkipped('uopz extension is necessarry in order to stub "new".');
}

uopz_backup('\RedisArray', '__construct');

$self = $this;
uopz_function(
'\RedisArray',
'__construct',
function ($serverArray, $actualRedisArrayOptions) use ($self, $redisArrayOptions) {
$self->assertEquals(
$redisArrayOptions,
$actualRedisArrayOptions
);
}
);

$this->getFreshDriver($driverOptions);

uopz_restore('\RedisArray', '__construct');
}

}
9 changes: 9 additions & 0 deletions tests/travis/php_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ else
rm -Rf phpredis
echo "Finished installing phpredis extension."

echo ""
echo "******************************"
echo "Installing uopz extension if possible (PHP >=5.4)."
echo "******************************"
set +e
pecl install uopz
set -e
echo "Finished installing uopz extension."

echo ""
echo "*********************"
echo "Updating php.ini file"
Expand Down

0 comments on commit cf0cc32

Please sign in to comment.