Code Duplication    Length = 24-25 lines in 2 locations

tests/JSONTextIntegrationTest.php 2 locations

@@ 45-69 (lines=25) @@
42
     * Tests JSONText::setValue() by means of a simple JSONPath expression operating on a nested JSON array
43
     * on a saved DataObject record.
44
     */
45
    public function testSetValueOnNestedArray()
46
    {
47
        $model = $this->objFromFixture(MyAwesomeJSONModel::class, 'json-as-object');
48
        $expression = '$.cars.american.[0]';
49
        $field = $model->dbObject('MyJSON');
50
51
        // Primary assertion (JSON as return type is the default)
52
        $this->assertEquals('["buick"]', $field->query($expression));
53
        
54
        // How about now?
55
        $field->setValue('ford', null, $expression);
56
        $model->setField('MyJSON', $field->getValue());
57
        $model->write();
58
        $this->assertEquals('["ford"]', $field->query($expression));
59
60
        // Secondary assertion
61
        $field
62
            ->setValue('chrysler', null, $expression)
63
            ->setReturnType('array');
64
65
        // With chaining
66
        $model->setField('MyJSON', $field->getValue());
67
        $model->write();
68
        $this->assertEquals(['chrysler'], $field->query($expression));
69
    }
70
71
    /**
72
     * Tests JSONText::setValue() by means of a simple JSONPath expression operating on a simple, un-nested JSON array
@@ 75-98 (lines=24) @@
72
     * Tests JSONText::setValue() by means of a simple JSONPath expression operating on a simple, un-nested JSON array
73
     * on a saved DataObject record.
74
     */
75
    public function testSetValueOnUnNestedArray()
76
    {
77
        $model = $this->objFromFixture(MyAwesomeJSONModel::class, 'json-as-array');
78
        $expression = '$.[0]';
79
        $field = $model->dbObject('MyJSON');
80
81
        // Primary assertion (JSON as return type is the default)
82
        $this->assertEquals('["buick"]', $field->query($expression));
83
84
        // Secondary assertion
85
        $field->setValue('ford', null, $expression);
86
        $model->setField('MyJSON', $field->getValue());
87
        $model->write();
88
        $this->assertEquals('["ford"]', $field->query($expression));
89
        
90
        // With chaining
91
        $field
92
            ->setValue('chrysler', null, $expression)
93
            ->setReturnType('array');
94
        
95
        $model->setField('MyJSON', $field->getValue());
96
        $model->write();
97
        $this->assertEquals(['chrysler'], $field->query($expression));
98
    }
99
100
}
101