Code Duplication    Length = 42-42 lines in 2 locations

tests/JSONTextBasicTest.php 2 locations

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