Skip to content

Commit

Permalink
Fix tests with PHP >= 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vdechenaux committed Nov 24, 2017
1 parent a1aaa8b commit d95ed32
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion tests/units/RedisMockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public function testGetAdapterClass()

/**
* Build mock by using 'orphanizeConstruct' parameter
*
*
* @php < 7.1
* @return void
*/
public function testOrphanizeConstruct() {
Expand Down Expand Up @@ -170,6 +171,55 @@ public function testOrphanizeConstruct() {
->notExists();
}

/**
* Build mock by using 'orphanizeConstruct' parameter
*
* @php >= 7.1
* @return void
*/
public function testOrphanizeConstructAfterPhp7Dot1() {
$factory = new Factory();
$this->assert
->exception(function() use ($factory) {
$factory->getAdapter('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor', false, false);
})
->isInstanceOf(\ArgumentCountError::class);

$mock = $factory->getAdapter('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor');

$this->assert
->object($mock)
->isInstanceOf('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter')
->class(get_class($mock))
->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor');

$this->assert
->string($class = $factory->getAdapterClass('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor'))
->isEqualTo('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter_NativeConstructor')
->class($class)
->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor')
->exception(function() use ($class) {
$mock = new $class();
})
->isInstanceOf(\ArgumentCountError::class);

$this->assert
->when(function() use ($class) {
$mock = new $class(null);
})
->error()
->notExists()
->string($class2 = $factory->getAdapterClass('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor', false, true))
->isEqualTo('M6Web\Component\RedisMock\RedisMock_M6Web_Component_RedisMock_tests_units_RedisWithNativeConstructor_Adapter')
->class($class2)
->extends('M6Web\Component\RedisMock\tests\units\RedisWithNativeConstructor')
->when(function() use ($class2) {
$mock = new $class2();
})
->error()
->notExists();
}

/**
* Test the mock with a base class that implement unsupported Redis commands
*
Expand Down

0 comments on commit d95ed32

Please sign in to comment.