Completed
Push — master ( 5e28d7...78374e )
by Daniel
02:52
created

testApiAccessFieldRestrictions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 39
Code Lines 28

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 39
rs 8.8571
cc 1
eloc 28
nc 1
nop 0
1
<?php
2
/**
3
 * 
4
 * @todo Test Relation getters
5
 * @todo Test filter and limit through GET params
6
 * @todo Test DELETE verb
7
 *
8
 */
9
class RestfulServerTest 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...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
10
	
11
	static $fixture_file = 'RestfulServerTest.yml';
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $fixture_file.
Loading history...
Coding Style introduced by
The visibility should be declared for property $fixture_file.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
12
13
	protected $extraDataObjects = array(
14
		'RestfulServerTest_Comment',
15
		'RestfulServerTest_SecretThing',
16
		'RestfulServerTest_Page',
17
		'RestfulServerTest_Author',
18
		'RestfulServerTest_AuthorRating',
19
	);
20
21 View Code Duplication
	public function testApiAccess() {
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...
Coding Style introduced by
testApiAccess uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
22
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
23
		$page1 = $this->objFromFixture('RestfulServerTest_Page', 'page1');
24
		
25
		// normal GET should succeed with $api_access enabled
26
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
27
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
		$this->assertEquals($response->getStatusCode(), 200);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
29
		
30
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
31
		$_SERVER['PHP_AUTH_PW'] = 'user';
32
		
33
		// even with logged in user a GET with $api_access disabled should fail
34
		$url = "/api/v1/RestfulServerTest_Page/" . $page1->ID;
35
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
36
		$this->assertEquals($response->getStatusCode(), 401);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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
		
38
		unset($_SERVER['PHP_AUTH_USER']);
39
		unset($_SERVER['PHP_AUTH_PW']);
40
	}
41
	
42
	public function testApiAccessBoolean() {
43
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
44
		
45
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
46
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
		$this->assertContains('<ID>', $response->getBody());
48
		$this->assertContains('<Name>', $response->getBody());
49
		$this->assertContains('<Comment>', $response->getBody());
50
		$this->assertContains('<Page', $response->getBody());
51
		$this->assertContains('<Author', $response->getBody());
52
	}
53
	
54 View Code Duplication
	public function testAuthenticatedGET() {
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...
Coding Style introduced by
testAuthenticatedGET uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
55
		$thing1 = $this->objFromFixture('RestfulServerTest_SecretThing', 'thing1');
56
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
57
58
		// @todo create additional mock object with authenticated VIEW permissions
59
		$url = "/api/v1/RestfulServerTest_SecretThing/" . $thing1->ID;
60
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
		$this->assertEquals($response->getStatusCode(), 401);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
64
		$_SERVER['PHP_AUTH_PW'] = 'user';
65
		
66
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
67
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
		$this->assertEquals($response->getStatusCode(), 200);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
69
		
70
		unset($_SERVER['PHP_AUTH_USER']);
71
		unset($_SERVER['PHP_AUTH_PW']);
72
	}
73
	
74
	public function testAuthenticatedPUT() {
0 ignored issues
show
Coding Style introduced by
testAuthenticatedPUT uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
75
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
76
		
77
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
78
		$data = array('Comment' => 'created');
79
		
80
		$response = Director::test($url, $data, null, 'PUT');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
		$this->assertEquals($response->getStatusCode(), 401); // Permission failure
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
82
		
83
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
84
		$_SERVER['PHP_AUTH_PW'] = 'editor';
85
		$response = Director::test($url, $data, null, 'PUT');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
86
		$this->assertEquals($response->getStatusCode(), 200); // Success
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
87
		
88
		unset($_SERVER['PHP_AUTH_USER']);
89
		unset($_SERVER['PHP_AUTH_PW']);
90
	}
91
	
92
	public function testGETRelationshipsXML() {
93
		$author1 = $this->objFromFixture('RestfulServerTest_Author', 'author1');
94
		$rating1 = $this->objFromFixture('RestfulServerTest_AuthorRating', 'rating1');
95
		$rating2 = $this->objFromFixture('RestfulServerTest_AuthorRating', 'rating2');
96
		
97
		// @todo should be set up by fixtures, doesn't work for some reason...
98
		$author1->Ratings()->add($rating1);
99
		$author1->Ratings()->add($rating2);
100
		
101
		$url = "/api/v1/RestfulServerTest_Author/" . $author1->ID;
102
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
103
		$this->assertEquals($response->getStatusCode(), 200);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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
		$responseArr = Convert::xml2array($response->getBody());
106
		$ratingsArr = $responseArr['Ratings']['RestfulServerTest_AuthorRating'];
107
		$this->assertEquals(count($ratingsArr), 2);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
108
		$ratingIDs = array(
109
			(int)$ratingsArr[0]['@attributes']['id'], 
110
			(int)$ratingsArr[1]['@attributes']['id']
111
		);
112
		$this->assertContains($rating1->ID, $ratingIDs);
113
		$this->assertContains($rating2->ID, $ratingIDs);
114
	}
115
	
116
	public function testGETManyManyRelationshipsXML() {
117
		// author4 has related authors author2 and author3
118
		$author2 = $this->objFromFixture('RestfulServerTest_Author', 'author2');
119
		$author3 = $this->objFromFixture('RestfulServerTest_Author', 'author3');
120
		$author4 = $this->objFromFixture('RestfulServerTest_Author', 'author4');
121
		
122
		$url = "/api/v1/RestfulServerTest_Author/" . $author4->ID . '/RelatedAuthors';
123
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
124
		$this->assertEquals(200, $response->getStatusCode());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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
		$arr = Convert::xml2array($response->getBody());
126
		$authorsArr = $arr['RestfulServerTest_Author'];
127
		
128
		$this->assertEquals(count($authorsArr), 2);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
129
		$ratingIDs = array(
130
			(int)$authorsArr[0]['ID'], 
131
			(int)$authorsArr[1]['ID']
132
		);
133
		$this->assertContains($author2->ID, $ratingIDs);
134
		$this->assertContains($author3->ID, $ratingIDs);
135
	}
136
137
	public function testPUTWithFormEncoded() {
0 ignored issues
show
Coding Style introduced by
testPUTWithFormEncoded uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
138
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
139
		
140
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
141
		$_SERVER['PHP_AUTH_PW'] = 'editor';
142
	
143
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
144
		$body = 'Name=Updated Comment&Comment=updated';
145
		$headers = array(
146
			'Content-Type' => 'application/x-www-form-urlencoded'
147
		);
148
		$response = Director::test($url, null, null, 'PUT', $body, $headers);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
149
		$this->assertEquals($response->getStatusCode(), 200); // Success
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
150
		// Assumption: XML is default output
151
		$responseArr = Convert::xml2array($response->getBody());
152
		$this->assertEquals($responseArr['ID'], $comment1->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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

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...
154
		$this->assertEquals($responseArr['Name'], 'Updated Comment');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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
		unset($_SERVER['PHP_AUTH_USER']);
157
		unset($_SERVER['PHP_AUTH_PW']);
158
	}
159
	
160
	public function testPOSTWithFormEncoded() {
0 ignored issues
show
Coding Style introduced by
testPOSTWithFormEncoded uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
161
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
162
		
163
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
164
		$_SERVER['PHP_AUTH_PW'] = 'editor';
165
	
166
		$url = "/api/v1/RestfulServerTest_Comment";
167
		$body = 'Name=New Comment&Comment=created';
168
		$headers = array(
169
			'Content-Type' => 'application/x-www-form-urlencoded'
170
		);
171
		$response = Director::test($url, null, null, 'POST', $body, $headers);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
172
		$this->assertEquals($response->getStatusCode(), 201); // Created
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
173
		// Assumption: XML is default output
174
		$responseArr = Convert::xml2array($response->getBody());
175
		$this->assertTrue($responseArr['ID'] > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<RestfulServerTest>.

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->assertNotEquals($responseArr['ID'], $comment1->ID);
0 ignored issues
show
Bug introduced by
The method assertNotEquals() does not seem to exist on object<RestfulServerTest>.

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

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

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...
179
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
180
			$response->getHeader('Location'), 
181
			Controller::join_links(Director::absoluteBaseURL(), $url, $responseArr['ID'])
182
		);
183
	
184
		unset($_SERVER['PHP_AUTH_USER']);
185
		unset($_SERVER['PHP_AUTH_PW']);
186
	}
187
	
188
	public function testPUTwithJSON() {
0 ignored issues
show
Coding Style introduced by
testPUTwithJSON uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
189
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
190
		
191
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
192
		$_SERVER['PHP_AUTH_PW'] = 'editor';
193
		
194
		// by mimetype
195
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
196
		$body = '{"Comment":"updated"}';
197
		$response = Director::test($url, null, null, 'PUT', $body, array('Content-Type'=>'application/json'));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
198
		$this->assertEquals($response->getStatusCode(), 200); // Updated
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
199
		$obj = Convert::json2obj($response->getBody());
200
		$this->assertEquals($obj->ID, $comment1->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
201
		$this->assertEquals($obj->Comment, 'updated');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
202
	
203
		// by extension
204
		$url = sprintf("/api/v1/RestfulServerTest_Comment/%d.json", $comment1->ID);
205
		$body = '{"Comment":"updated"}';
206
		$response = Director::test($url, null, null, 'PUT', $body);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
207
		$this->assertEquals($response->getStatusCode(), 200); // Updated
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
208
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
209
			$response->getHeader('Location'), 
210
			Controller::join_links(Director::absoluteBaseURL(), $url)
211
		);
212
		$obj = Convert::json2obj($response->getBody());
213
		$this->assertEquals($obj->ID, $comment1->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
214
		$this->assertEquals($obj->Comment, 'updated');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
215
		
216
		unset($_SERVER['PHP_AUTH_USER']);
217
		unset($_SERVER['PHP_AUTH_PW']);
218
	}
219
	
220
	public function testPUTwithXML() {
0 ignored issues
show
Coding Style introduced by
testPUTwithXML uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
221
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
222
		
223
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
224
		$_SERVER['PHP_AUTH_PW'] = 'editor';
225
		
226
		// by mimetype
227
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
228
		$body = '<RestfulServerTest_Comment><Comment>updated</Comment></RestfulServerTest_Comment>';
229
		$response = Director::test($url, null, null, 'PUT', $body, array('Content-Type'=>'text/xml'));
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
230
		$this->assertEquals($response->getStatusCode(), 200); // Updated
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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
		$obj = Convert::xml2array($response->getBody());
232
		$this->assertEquals($obj['ID'], $comment1->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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

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...
234
	
235
		// by extension
236
		$url = sprintf("/api/v1/RestfulServerTest_Comment/%d.xml", $comment1->ID);
237
		$body = '<RestfulServerTest_Comment><Comment>updated</Comment></RestfulServerTest_Comment>';
238
		$response = Director::test($url, null, null, 'PUT', $body);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
239
		$this->assertEquals($response->getStatusCode(), 200); // Updated
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
240
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
241
			$response->getHeader('Location'), 
242
			Controller::join_links(Director::absoluteBaseURL(), $url)
243
		);
244
		$obj = Convert::xml2array($response->getBody());
245
		$this->assertEquals($obj['ID'], $comment1->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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

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
		
248
		unset($_SERVER['PHP_AUTH_USER']);
249
		unset($_SERVER['PHP_AUTH_PW']);
250
	}
251
		
252
	public function testHTTPAcceptAndContentType() {
253
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
254
		
255
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
256
		
257
		$headers = array('Accept' => 'application/json');
258
		$response = Director::test($url, null, null, 'GET', null, $headers);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
259
		$this->assertEquals($response->getStatusCode(), 200); // Success
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
260
		$obj = Convert::json2obj($response->getBody());
261
		$this->assertEquals($obj->ID, $comment1->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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
		$this->assertEquals($response->getHeader('Content-Type'), 'application/json');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
263
	}
264
	
265
	public function testNotFound(){
0 ignored issues
show
Coding Style introduced by
testNotFound uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
266
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
267
		$_SERVER['PHP_AUTH_PW'] = 'user';
268
		
269
		$url = "/api/v1/RestfulServerTest_Comment/99";
270
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
271
		$this->assertEquals($response->getStatusCode(), 404);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
272
		
273
		unset($_SERVER['PHP_AUTH_USER']);
274
		unset($_SERVER['PHP_AUTH_PW']);
275
	}
276
	
277 View Code Duplication
	public function testMethodNotAllowed() {
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...
278
		$comment1 = $this->objFromFixture('RestfulServerTest_Comment', 'comment1');
279
		
280
		$url = "/api/v1/RestfulServerTest_Comment/" . $comment1->ID;
281
		$response = Director::test($url, null, null, 'UNKNOWNHTTPMETHOD');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
282
		$this->assertEquals($response->getStatusCode(), 405);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
283
	}
284
	
285 View Code Duplication
	public function testConflictOnExistingResourceWhenUsingPost() {
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
		$rating1 = $this->objFromFixture('RestfulServerTest_AuthorRating', 'rating1');
287
		
288
		$url = "/api/v1/RestfulServerTest_AuthorRating/" . $rating1->ID;
289
		$response = Director::test($url, null, null, 'POST');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
290
		$this->assertEquals($response->getStatusCode(), 409);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
291
	}
292
	
293
	public function testUnsupportedMediaType() {
0 ignored issues
show
Coding Style introduced by
testUnsupportedMediaType uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
294
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
295
		$_SERVER['PHP_AUTH_PW'] = 'user';
296
	
297
		$url = "/api/v1/RestfulServerTest_Comment";
298
		$data = "Comment||\/||updated"; // weird format
299
		$headers = array('Content-Type' => 'text/weirdformat');
300
		$response = Director::test($url, null, null, 'POST', $data, $headers);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
301
		$this->assertEquals($response->getStatusCode(), 415);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
302
		
303
		unset($_SERVER['PHP_AUTH_USER']);
304
		unset($_SERVER['PHP_AUTH_PW']);
305
	}
306
	
307
	public function testXMLValueFormatting() {
308
		$rating1 = $this->objFromFixture('RestfulServerTest_AuthorRating','rating1');
309
		
310
		$url = "/api/v1/RestfulServerTest_AuthorRating/" . $rating1->ID;
311
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
312
		$this->assertContains('<ID>' . $rating1->ID . '</ID>', $response->getBody());
313
		$this->assertContains('<Rating>' . $rating1->Rating . '</Rating>', $response->getBody());
314
	}
315
	
316
	public function testApiAccessFieldRestrictions() {
317
		$author1 = $this->objFromFixture('RestfulServerTest_Author','author1');
318
		$rating1 = $this->objFromFixture('RestfulServerTest_AuthorRating','rating1');
319
		
320
		$url = "/api/v1/RestfulServerTest_AuthorRating/" . $rating1->ID;
321
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
322
		$this->assertContains('<ID>', $response->getBody());
323
		$this->assertContains('<Rating>', $response->getBody());
324
		$this->assertContains('<Author', $response->getBody());
325
		$this->assertNotContains('<SecretField>', $response->getBody());
326
		$this->assertNotContains('<SecretRelation>', $response->getBody());
327
		
328
		$url = "/api/v1/RestfulServerTest_AuthorRating/" . $rating1->ID . '?add_fields=SecretField,SecretRelation';
329
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
330
		$this->assertNotContains('<SecretField>', $response->getBody(),
331
			'"add_fields" URL parameter filters out disallowed fields from $api_access'
332
		);
333
		$this->assertNotContains('<SecretRelation>', $response->getBody(),
334
			'"add_fields" URL parameter filters out disallowed relations from $api_access'
335
		);
336
		
337
		$url = "/api/v1/RestfulServerTest_AuthorRating/" . $rating1->ID . '?fields=SecretField,SecretRelation';
338
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
339
		$this->assertNotContains('<SecretField>', $response->getBody(),
340
			'"fields" URL parameter filters out disallowed fields from $api_access'
341
		);
342
		$this->assertNotContains('<SecretRelation>', $response->getBody(),
343
			'"fields" URL parameter filters out disallowed relations from $api_access'
344
		);
345
		
346
		$url = "/api/v1/RestfulServerTest_Author/" . $author1->ID . '/Ratings';
347
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
348
		$this->assertContains('<Rating>', $response->getBody(),
349
			'Relation viewer shows fields allowed through $api_access'
350
		);
351
		$this->assertNotContains('<SecretField>', $response->getBody(),
352
			'Relation viewer on has-many filters out disallowed fields from $api_access'
353
		);
354
	}
355
	
356
	public function testApiAccessRelationRestrictionsInline() {
357
		$author1 = $this->objFromFixture('RestfulServerTest_Author','author1');
358
		
359
		$url = "/api/v1/RestfulServerTest_Author/" . $author1->ID;
360
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
361
		$this->assertNotContains('<RelatedPages', $response->getBody(), 'Restricts many-many with api_access=false');
362
		$this->assertNotContains('<PublishedPages', $response->getBody(), 'Restricts has-many with api_access=false');
363
	}
364
	
365
	public function testApiAccessRelationRestrictionsOnEndpoint() {
366
		$author1 = $this->objFromFixture('RestfulServerTest_Author','author1');
367
		
368
		$url = "/api/v1/RestfulServerTest_Author/" . $author1->ID . "/ProfilePage";
369
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
370
		$this->assertEquals(404, $response->getStatusCode(), 'Restricts has-one with api_access=false');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
371
		
372
		$url = "/api/v1/RestfulServerTest_Author/" . $author1->ID . "/RelatedPages";
373
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
374
		$this->assertEquals(404, $response->getStatusCode(), 'Restricts many-many with api_access=false');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
375
		
376
		$url = "/api/v1/RestfulServerTest_Author/" . $author1->ID . "/PublishedPages";
377
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
378
		$this->assertEquals(404, $response->getStatusCode(), 'Restricts has-many with api_access=false');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
379
	}
380
	
381
	public function testApiAccessWithPUT() {
382
		$rating1 = $this->objFromFixture('RestfulServerTest_AuthorRating','rating1');
383
		
384
		$url = "/api/v1/RestfulServerTest_AuthorRating/" . $rating1->ID;
385
		$data = array(
386
			'Rating' => '42',
387
			'WriteProtectedField' => 'haxx0red'
388
		);
389
		$response = Director::test($url, $data, null, 'PUT');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
390
		// Assumption: XML is default output
391
		$responseArr = Convert::xml2array($response->getBody());
392
		$this->assertEquals($responseArr['Rating'], 42);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
393
		$this->assertNotEquals($responseArr['WriteProtectedField'], 'haxx0red');
0 ignored issues
show
Bug introduced by
The method assertNotEquals() does not seem to exist on object<RestfulServerTest>.

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...
394
	}
395
396
	public function testJSONDataFormatter() {
397
		$formatter = new JSONDataFormatter();
398
		$editor = $this->objFromFixture('Member', 'editor');
399
		$user = $this->objFromFixture('Member', 'user');
400
401
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
402
			$formatter->convertDataObject($editor, array("FirstName", "Email")),
0 ignored issues
show
Bug introduced by
It seems like $editor defined by $this->objFromFixture('Member', 'editor') on line 398 can be null; however, JSONDataFormatter::convertDataObject() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
403
			'{"FirstName":"Editor","Email":"[email protected]"}',
404
			"Correct JSON formatting with field subset");
405
406
		$set = DataObject::get(
407
			"Member", 
408
			sprintf('"Member"."ID" IN (%s)', implode(',', array($editor->ID, $user->ID))), 
409
			'"Email" ASC' // for sorting for postgres
410
		);
411
		$this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
412
			$formatter->convertDataObjectSet($set, array("FirstName", "Email")),
413
			'{"totalSize":null,"items":[{"FirstName":"Editor","Email":"[email protected]"},' . 
414
			'{"FirstName":"User","Email":"[email protected]"}]}',
415
			"Correct JSON formatting on a dataobjectset with field filter");
416
	}
417
	
418
	public function testApiAccessWithPOST() {
419
		$url = "/api/v1/RestfulServerTest_AuthorRating";
420
		$data = array(
421
			'Rating' => '42',
422
			'WriteProtectedField' => 'haxx0red'
423
		);
424
		$response = Director::test($url, $data, null, 'POST');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
425
		// Assumption: XML is default output
426
		$responseArr = Convert::xml2array($response->getBody());
427
		$this->assertEquals($responseArr['Rating'], 42);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
428
		$this->assertNotEquals($responseArr['WriteProtectedField'], 'haxx0red');
0 ignored issues
show
Bug introduced by
The method assertNotEquals() does not seem to exist on object<RestfulServerTest>.

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...
429
	}
430
431
	public function testCanViewRespectedInList() {
0 ignored issues
show
Coding Style introduced by
testCanViewRespectedInList uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
432
		// Default content type
433
		$url = "/api/v1/RestfulServerTest_SecretThing/";
434
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
435
		$this->assertEquals($response->getStatusCode(), 200);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
436
		$this->assertNotContains('Unspeakable', $response->getBody());
437
438
		// JSON content type
439
		$url = "/api/v1/RestfulServerTest_SecretThing.json";
440
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
441
		$this->assertEquals($response->getStatusCode(), 200);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
442
		$this->assertNotContains('Unspeakable', $response->getBody());
443
444
		// With authentication
445
		$_SERVER['PHP_AUTH_USER'] = '[email protected]';
446
		$_SERVER['PHP_AUTH_PW'] = 'editor';
447
		$url = "/api/v1/RestfulServerTest_SecretThing/";
448
		$response = Director::test($url, null, null, 'GET');
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Session>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
449
		$this->assertEquals($response->getStatusCode(), 200);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RestfulServerTest>.

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...
450
		$this->assertContains('Unspeakable', $response->getBody());
451
		unset($_SERVER['PHP_AUTH_USER']);
452
		unset($_SERVER['PHP_AUTH_PW']);
453
	}
454
	
455
}
0 ignored issues
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...
456
457
/**
458
 * Everybody can view comments, logged in members in the "users" group can create comments,
459
 * but only "editors" can edit or delete them.
460
 *
461
 */
462
class RestfulServerTest_Comment extends DataObject implements PermissionProvider,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...
Coding Style introduced by
Expected 1 space before "TestOnly"; 0 found
Loading history...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
463
	
464
	static $api_access = true;
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $api_access.
Loading history...
Coding Style introduced by
The visibility should be declared for property $api_access.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
465
	
466
	static $db = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $db.
Loading history...
Coding Style introduced by
The visibility should be declared for property $db.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
467
		"Name" => "Varchar(255)",
468
		"Comment" => "Text"
469
	);
470
	
471
	static $has_one = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $has_one.
Loading history...
Coding Style introduced by
The visibility should be declared for property $has_one.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
472
		'Page' => 'RestfulServerTest_Page', 
473
		'Author' => 'RestfulServerTest_Author', 
474
	);
475
	
476
	public function providePermissions(){
477
		return array(
478
			'EDIT_Comment' => 'Edit Comment Objects',
479
			'CREATE_Comment' => 'Create Comment Objects',
480
			'DELETE_Comment' => 'Delete Comment Objects',
481
		);
482
	}
483
	
484
	public function canView($member = null) {
485
		return true;
486
	}
487
	
488
	public function canEdit($member = null) {
489
		return Permission::checkMember($member, 'EDIT_Comment');
490
	}
491
	
492
	public function canDelete($member = null) {
493
		return Permission::checkMember($member, 'DELETE_Comment');
494
	}
495
	
496
	public function canCreate($member = null) {
497
		return Permission::checkMember($member, 'CREATE_Comment');
498
	}
499
	
500
}
0 ignored issues
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...
501
502
class RestfulServerTest_SecretThing extends DataObject implements TestOnly,PermissionProvider{
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...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
503
	static $api_access = true;
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $api_access.
Loading history...
Coding Style introduced by
The visibility should be declared for property $api_access.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
504
	
505
	static $db = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $db.
Loading history...
Coding Style introduced by
The visibility should be declared for property $db.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
506
		"Name" => "Varchar(255)",
507
	);
508
	
509
	public function canView($member = null) {
510
		return Permission::checkMember($member, 'VIEW_SecretThing');
511
	}
512
	
513
	public function providePermissions(){
514
		return array(
515
			'VIEW_SecretThing' => 'View Secret Things',
516
		);
517
	}
518
}
519
520
class RestfulServerTest_Page extends DataObject 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...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
521
	
522
	static $api_access = false;
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $api_access.
Loading history...
Coding Style introduced by
The visibility should be declared for property $api_access.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
523
	
524
	static $db = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $db.
Loading history...
Coding Style introduced by
The visibility should be declared for property $db.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
525
		'Title' => 'Text',	
526
		'Content' => 'HTMLText',
527
	);
528
	
529
	static $has_one = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $has_one.
Loading history...
Coding Style introduced by
The visibility should be declared for property $has_one.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
530
		'Author' => 'RestfulServerTest_Author', 
531
	);
532
	
533
	static $has_many = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $has_many.
Loading history...
Coding Style introduced by
The visibility should be declared for property $has_many.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
534
		'TestComments' => 'RestfulServerTest_Comment'
535
	);
536
	
537
	static $belongs_many_many = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $belongs_many_many.
Loading history...
Coding Style introduced by
The visibility should be declared for property $belongs_many_many.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
538
		'RelatedAuthors' => 'RestfulServerTest_Author', 
539
	);
540
541
}
0 ignored issues
show
Coding Style introduced by
According to PSR2, the closing brace of classes should be placed on the next line directly after the body.

Below you find some examples:

// Incorrect placement according to PSR2
class MyClass
{
    public function foo()
    {

    }
    // This blank line is not allowed.

}

// Correct
class MyClass
{
    public function foo()
    {

    } // No blank lines after this line.
}
Loading history...
542
543
class RestfulServerTest_Author extends DataObject 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...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
544
	
545
	static $api_access = true;
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $api_access.
Loading history...
Coding Style introduced by
The visibility should be declared for property $api_access.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
546
	
547
	static $db = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $db.
Loading history...
Coding Style introduced by
The visibility should be declared for property $db.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
548
		'Name' => 'Text',
549
	);
550
		
551
	static $many_many = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $many_many.
Loading history...
Coding Style introduced by
The visibility should be declared for property $many_many.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
552
		'RelatedPages' => 'RestfulServerTest_Page', 
553
		'RelatedAuthors' => 'RestfulServerTest_Author', 
554
	);
555
	
556
	static $has_many = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $has_many.
Loading history...
Coding Style introduced by
The visibility should be declared for property $has_many.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
557
		'PublishedPages' => 'RestfulServerTest_Page',
558
		'Ratings' => 'RestfulServerTest_AuthorRating', 
559
	);
560
	
561
	public function canView($member = null) {
562
		return true;
563
	}
564
}
565
566
class RestfulServerTest_AuthorRating extends DataObject 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...
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
567
	static $api_access = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $api_access.
Loading history...
Coding Style introduced by
The visibility should be declared for property $api_access.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
568
		'view' => array(
569
			'Rating',
570
			'WriteProtectedField',
571
			'Author'
572
		),
573
		'edit' => array(
574
			'Rating'
575
		)
576
	);
577
	
578
	static $db = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $db.
Loading history...
Coding Style introduced by
The visibility should be declared for property $db.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
579
		'Rating' => 'Int',
580
		'SecretField' => 'Text',
581
		'WriteProtectedField' => 'Text',
582
	);
583
	
584
	static $has_one = array(
0 ignored issues
show
Coding Style introduced by
We recommend specifying an explicit visibility for the field $has_one.
Loading history...
Coding Style introduced by
The visibility should be declared for property $has_one.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
585
		'Author' => 'RestfulServerTest_Author', 
586
		'SecretRelation' => 'RestfulServerTest_Author', 
587
	);
588
	
589
	public function canView($member = null) {
590
		return true;
591
	}
592
	
593
	public function canEdit($member = null) {
594
		return true;
595
	}
596
	
597
	public function canCreate($member = null) {
598
		return true;
599
	}
600
}
601
602