Code Duplication    Length = 39-39 lines in 2 locations

tests/JSONTextBasicTest.php 2 locations

@@ 62-100 (lines=39) @@
59
        $field->getJSONStore();
60
    }
61
62
    public function testFirst()
63
    {
64
        $field = $this->sut;
65
66
        // Test: Source data is simple JSON array
67
        // Return type: Array
68
        $field->setReturnType('array');
69
        $field->setValue($this->getFixture('array'));
70
        $this->assertInternalType('array', $field->first());
71
        $this->assertCount(1, $field->first());
72
        $this->assertEquals([0 => 'great wall'], $field->first());
73
74
        // Test: Source data is simple JSON array
75
        // Return type: JSON
76
        $field->setReturnType('json');
77
        $field->setValue($this->getFixture('array'));
78
        $this->assertInternalType('string', $field->first());
79
        $this->assertEquals('["great wall"]', $field->first());
80
81
        // Test: Source data is simple JSON array
82
        // Return type: SilverStripe
83
        $field->setReturnType('silverstripe');
84
        $field->setValue($this->getFixture('array'));
85
        $this->assertInternalType('array', $field->first());
86
        $this->assertInstanceOf('Varchar', $field->first()[0]);
87
        $this->assertEquals('great wall', $field->first()[0]->getValue());
88
89
        // Test: Empty
90
        $field->setReturnType('array');
91
        $field->setValue('');
92
        $this->assertInternalType('array', $field->first());
93
        $this->assertCount(0, $field->first());
94
95
        // Test: Invalid
96
        $field->setReturnType('array');
97
        $field->setValue('{');
98
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
99
        $field->first();
100
    }
101
102
    public function testLast()
103
    {
@@ 102-140 (lines=39) @@
99
        $field->first();
100
    }
101
102
    public function testLast()
103
    {
104
        $field = $this->sut;
105
        
106
        // Test: Source data is simple JSON array
107
        // Return type: Array
108
        $field->setReturnType('array');
109
        $field->setValue($this->getFixture('array'));
110
        $this->assertInternalType('array', $field->last());
111
        $this->assertCount(1, $field->last());
112
        $this->assertEquals([6 => 33.3333], $field->last());
113
114
        // Test: Source data is simple JSON array
115
        // Return type: JSON
116
        $field->setReturnType('json');
117
        $field->setValue($this->getFixture('array'));
118
        $this->assertInternalType('string', $field->last());
119
        $this->assertEquals('{"6":33.3333}', $field->last());
120
121
        // Test: Source data is simple JSON array
122
        // Return type: SilverStripe
123
        $field->setReturnType('silverstripe');
124
        $field->setValue($this->getFixture('array'));
125
        $this->assertInternalType('array', $field->last());
126
        $this->assertInstanceOf('Float', $field->last()[6]);
127
        $this->assertEquals(33.3333, $field->last()[6]->getValue());
128
129
        // Test: Empty
130
        $field->setReturnType('array');
131
        $field->setValue('');
132
        $this->assertInternalType('array', $field->last());
133
        $this->assertCount(0, $field->last());
134
135
        // Test: Invalid
136
        $field->setReturnType('array');
137
        $field->setValue('{');
138
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
139
        $field->last();
140
    }
141
142
    public function testNth()
143
    {