Completed
Push — master ( 5cb32a...c1f2b6 )
by Russell
02:22
created

JSONTextTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 17
Bugs 4 Features 7
Metric Value
wmc 2
c 17
b 4
f 7
lcom 0
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsExpressionValid() 0 10 1
A testIsJson() 0 16 1
1
<?php
2
3
/**
4
 * @package silverstripe-jsontext
5
 * @subpackage fields
6
 * @author Russell Michell <[email protected]>
7
 */
8
9
use JSONText\Fields\JSONText;
10
11
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...
12
{
13
    /**
14
     * @todo There are a ton more permutations of a JSONPath regex
15
     * See the walk() method in JSONStore
16
     */
17
    public function testIsExpressionValid()
18
    {
19
        $field = JSONText::create('MyJSON');
20
        
21
        $this->assertTrue($field->isValidExpression('$..'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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...
22
        $this->assertTrue($field->isValidExpression('$.[2]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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...
23
        $this->assertTrue($field->isValidExpression('$.cars.american[*]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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...
24
        $this->assertFalse($field->isValidExpression('$'));
0 ignored issues
show
Bug introduced by
The method assertFalse() 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...
25
        $this->assertFalse($field->isValidExpression('$[2]'));
0 ignored issues
show
Bug introduced by
The method assertFalse() 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...
26
    }
27
28
    /**
29
     * Ordinarily we can just use !is_null(json_decode($json)) but SS allows empty strings passed to setValue() so we need
30
     * to allow otherwise invalid JSON by means of an optional 2nd param
31
     */
32
    public function testIsJson()
33
    {
34
        $field = JSONText::create('MyJSON');
35
36
        $this->assertFalse($field->isJson(''));
0 ignored issues
show
Bug introduced by
The method assertFalse() 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...
37
        $this->assertTrue($field->isJson('true'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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...
38
        $this->assertTrue($field->isJson('false'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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...
39
        $this->assertFalse($field->isJson('null'));
0 ignored issues
show
Bug introduced by
The method assertFalse() 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...
40
        $this->assertFalse($field->isJson("['one']"));
0 ignored issues
show
Bug introduced by
The method assertFalse() 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...
41
        $this->assertFalse($field->isJson('["one]'));
0 ignored issues
show
Bug introduced by
The method assertFalse() 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...
42
        $this->assertTrue($field->isJson('[]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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->assertTrue($field->isJson('["one"]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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->assertTrue($field->isJson('["one","two"]'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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
        $this->assertTrue($field->isJson('{"cars":{"american":["buick","oldsmobile"]}}'));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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...
46
        $this->assertTrue($field->isJson('', ['']));
0 ignored issues
show
Bug introduced by
The method assertTrue() 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...
47
    }
48
}
49