Code Duplication    Length = 88-88 lines in 2 locations

Tests/Asserters/ListAsserter.php 1 location

@@ 22-109 (lines=88) @@
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
class ListAsserter extends CollectionAsserter
23
{
24
    /**
25
     * @var bool
26
     */
27
    protected $assertAll;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function setWith($value, $checkType = true)
33
    {
34
        parent::setWith($value, $checkType);
35
36
        if ($checkType === true) {
37
            if ($this->value instanceof ListInterface) {
38
                $this->pass();
39
            } else {
40
                $this->fail($this->getLocale()->_('%s is not a list', $this));
41
            }
42
        }
43
44
        return $this;
45
    }
46
47
    /**
48
     * @param mixed $value
49
     *
50
     * @return $this
51
     */
52
    public function contains($value)
53
    {
54
        $collection = $this->valueAsCollection();
55
        if ($collection->findOne(Criteria::eq($value)) !== null) {
56
            $this->pass();
57
        } else {
58
            $this->fail($this->getLocale()->_('The list not contain the value %s', $value));
59
        }
60
61
        return $this;
62
    }
63
64
    /**
65
     * @param array|\Traversable $values
66
     *
67
     * @return $this
68
     */
69
    public function containsValues($values)
70
    {
71
        foreach ($values as $value) {
72
            $this->contains($value);
73
        }
74
75
        return $this;
76
    }
77
78
    /**
79
     * @param mixed $value
80
     *
81
     * @return $this
82
     */
83
    public function notContains($value)
84
    {
85
        $collection = $this->valueAsCollection();
86
        if ($collection->findOne(Criteria::eq($value)) !== null) {
87
            $this->fail($this->getLocale()->_('The list contain an element with this value %s', $value));
88
        } else {
89
            $this->pass();
90
        }
91
92
        return $this;
93
    }
94
95
    /**
96
     * @throws LogicException
97
     *
98
     * @return \Cubiche\Core\Collections\ListInterface
99
     */
100
    protected function valueAsCollection()
101
    {
102
        $value = $this->valueIsSet()->getValue();
103
        if ($value instanceof ListInterface) {
104
            return $value;
105
        }
106
107
        throw new LogicException('List is undefined');
108
    }
109
}
110

Tests/Asserters/SetAsserter.php 1 location

@@ 22-109 (lines=88) @@
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
class SetAsserter extends CollectionAsserter
23
{
24
    /**
25
     * @var bool
26
     */
27
    protected $assertAll;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function setWith($value, $checkType = true)
33
    {
34
        parent::setWith($value, $checkType);
35
36
        if ($checkType === true) {
37
            if ($this->value instanceof SetInterface) {
38
                $this->pass();
39
            } else {
40
                $this->fail($this->getLocale()->_('%s is not a list', $this));
41
            }
42
        }
43
44
        return $this;
45
    }
46
47
    /**
48
     * @param mixed $value
49
     *
50
     * @return $this
51
     */
52
    public function contains($value)
53
    {
54
        $collection = $this->valueAsCollection();
55
        if ($collection->findOne(Criteria::eq($value)) !== null) {
56
            $this->pass();
57
        } else {
58
            $this->fail($this->getLocale()->_('The set not contain the value %s', $value));
59
        }
60
61
        return $this;
62
    }
63
64
    /**
65
     * @param array|\Traversable $values
66
     *
67
     * @return $this
68
     */
69
    public function containsValues($values)
70
    {
71
        foreach ($values as $value) {
72
            $this->contains($value);
73
        }
74
75
        return $this;
76
    }
77
78
    /**
79
     * @param mixed $value
80
     *
81
     * @return $this
82
     */
83
    public function notContains($value)
84
    {
85
        $collection = $this->valueAsCollection();
86
        if ($collection->findOne(Criteria::eq($value)) !== null) {
87
            $this->fail($this->getLocale()->_('The set contain an element with this value %s', $value));
88
        } else {
89
            $this->pass();
90
        }
91
92
        return $this;
93
    }
94
95
    /**
96
     * @throws LogicException
97
     *
98
     * @return \Cubiche\Core\Collections\SetInterface
99
     */
100
    protected function valueAsCollection()
101
    {
102
        $value = $this->valueIsSet()->getValue();
103
        if ($value instanceof SetInterface) {
104
            return $value;
105
        }
106
107
        throw new LogicException('Set is undefined');
108
    }
109
}
110