Completed
Push — master ( dacd10...9a508f )
by Russell
03:06
created

testQuery_MatchPathDuplicate_AsJSON()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 9
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package silverstripe-jsontext
5
 * @subpackage fields
6
 * @author Russell Michell <[email protected]>
7
 */
8
9
use JSONText\Fields;
10
use JSONText\Exceptions;
11
12
class JSONTextTest 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...
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $fixtures = [
18
        'array_simple'  => 'tests/fixtures/json/array_simple.json',
19
        'hash_simple'   => 'tests/fixtures/json/hash_simple.json',
20
        'invalid'       => 'tests/fixtures/json/invalid.json',
21
        'hash_deep'     => 'tests/fixtures/json/hash_deep.json',
22
        'hash_dupes'    => 'tests/fixtures/json/hash_duplicated.json',
23
        'empty'         => 'tests/fixtures/json/empty.json',
24
        'minimal_bool'  => 'tests/fixtures/json/minimal_bool.json'
25
    ];
26
27
    /**
28
     * JSONTextTest constructor.
29
     * 
30
     * Modify fixtures property to be able to run on PHP <5.6 without use of constant in class property which 5.6+ allows
31
     */
32
    public function __construct()
33
    {
34
        foreach($this->fixtures as $name => $path) {
35
            $this->fixtures[$name] = MODULE_DIR . '/' . $path;
36
        }
37
    }
38
39
    public function testgetValueAsIterable()
40
    {
41
        $field = JSONText\Fields\JSONText::create('MyJSON');
42
        $field->setValue($this->getFixture('invalid'));
43
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextTest>.

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...
44
        $this->assertEquals(['chinese' => 'great wall'], $field->getValueAsIterable());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
45
46
        $field = JSONText\Fields\JSONText::create('MyJSON');
47
        $field->setValue($this->getFixture('empty'));
48
        $this->assertEquals([], $field->getValueAsIterable());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
49
    }
50
51 View Code Duplication
    public function testFirst_AsArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
52
    {
53
        $field = JSONText\Fields\JSONText::create('MyJSON');
54
        $field->setValue($this->getFixture('array_simple'));
55
        $field->setReturnType('array');
56
        $this->assertEquals([0 => 'great wall'], $field->first());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
57
58
        $field = JSONText\Fields\JSONText::create('MyJSON');
59
        $field->setValue($this->getFixture('empty'));
60
        $field->setReturnType('array');
61
        $this->assertInternalType('array', $field->first());
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextTest>.

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

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...
63
    }
64
65 View Code Duplication
    public function testFirst_AsJson()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
66
    {
67
        $field = JSONText\Fields\JSONText::create('MyJSON');
68
        $field->setValue($this->getFixture('array_simple'));
69
        $field->setReturnType('json');
70
        $this->assertEquals('["great wall"]', $field->first());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
71
72
        $field = JSONText\Fields\JSONText::create('MyJSON');
73
        $field->setValue($this->getFixture('empty'));
74
        $field->setReturnType('json');
75
        $this->assertInternalType('string', $field->first());
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextTest>.

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

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...
77
    }
78
79 View Code Duplication
    public function testLast_AsArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
80
    {
81
        $field = JSONText\Fields\JSONText::create('MyJSON');
82
        $field->setValue($this->getFixture('array_simple'));
83
        $field->setReturnType('array');
84
        $this->assertEquals([6 => 'morris'], $field->last());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
85
86
        $field = JSONText\Fields\JSONText::create('MyJSON');
87
        $field->setValue($this->getFixture('empty'));
88
        $field->setReturnType('array');
89
        $this->assertInternalType('array', $field->first());
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextTest>.

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

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...
91
    }
92
93 View Code Duplication
    public function testLast_AsJson()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
94
    {
95
        $field = JSONText\Fields\JSONText::create('MyJSON');
96
        $field->setValue($this->getFixture('array_simple'));
97
        $field->setReturnType('json');
98
        $this->assertEquals('{"6":"morris"}', $field->last());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
99
100
        $field = JSONText\Fields\JSONText::create('MyJSON');
101
        $field->setValue($this->getFixture('empty'));
102
        $field->setReturnType('json');
103
        $this->assertInternalType('string', $field->first());
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextTest>.

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

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
107
    public function testNth_AsArray()
108
    {
109
        $field = JSONText\Fields\JSONText::create('MyJSON');
110
        $field->setValue($this->getFixture('array_simple'));
111
        $field->setReturnType('array');
112
        $this->assertEquals([0 => 'great wall'], $field->nth(0));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
113
        $this->assertEquals([2 => 'trabant'], $field->nth(2));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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
115
        $field = JSONText\Fields\JSONText::create('MyJSON');
116
        $field->setValue($this->getFixture('empty'));
117
        $field->setReturnType('array');
118
        $this->assertInternalType('array', $field->first());
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextTest>.

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

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...
120
121
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextTest>.

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...
122
        $field = JSONText\Fields\JSONText::create('MyJSON');
123
        $field->setValue($this->getFixture('hash_simple'));
124
        $field->setReturnType('array');
125
        $this->assertEquals(['british' => ['vauxhall', 'morris']], $field->nth('2'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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
    }
127
128
    public function testNth_AsJson()
129
    {
130
        $field = JSONText\Fields\JSONText::create('MyJSON');
131
        $field->setValue($this->getFixture('array_simple'));
132
        $field->setReturnType('json');
133
        $this->assertEquals('["great wall"]', $field->nth(0));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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

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...
135
136
        $field = JSONText\Fields\JSONText::create('MyJSON');
137
        $field->setValue($this->getFixture('empty'));
138
        $field->setReturnType('json');
139
        $this->assertInternalType('string', $field->first());
0 ignored issues
show
Bug introduced by
The method assertInternalType() does not seem to exist on object<JSONTextTest>.

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

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...
141
142
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextTest>.

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...
143
        $field = JSONText\Fields\JSONText::create('MyJSON');
144
        $field->setValue($this->getFixture('hash_simple'));
145
        $field->setReturnType('json');
146
        $this->assertEquals('{"british":["vauxhall","morris"]}', $field->nth('2'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
147
    }
148
149
    /**
150
     * Tests query() by means of the integer Postgres operator: '->'
151
     */
152
    public function testQuery_MatchOnKeyAsInt_AsArray()
153
    {
154
        // Hashed
155
        $field = JSONText\Fields\JSONText::create('MyJSON');
156
        $field->setValue($this->getFixture('hash_simple'));
157
        $field->setReturnType('array');
158
        
159
        $this->assertEquals(['british' => ['vauxhall', 'morris']], $field->query('->', 5));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
160
        $this->assertEquals(['american' => ['buick', 'oldsmobile', 'ford']], $field->query('->', 1));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
161
        $this->assertEquals([], $field->query('->', '6')); // strict handling
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
162
163
        // Empty
164
        $field = JSONText\Fields\JSONText::create('MyJSON');
165
        $field->setValue($this->getFixture('empty'));
166
        $field->setReturnType('array');
167
        $this->assertEquals([], $field->query('->', 42));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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
169
        // Nested
170
        $field = JSONText\Fields\JSONText::create('MyJSON');
171
        $field->setValue($this->getFixture('hash_deep'));
172
        $field->setReturnType('array');
173
        
174
        $this->assertEquals(['planes' => ['russian' => ['antonov', 'mig'], 'french' => 'airbus']], $field->query('->', 7));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
175
        $this->assertEquals([], $field->query('->', '7')); // Attempt to match a string using the int matcher 
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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

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...
177
    }
178
179
    /**
180
     * Tests query() by means of the string Postgres operator: '->>'
181
     */
182
    public function testQuery_MatchOnKeyAsStr_AsArray()
183
    {
184
        // Hashed
185
        $field = JSONText\Fields\JSONText::create('MyJSON');
186
        $field->setValue($this->getFixture('hash_simple'));
187
        $field->setReturnType('array');
188
189
        $this->assertEquals(['british' => ['vauxhall', 'morris']], $field->query('->>', 'british'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
190
        $this->assertEquals([], $field->query('->', '6')); // strict handling
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
191
192
        // Empty
193
        $field = JSONText\Fields\JSONText::create('MyJSON');
194
        $field->setValue($this->getFixture('empty'));
195
        $field->setReturnType('array');
196
        $this->assertEquals([], $field->query('->>', 'british'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
197
198
        // Nested
199
        $field = JSONText\Fields\JSONText::create('MyJSON');
200
        $field->setValue($this->getFixture('hash_deep'));
201
        $field->setReturnType('array');
202
203
        $this->assertEquals(['planes' => ['russian' => ['antonov', 'mig'], 'french' => 'airbus']], $field->query('->>', 'planes'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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([], $field->query('->', '7')); // Attempt to match a string using the int matcher
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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
207
    /**
208
     * Tests query() by means of the string Postgres operator: '->>'
209
     */
210
    public function testQuery_MatchOnKeyAsStr_AsJSON()
211
    {
212
        // Hashed
213
        $field = JSONText\Fields\JSONText::create('MyJSON');
214
        $field->setValue($this->getFixture('hash_simple'));
215
        $field->setReturnType('json');
216
217
        $this->assertEquals('{"british":["vauxhall","morris"]}', $field->query('->>', 'british'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
218
        $this->assertEquals('[]', $field->query('->', '6')); // strict handling
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
219
220
        // Empty
221
        $field = JSONText\Fields\JSONText::create('MyJSON');
222
        $field->setValue($this->getFixture('empty'));
223
        $field->setReturnType('json');
224
        $this->assertEquals('[]', $field->query('->>', 'british'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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
226
        // Nested
227
        $field = JSONText\Fields\JSONText::create('MyJSON');
228
        $field->setValue($this->getFixture('hash_deep'));
229
        $field->setReturnType('json');
230
231
        $this->assertEquals('{"planes":{"russian":["antonov","mig"],"french":"airbus"}}', $field->query('->>', 'planes'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
232
        $this->assertEquals('[]', $field->query('->', '7')); // Attempt to match a string using the int matcher
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
233
    }
234
235
    /**
236
     * Tests query() by means of path-matching using the Postgres path match operator: '#>'
237
     */
238
    public function testQuery_MatchPath_AsArray()
239
    {
240
        // Hashed
241
        $field = JSONText\Fields\JSONText::create('MyJSON');
242
        $field->setValue($this->getFixture('hash_deep'));
243
        $field->setReturnType('array');
244
        
245
        $this->assertEquals(["fast" => ["Kawasaki" => "KR1S250"],"slow" => ["Honda" => "FS150"]], $field->query('#>', '{"bikes":"japanese"}'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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
247
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextTest>.

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...
248
        $field->query('#>', '{"bikes","japanese"}'); // Bad JSON
249
    }
250
251
    /**
252
     * Tests query() by means of path-matching using the Postgres path match operator: '#>'
253
     */
254 View Code Duplication
    public function testQuery_MatchPath_AsJSON()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
255
    {
256
        // Hashed
257
        $field = JSONText\Fields\JSONText::create('MyJSON');
258
        $field->setValue($this->getFixture('hash_deep'));
259
        $field->setReturnType('json');
260
        
261
        $this->assertEquals('{"fast":{"Kawasaki":"KR1S250"},"slow":{"Honda":"FS150"}}', $field->query('#>', '{"bikes":"japanese"}'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
262
    }
263
264
    /**
265
     * Tests query() by means of path-matching using the Postgres path match operator: '#>' but where duplicate keys exist 
266
     * for different parent structures in the source data
267
     */
268
    public function testQuery_MatchPathDuplicate_AsArray()
269
    {
270
        // Hashed
271
        $field = JSONText\Fields\JSONText::create('MyJSON');
272
        $field->setValue($this->getFixture('hash_dupes'));
273
        $field->setReturnType('array');
274
275
        $this->assertEquals([["Subaru" => "Impreza"],["Kawasaki" => "KR1S250"]], $field->query('#>', '{"japanese":"fast"}'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
276
        $this->assertEquals([], $field->query('#>', '{"":"fast"}')); // No match
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
277
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException');
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextTest>.

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...
278
        $this->assertEquals([], $field->query('#>', 1)); // Bad matcher used
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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...
279
    }
280
281
    /**
282
     * Tests query() by means of path-matching using the Postgres path match operator: '#>' but where duplicate keys exist
283
     * for different parent structures in the source data
284
     */
285 View Code Duplication
    public function testQuery_MatchPathDuplicate_AsJSON()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
286
    {
287
        // Hashed
288
        $field = JSONText\Fields\JSONText::create('MyJSON');
289
        $field->setValue($this->getFixture('hash_dupes'));
290
        $field->setReturnType('json');
291
292
        $this->assertEquals('[{"Subaru":"Impreza"},{"Kawasaki":"KR1S250"}]', $field->query('#>', '{"japanese":"fast"}'));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<JSONTextTest>.

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
    }
294
    
295
    /**
296
     * Get the contents of a fixture
297
     * 
298
     * @param string $fixture
299
     * @return string
300
     */
301
    private function getFixture($fixture)
302
    {
303
        $files = $this->fixtures;
304
        return file_get_contents($files[$fixture]);
305
    }
306
307
}
308