Completed
Push — master ( 9d18b4...301d75 )
by Russell
03:01
created

JSONTextQueryTest::testQueryWithMatchOnStr()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 109
Code Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 109
rs 8.2857
cc 1
eloc 65
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @package silverstripe-jsontext
5
 * @subpackage fields
6
 * @author Russell Michell <[email protected]>
7
 * @todo Add tests where source data is a JSON array, not just a JSON object
8
 * @todo Split tests into discreet types
9
 * @todo $this->clearFixtures(); in setUp()
10
 * @todo Use same source data instead of repeating for each test
11
 * @todo See the PHPUnit @dataProvider annotaton ala
12
 * 
13
 *
14
 */
15
16
/**
17
 * @dataProvider additionProvider
18
 */
19
/*public function testAdd($a, $b, $expected)
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
20
{
21
    $this->assertEquals($expected, $a + $b);
22
}
23
24
public function additionProvider()
25
{
26
    return [
27
        [0, 0, 0],
28
        [0, 1, 1],
29
        [1, 0, 1],
30
        [1, 1, 3]
31
    ];
32
}*/
33
34
use JSONText\Fields;
35
use JSONText\Exceptions;
36
37
class JSONTextQueryTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
38
{
39
    /**
40
     * @var array
41
     */
42
    protected $fixtures = [
43
        'array'     => 'tests/fixtures/json/array.json',
44
        'object'    => 'tests/fixtures/json/object.json',
45
        'invalid'   => 'tests/fixtures/json/invalid.json'
46
    ];
47
48
    /**
49
     * JSONTextTest constructor.
50
     * 
51
     * Modify fixtures property to be able to run on PHP <5.6 without use of constant in class property which 5.6+ allows
52
     */
53
    public function __construct()
54
    {
55 View Code Duplication
        foreach($this->fixtures as $name => $path) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
            $this->fixtures[$name] = MODULE_DIR . '/' . $path;
57
        }
58
    }
59
60
    /**
61
     * Tests query() by means of the integer Postgres Int match operator: '->'
62
     * 
63
     * @todo Use same source data instead of repeating..
64
     */
65
    public function testQueryWithMatchOnInt()
66
    {
67
        // Data Source: Array
68
        // Return Type: ARRAY
69
        // Operator: "->" (Int)
70
        $field = JSONText\Fields\JSONText::create('MyJSON');
71
        $field->setReturnType('array');
72
        $field->setValue($this->getFixture('array'));
73
        $this->assertEquals([2 => 'trabant'], $field->query('->', 2));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
74
        
75
        // Data Source: Array
76
        // Return Type: JSON
77
        // Operator: "->" (Int)
78
        $field = JSONText\Fields\JSONText::create('MyJSON');
79
        $field->setReturnType('json');
80
        $field->setValue($this->getFixture('array'));
81
        $this->assertEquals('{"2":"trabant"}', $field->query('->', 2));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
82
        $this->assertEquals('{"5":101}', $field->query('->', 5));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
83
        
84
        // Data Source: Array
85
        // Return Type: SILVERSTRIPE
86
        // Operator: "->" (Int)
87
        // SS Type: Float
88
        $field = JSONText\Fields\JSONText::create('MyJSON');
89
        $field->setReturnType('silverstripe');
90
        $field->setValue($this->getFixture('array'));
91
        $this->assertInternalType('array', $field->query('->', 3));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
92
        $this->assertInstanceOf('Float', $field->query('->', 3)[3]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
93
        $this->assertEquals(44.6, $field->query('->', 3)[3]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
94
95
        // Data Source: Array
96
        // Return Type: SILVERSTRIPE
97
        // Operator: "->" (Int)
98
        // SS Type: Boolean
99
        $field = JSONText\Fields\JSONText::create('MyJSON');
100
        $field->setReturnType('silverstripe');
101
        $field->setValue($this->getFixture('array'));
102
        $this->assertInternalType('array', $field->query('->', 1));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
103
        $this->assertInstanceOf('Boolean', $field->query('->', 1)[1]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
104
        $this->assertEquals(1, $field->query('->', 1)[1]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
105
106
        // Data Source: Array
107
        // Return Type: SILVERSTRIPE
108
        // Operator: "->" (Int)
109
        // SS Type: Int
110
        $field = JSONText\Fields\JSONText::create('MyJSON');
111
        $field->setReturnType('silverstripe');
112
        $field->setValue($this->getFixture('array'));
113
        $this->assertInternalType('array', $field->query('->', 5));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
114
        $this->assertInstanceOf('Int', $field->query('->', 5)[5]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
115
        $this->assertEquals(101, $field->query('->', 5)[5]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
116
117
        // Data Source: Array
118
        // Return Type: SILVERSTRIPE
119
        // Operator: "->" (Int)
120
        // SS Type: Varchar
121
        $field = JSONText\Fields\JSONText::create('MyJSON');
122
        $field->setReturnType('silverstripe');
123
        $field->setValue($this->getFixture('array'));
124
        $this->assertInternalType('array', $field->query('->', 4));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
125
        $this->assertInstanceOf('Varchar', $field->query('->', 4)[4]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
126
        $this->assertEquals('buick', $field->query('->', 4)[4]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
127
128
        // Test: Empty #1
129
        $field = JSONText\Fields\JSONText::create('MyJSON');
130
        $field->setReturnType('array');
131
        $field->setValue('');
132
        $this->assertInternalType('array', $field->query('->', 3));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
133
        $this->assertCount(0, $field->query('->', 3));
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<JSONTextQueryTest>.

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...
134
135
        // Test: Empty #2
136
        $field = JSONText\Fields\JSONText::create('MyJSON');
137
        $field->setReturnType('array');
138
        $field->setValue('["morris"]');
139
        $this->assertEquals([], $field->query('->', 17));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
140
141
        // Test: Invalid #1
142
        $field = JSONText\Fields\JSONText::create('MyJSON');
143
        $field->setReturnType('array');
144
        $field->setValue('["trabant"]');
145
        $this->assertEquals([], $field->query('->', 1));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
146
147
        // Test: Invalid #2
148
        $field = JSONText\Fields\JSONText::create('MyJSON');
149
        $field->setReturnType('array');
150
        $field->setValue('{');
151
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextQueryTest>.

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...
152
        $field->query('->', 3);
153
    }
154
155
    /**
156
     * Tests query() by means of the integer Postgres String match operator: '->>'
157
     */
158
    public function testQueryWithMatchOnStr()
159
    {
160
        // Data Source: Object
161
        // Return Type: ARRAY
162
        // Operator: "->>" (String)
163
        $field = JSONText\Fields\JSONText::create('MyJSON');
164
        $field->setReturnType('array');
165
        $field->setValue($this->getFixture('object'));
166
        $this->assertEquals(['Subaru' => 'Impreza'], $field->query('->>', 'Subaru'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
167
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
168
            ['japanese' => ['fast' => ['Subaru' => 'Impreza'], 'slow' => ['Honda' => 'Civic']]],
169
            $field->query('->>', 'japanese')
170
        );
171
172
        // Data Source: Object
173
        // Return Type: JSON
174
        // Operator: "->>" (String)
175
        $field = JSONText\Fields\JSONText::create('MyJSON');
176
        $field->setReturnType('json');
177
        $field->setValue($this->getFixture('object'));
178
        $this->assertEquals('{"Subaru":"Impreza"}', $field->query('->>', 'Subaru'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
179
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
180
            '{"japanese":{"fast":{"Subaru":"Impreza"},"slow":{"Honda":"Civic"}}}',
181
            $field->query('->>', 'japanese')
182
        );
183
184
        // Data Source: Object
185
        // Return Type: SilverStripe
186
        // Operator: "->>" (String)
187
        // SS Type: Varchar
188
        $field = JSONText\Fields\JSONText::create('MyJSON');
189
        $field->setReturnType('silverstripe');
190
        $field->setValue($this->getFixture('object'));
191
        $this->assertInternalType('array', $field->query('->>', 'Subaru'));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
192
        $this->assertInstanceOf('Varchar', $field->query('->>', 'Subaru')['Subaru']);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
193
        $this->assertEquals('Impreza', $field->query('->>', 'Subaru')['Subaru']->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
194
195
        // Data Source: Object
196
        // Return Type: SilverStripe
197
        // Operator: "->>" (String)
198
        // SS Type: Boolean
199
        $field = JSONText\Fields\JSONText::create('MyJSON');
200
        $field->setReturnType('silverstripe');
201
        $field->setValue($this->getFixture('object'));
202
        $this->assertInternalType('array', $field->query('->>', 'beer tastes good'));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
203
        $this->assertInstanceOf('Boolean', $field->query('->>', 'beer tastes good')['beer tastes good']);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
204
        $this->assertEquals(1, $field->query('->>', 'beer tastes good')['beer tastes good']->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
205
206
        // Data Source: Object
207
        // Return Type: SilverStripe
208
        // Operator: "->>" (String)
209
        // SS Type: Float
210
        $field = JSONText\Fields\JSONText::create('MyJSON');
211
        $field->setReturnType('silverstripe');
212
        $field->setValue($this->getFixture('object'));
213
        $this->assertInternalType('array', $field->query('->>', 'how sure are you'));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
214
        $this->assertInstanceOf('Float', $field->query('->>', 'how sure are you')['how sure are you']);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
215
        $this->assertEquals(99.99, $field->query('->>', 'how sure are you')['how sure are you']->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
216
217
        // Data Source: Object
218
        // Return Type: SilverStripe
219
        // Operator: "->>" (String)
220
        // SS Type: Int
221
        $field = JSONText\Fields\JSONText::create('MyJSON');
222
        $field->setReturnType('silverstripe');
223
        $field->setValue($this->getFixture('object'));
224
        $this->assertInternalType('array', $field->query('->>', 'how high'));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
225
        $this->assertInstanceOf('Int', $field->query('->>', 'how high')['how high']);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
226
        $this->assertEquals(6, $field->query('->>', 'how high')['how high']->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
227
228
        // Data Source: Object
229
        // Return Type: SilverStripe
230
        // Operator: "->>" (String)
231
        // SS Type: N/A Nested sub-array example, expect an array
232
        $field = JSONText\Fields\JSONText::create('MyJSON');
233
        $field->setReturnType('silverstripe');
234
        $field->setValue($this->getFixture('object'));
235
        $this->assertInternalType('array', $field->query('->>', 'planes')['planes']);
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
236
        $this->assertInternalType('array', $field->query('->>', 'planes')['planes']['russian']);
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
237
        $this->assertCount(2, $field->query('->>', 'planes')['planes']['russian']);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<JSONTextQueryTest>.

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...
238
        $this->assertInstanceOf('Varchar', $field->query('->>', 'planes')['planes']['russian'][0]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
239
        $this->assertInstanceOf('Varchar', $field->query('->>', 'planes')['planes']['russian'][1]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
240
241
        // Test: Empty #1
242
        $field = JSONText\Fields\JSONText::create('MyJSON');
243
        $field->setReturnType('array');
244
        $field->setValue('');
245
        $this->assertInternalType('array', $field->query('->>', 'planes'));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
246
        $this->assertCount(0, $field->query('->', 3));
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<JSONTextQueryTest>.

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...
247
248
        // Test: Empty #2
249
        $field = JSONText\Fields\JSONText::create('MyJSON');
250
        $field->setReturnType('array');
251
        $field->setValue('["morris"]');
252
        $this->assertEquals([], $field->query('->', 17));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
253
254
        // Test: Invalid #1
255
        $field = JSONText\Fields\JSONText::create('MyJSON');
256
        $field->setReturnType('array');
257
        $field->setValue('["trabant"]');
258
        $this->assertEquals([], $field->query('->', 1));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
259
260
        // Test: Invalid #2
261
        $field = JSONText\Fields\JSONText::create('MyJSON');
262
        $field->setReturnType('array');
263
        $field->setValue('{');
264
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextQueryTest>.

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...
265
        $field->query('->', 3);
266
    }
267
268
    /**
269
     * Tests query() by means of the Postgres path-match operator: '#>'
270
     */
271
    public function testQueryWithMatchOnPath()
272
    {
273
        // Data Source: Object
274
        // Return Type: ARRAY
275
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
276
        // Expect: Array due to duplicate keys in different parts of the source data
277
        $field = JSONText\Fields\JSONText::create('MyJSON');
278
        $field->setReturnType('array');
279
        $field->setValue($this->getFixture('object'));
280
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
281
            [['Subaru' => 'Impreza'],['Kawasaki' => 'KR1S250']],
282
            $field->query('#>', '{"japanese":"fast"}')
283
        );
284
285
        // Data Source: Object
286
        // Return Type: JSON
287
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
288
        // Expect: Array due to duplicate keys in different parts of the source data
289
        $field = JSONText\Fields\JSONText::create('MyJSON');
290
        $field->setReturnType('json');
291
        $field->setValue($this->getFixture('object'));
292
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
293
            '[{"Subaru":"Impreza"},{"Kawasaki":"KR1S250"}]',
294
            $field->query('#>', '{"japanese":"fast"}')
295
        );
296
297
        // Data Source: Object
298
        // Return Type: SILVERSTRIPE
299
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
300
        // Expect: Array due to duplicate keys in different parts of the source data
301
        $field = JSONText\Fields\JSONText::create('MyJSON');
302
        $field->setReturnType('silverstripe');
303
        $field->setValue($this->getFixture('object'));
304
        $this->assertInternalType('array', $field->query('#>', '{"japanese":"fast"}'));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
305
        $this->assertCount(2, $field->query('#>', '{"japanese":"fast"}'));
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<JSONTextQueryTest>.

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...
306
        
307
        $one = $field->query('#>', '{"japanese":"fast"}')[0];
308
        $two = $field->query('#>', '{"japanese":"fast"}')[1];
309
        
310
        $this->assertInternalType('array', $one);
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
311
        $this->assertInternalType('array', $two);
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
312
        $this->assertInstanceOf('Varchar', array_values($one)[0]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
313
        $this->assertInstanceOf('Varchar', array_values($two)[0]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
314
        $this->assertEquals('Impreza', array_values($one)[0]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
315
        $this->assertEquals('KR1S250', array_values($two)[0]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
316
317
        // Data Source: Object
318
        // Return Type: ARRAY
319
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
320
        // Expect: Direct scalar comparison assertion
321
        $field = JSONText\Fields\JSONText::create('MyJSON');
322
        $field->setReturnType('array');
323
        $field->setValue($this->getFixture('object'));
324
        $this->assertEquals(['airbus'], $field->query('#>', '{"planes":"french"}'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
325
326
        // Data Source: Object
327
        // Return Type: JSON
328
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
329
        // Expect: Direct scalar comparison assertion
330
        $field = JSONText\Fields\JSONText::create('MyJSON');
331
        $field->setReturnType('json');
332
        $field->setValue($this->getFixture('object'));
333
        $this->assertEquals('["airbus"]', $field->query('#>', '{"planes":"french"}'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
334
335
        // Data Source: Object
336
        // Return Type: SILVERSTRIPE
337
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
338
        // Expect: Direct scalar comparison assertion (Varchar)
339
        $field = JSONText\Fields\JSONText::create('MyJSON');
340
        $field->setReturnType('silverstripe');
341
        $field->setValue($this->getFixture('object'));
342
        $this->assertInternalType('array', $field->query('#>', '{"planes":"french"}'));
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
343
        $this->assertInstanceOf('Varchar', $field->query('#>', '{"planes":"french"}')[0]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
344
        $this->assertEquals('airbus', $field->query('#>', '{"planes":"french"}')[0]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
345
346
        // Data Source: Object
347
        // Return Type: SILVERSTRIPE
348
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
349
        // Expect: Direct scalar comparison assertion (Float)
350
        $field = JSONText\Fields\JSONText::create('MyJSON');
351
        $field->setReturnType('silverstripe');
352
        $field->setValue($this->getFixture('object'));
353
        
354
        $res = $field->query('#>', '{"floats":"0"}');
355
        
356
        $this->assertInternalType('array', $res);
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
357
        $this->assertInternalType('array', $res[0]); // Why? Because value of "floats" key is a JSON array
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
358
        $this->assertInstanceOf('Float', array_values($res[0])[0]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
359
        $this->assertEquals(99.99, array_values($res[0])[0]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
360
361
        // Data Source: Object
362
        // Return Type: SILVERSTRIPE
363
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
364
        // Expect: Direct scalar comparison assertion (Int)
365
        $field = JSONText\Fields\JSONText::create('MyJSON');
366
        $field->setReturnType('silverstripe');
367
        $field->setValue($this->getFixture('object'));
368
369
        $res = $field->query('#>', '{"ints":"0"}');
370
371
        $this->assertInternalType('array', $res);
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
372
        $this->assertInternalType('array', $res[0]); // Why? Because value of "floats" key is a JSON array
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
373
        $this->assertInstanceOf('Int', array_values($res[0])[1]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
374
        $this->assertEquals(6, array_values($res[0])[1]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
375
376
        // Data Source: Object
377
        // Return Type: SILVERSTRIPE
378
        // Operator: "#>" (Path)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
379
        // Expect: Direct scalar comparison assertion (Boolean)
380
        $field = JSONText\Fields\JSONText::create('MyJSON');
381
        $field->setReturnType('silverstripe');
382
        $field->setValue($this->getFixture('object'));
383
384
        $res = $field->query('#>', '{"booleans":"0"}');
385
386
        $this->assertInternalType('array', $res);
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
387
        $this->assertInternalType('array', $res[0]); // Why? Because value of "booleans" key is a JSON array
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextQueryTest>.

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...
388
        $this->assertInstanceOf('Boolean', array_values($res[0])[0]);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<JSONTextQueryTest>.

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...
389
        $this->assertEquals(1, array_values($res[0])[0]->getValue());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
390
391
        // #1 Empty source data
392
        $field = JSONText\Fields\JSONText::create('MyJSON');
393
        $field->setReturnType('array');
394
        $field->setValue('');
395
        $this->assertEquals([], $field->query('#>', '{"japanese":"fast"}'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
396
397
        // #2 JSON path not found
398
        $field = JSONText\Fields\JSONText::create('MyJSON');
399
        $field->setReturnType('silverstripe');
400
        $field->setValue($this->getFixture('object'));
401
        $this->assertNull($field->query('#>', '{"ints":"1"}')); // The "ints" key only has a single array as a value
0 ignored issues
show
Bug introduced by
The method assertNull() does not seem to exist on object<JSONTextQueryTest>.

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...
402
403
        // #3 Invalid operand on RHS
404
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextQueryTest>.

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...
405
        $field = JSONText\Fields\JSONText::create('MyJSON');
406
        $field->setReturnType('array');
407
        $field->setValue($this->getFixture('object'));
408
        $this->assertEquals(['Kawasaki' => 'KR1S250'], $field->query('#>', '{"japanese":"fast"'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextQueryTest>.

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...
409
    }
410
    
411
    /**
412
     * Get the contents of a fixture
413
     * 
414
     * @param string $fixture
415
     * @return string
416
     */
417
    private function getFixture($fixture)
418
    {
419
        $files = $this->fixtures;
420
        return file_get_contents($files[$fixture]);
421
    }
422
423
}
424