Completed
Push — master ( 610136...82575c )
by De Cramer
06:15 queued 03:00
created

ImplodeTest::testImplode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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);
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $ruleApplier->/** @scrutinizer ignore-call */ 
34
                      method('apply')->willReturn($values);

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.

Loading history...
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
}