|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Oliverde8\Component\RuleEngine\Tests\Rules; |
|
4
|
|
|
|
|
5
|
|
|
use Oliverde8\Component\RuleEngine\RuleApplier; |
|
6
|
|
|
use Oliverde8\Component\RuleEngine\Rules\Implode; |
|
7
|
|
|
use Psr\Log\NullLogger; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class ImplodeTest |
|
11
|
|
|
* |
|
12
|
|
|
* @author de Cramer Oliver<[email protected]> |
|
13
|
|
|
* @copyright 2018 Smile |
|
14
|
|
|
* @package Oliverde8\Component\RuleEngine\Tests\Rules |
|
15
|
|
|
*/ |
|
16
|
|
|
class ImplodeTest extends AbstractRule |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Test simple array being imploded. |
|
20
|
|
|
*/ |
|
21
|
1 |
|
public function testImplode() |
|
22
|
|
|
{ |
|
23
|
1 |
|
$this->assertRuleResults([], [], ['values' => ['1', '2'], 'with' => ','], '1,2'); |
|
24
|
1 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Test when array is contained in array. |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function testTwoLevelImplode() |
|
30
|
|
|
{ |
|
31
|
1 |
|
$values = [['1', '2']]; |
|
32
|
1 |
|
$ruleApplier = $this->getMockBuilder(RuleApplier::class)->disableOriginalConstructor()->getMock(); |
|
33
|
1 |
|
$ruleApplier->method('apply')->willReturn($values); |
|
|
|
|
|
|
34
|
1 |
|
$this->rule->setApplier($ruleApplier); |
|
35
|
|
|
|
|
36
|
1 |
|
$this->assertRuleResults([], [], ['values' => $values, 'with' => ','], '1,2'); |
|
37
|
1 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Test imploding complex array. |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function testFourLevelImplode() |
|
43
|
|
|
{ |
|
44
|
1 |
|
$values = [[[['1', '2'], ['3']], '4']]; |
|
45
|
1 |
|
$ruleApplier = $this->getMockBuilder(RuleApplier::class)->disableOriginalConstructor()->getMock(); |
|
46
|
1 |
|
$ruleApplier->method('apply')->willReturn($values); |
|
47
|
1 |
|
$this->rule->setApplier($ruleApplier); |
|
48
|
|
|
|
|
49
|
1 |
|
$this->assertRuleResults([], [], ['values' => $values, 'with' => ','], '1,2,3,4'); |
|
50
|
1 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritdoc |
|
54
|
|
|
*/ |
|
55
|
4 |
|
function getRule() |
|
56
|
|
|
{ |
|
57
|
4 |
|
return new Implode(new NullLogger()); |
|
58
|
|
|
} |
|
59
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.