Completed
Push — master ( 83f346...123e90 )
by Russell
06:33
created

JSONTextTest::testquery_AsStr_AsArray()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 1
eloc 15
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'  => MODULE_DIR . '/tests/fixtures/json/array_simple.json',
19
        'hash_simple'   => MODULE_DIR . '/tests/fixtures/json/hash_simple.json',
20
        'invalid'       => MODULE_DIR . '/tests/fixtures/json/invalid.json',
21
        'hash_deep'     => MODULE_DIR . '/tests/fixtures/json/hash_deep.json',
22
        'hash_dupes'    => MODULE_DIR . '/tests/fixtures/json/hash_duplicates.json',
23
        'empty'         => MODULE_DIR . '/tests/fixtures/json/empty.json'
24
    ];
25
    
26
    public function testgetValueAsIterable()
27
    {
28
        $field = JSONText\Fields\JSONText::create('MyJSON');
29
        $field->setValue($this->getFixture('invalid'));
30
        $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...
31
        $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...
32
33
        $field = JSONText\Fields\JSONText::create('MyJSON');
34
        $field->setValue($this->getFixture('empty'));
35
        $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...
36
    }
37
38 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...
39
    {
40
        $field = JSONText\Fields\JSONText::create('MyJSON');
41
        $field->setValue($this->getFixture('array_simple'));
42
        $field->setReturnType('array');
43
        $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...
44
45
        $field = JSONText\Fields\JSONText::create('MyJSON');
46
        $field->setValue($this->getFixture('empty'));
47
        $field->setReturnType('array');
48
        $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...
49
        $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...
50
    }
51
52 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...
53
    {
54
        $field = JSONText\Fields\JSONText::create('MyJSON');
55
        $field->setValue($this->getFixture('array_simple'));
56
        $field->setReturnType('json');
57
        $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...
58
59
        $field = JSONText\Fields\JSONText::create('MyJSON');
60
        $field->setValue($this->getFixture('empty'));
61
        $field->setReturnType('json');
62
        $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...
63
        $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...
64
    }
65
66 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...
67
    {
68
        $field = JSONText\Fields\JSONText::create('MyJSON');
69
        $field->setValue($this->getFixture('array_simple'));
70
        $field->setReturnType('array');
71
        $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...
72
73
        $field = JSONText\Fields\JSONText::create('MyJSON');
74
        $field->setValue($this->getFixture('empty'));
75
        $field->setReturnType('array');
76
        $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...
77
        $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...
78
    }
79
80 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...
81
    {
82
        $field = JSONText\Fields\JSONText::create('MyJSON');
83
        $field->setValue($this->getFixture('array_simple'));
84
        $field->setReturnType('json');
85
        $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...
86
87
        $field = JSONText\Fields\JSONText::create('MyJSON');
88
        $field->setValue($this->getFixture('empty'));
89
        $field->setReturnType('json');
90
        $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...
91
        $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...
92
    }
93
94
    public function testNth_AsArray()
95
    {
96
        $field = JSONText\Fields\JSONText::create('MyJSON');
97
        $field->setValue($this->getFixture('array_simple'));
98
        $field->setReturnType('array');
99
        $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...
100
        $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...
101
102
        $field = JSONText\Fields\JSONText::create('MyJSON');
103
        $field->setValue($this->getFixture('empty'));
104
        $field->setReturnType('array');
105
        $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...
106
        $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...
107
108
        $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...
109
        $field = JSONText\Fields\JSONText::create('MyJSON');
110
        $field->setValue($this->getFixture('hash_simple'));
111
        $field->setReturnType('array');
112
        $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...
113
    }
114
115
    public function testNth_AsJson()
116
    {
117
        $field = JSONText\Fields\JSONText::create('MyJSON');
118
        $field->setValue($this->getFixture('array_simple'));
119
        $field->setReturnType('json');
120
        $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...
121
        $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...
122
123
        $field = JSONText\Fields\JSONText::create('MyJSON');
124
        $field->setValue($this->getFixture('empty'));
125
        $field->setReturnType('json');
126
        $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...
127
        $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...
128
129
        $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...
130
        $field = JSONText\Fields\JSONText::create('MyJSON');
131
        $field->setValue($this->getFixture('hash_simple'));
132
        $field->setReturnType('json');
133
        $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...
134
    }
135
136
    /**
137
     * Tests query() by means of the integer Postgres operator: '->'
138
     */
139
    public function testQuery_MatchOnKeyAsInt_AsArray()
140
    {
141
        // Hashed
142
        $field = JSONText\Fields\JSONText::create('MyJSON');
143
        $field->setValue($this->getFixture('hash_simple'));
144
        $field->setReturnType('array');
145
        
146
        $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...
147
        $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...
148
        $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...
149
150
        // Empty
151
        $field = JSONText\Fields\JSONText::create('MyJSON');
152
        $field->setValue($this->getFixture('empty'));
153
        $field->setReturnType('array');
154
        $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...
155
156
        // Nested
157
        $field = JSONText\Fields\JSONText::create('MyJSON');
158
        $field->setValue($this->getFixture('hash_deep'));
159
        $field->setReturnType('array');
160
        
161
        $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...
162
        $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...
163
        $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...
164
    }
165
166
    /**
167
     * Tests query() by means of the string Postgres operator: '->>'
168
     */
169
    public function testQuery_MatchOnKeyAsStr_AsArray()
170
    {
171
        // Hashed
172
        $field = JSONText\Fields\JSONText::create('MyJSON');
173
        $field->setValue($this->getFixture('hash_simple'));
174
        $field->setReturnType('array');
175
176
        $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...
177
        $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...
178
179
        // Empty
180
        $field = JSONText\Fields\JSONText::create('MyJSON');
181
        $field->setValue($this->getFixture('empty'));
182
        $field->setReturnType('array');
183
        $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...
184
185
        // Nested
186
        $field = JSONText\Fields\JSONText::create('MyJSON');
187
        $field->setValue($this->getFixture('hash_deep'));
188
        $field->setReturnType('array');
189
190
        $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...
191
        $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...
192
    }
193
194
    /**
195
     * Tests query() by means of the string Postgres operator: '->>'
196
     */
197
    public function testQuery_MatchOnKeyAsStr_AsJSON()
198
    {
199
        // Hashed
200
        $field = JSONText\Fields\JSONText::create('MyJSON');
201
        $field->setValue($this->getFixture('hash_simple'));
202
        $field->setReturnType('json');
203
204
        $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...
205
        $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...
206
207
        // Empty
208
        $field = JSONText\Fields\JSONText::create('MyJSON');
209
        $field->setValue($this->getFixture('empty'));
210
        $field->setReturnType('json');
211
        $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...
212
213
        // Nested
214
        $field = JSONText\Fields\JSONText::create('MyJSON');
215
        $field->setValue($this->getFixture('hash_deep'));
216
        $field->setReturnType('json');
217
218
        $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...
219
        $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...
220
    }
221
222
    /**
223
     * Tests query() by means of path-matching using the Postgres path match operator: '#>'
224
     */
225
    public function testQuery_MatchPath_AsArray()
226
    {
227
        // Hashed
228
        $field = JSONText\Fields\JSONText::create('MyJSON');
229
        $field->setValue($this->getFixture('hash_deep'));
230
        $field->setReturnType('array');
231
        
232
        $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...
233
234
        $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...
235
        $field->query('#>', '{"bikes","japanese"}'); // Bad JSON
236
    }
237
238
    /**
239
     * Tests query() by means of path-matching using the Postgres path match operator: '#>'
240
     */
241
    public function testQuery_MatchPath_AsJSON()
242
    {
243
        // Hashed
244
        $field = JSONText\Fields\JSONText::create('MyJSON');
245
        $field->setValue($this->getFixture('hash_deep'));
246
        $field->setReturnType('json');
247
        
248
        $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...
249
    }
250
    
251
    /**
252
     * Get the contents of a fixture
253
     * 
254
     * @return string
255
     */
256
    private function getFixture($fixture)
257
    {
258
        $files = $this->fixtures;
259
        return file_get_contents($files[$fixture]);
260
    }
261
262
}
263