Completed
Push — master ( 471861...67ffab )
by Russell
02:40
created

JSONTextTest::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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