Completed
Push — master ( 0d7657...df0666 )
by Russell
07:37
created

testExceptionThrownOnBeforeWrite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
/**
4
 * @package silverstripe-jsontext
5
 * @subpackage fields
6
 * @author Russell Michell <[email protected]>
7
 */
8
9
class JSONTextExtensionTest extends FunctionalTest
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...
10
{
11
    /**
12
     * @var string
13
     */
14
    protected static $fixture_file = 'jsontext/tests/fixtures/yml/JSONTextExtension.yml';
15
    
16
    /**
17
     * Ensure our TestOnly DO's are usable as fixtures in the test DB
18
     * 
19
     * @var array
20
     */
21
	protected $extraDataObjects = [
22
		'JSONTextTestPage',
23
	];
24
    
25
    /**
26
     * Is an exception thrown when no POSTed vars are available for
27
     * non DB-backed fields declared on a SiteTree class?
28
     */
29
    public function testExceptionThrownOnBeforeWrite()
30
    {
31
        $member = $this->objFromFixture('Member', 'admin');
32
        $this->session()->inst_set('loggedInAs', $member->ID);
33
        $fixture = $this->objFromFixture('JSONTextTestPage', 'jsontext-text');
0 ignored issues
show
Unused Code introduced by
$fixture is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
        
35
        $this->setExpectedException('\JSONText\Exceptions\JSONTextException', "FooField doesn't exist in POST data.");
0 ignored issues
show
Bug introduced by
The method setExpectedException() does not seem to exist on object<JSONTextExtensionTest>.

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
        $response = $this->post('admin/pages/edit/EditForm', [
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
            'Title' => 'Dummy',
39
            'URLSegment' => 'dummy',
40
			'action_save' => 1,
41
			'ID' => 44,
42
            'ParentID' => 1,
43
		]);
44
    }
45
}
46
47
class JSONTextTestPage extends Page implements TestOnly
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
48
{
49
    private static $db = [
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
50
        'MyJSON' => 'JSONText'
51
    ];
52
    
53
    private static $json_field_map = [
0 ignored issues
show
Unused Code introduced by
The property $json_field_map is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
54
        'MyJSON' => ['FooField']
55
    ];
56
    
57
}
58