|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the Exception context class for RestBundle. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @version //autogentag// |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace eZ\Bundle\EzPublishRestBundle\Features\Context\SubContext; |
|
12
|
|
|
|
|
13
|
|
|
trait Exception |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @Then response has (an) unauthorized exception/error |
|
17
|
|
|
* @Then response has (a) not authorized exception/error |
|
18
|
|
|
*/ |
|
19
|
|
|
public function iSeeNotAuthorizedException() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->assertStatusCode(401); |
|
|
|
|
|
|
22
|
|
|
$this->assertStatusMessage('Unauthorized'); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @Then response has (an) invalid field exception/error |
|
27
|
|
|
*/ |
|
28
|
|
View Code Duplication |
public function assertInvalidFieldException() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->assertStatusCode(403); |
|
|
|
|
|
|
31
|
|
|
$this->assertStatusMessage('Forbidden'); |
|
|
|
|
|
|
32
|
|
|
$this->assertHeaderHasObject('content-type', 'ErrorMessage'); |
|
|
|
|
|
|
33
|
|
|
$this->assertResponseObject('eZ\\Publish\\Core\\REST\\Common\\Exceptions\\ForbiddenException'); |
|
|
|
|
|
|
34
|
|
|
$this->assertResponseErrorStatusCode(403); |
|
|
|
|
|
|
35
|
|
|
$this->assertResponseErrorDescription("/^Argument '([^']+)' is invalid:(.+)\$/"); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @Then response has a forbidden exception/error with message :message |
|
40
|
|
|
*/ |
|
41
|
|
View Code Duplication |
public function assertForbiddenExceptionWithMessage($message) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->assertStatusCode(403); |
|
|
|
|
|
|
44
|
|
|
$this->assertStatusMessage('Forbidden'); |
|
|
|
|
|
|
45
|
|
|
$this->assertHeaderHasObject('content-type', 'ErrorMessage'); |
|
|
|
|
|
|
46
|
|
|
$this->assertResponseObject('eZ\\Publish\\Core\\REST\\Common\\Exceptions\\ForbiddenException'); |
|
|
|
|
|
|
47
|
|
|
$this->assertResponseErrorStatusCode(403); |
|
|
|
|
|
|
48
|
|
|
$this->assertResponseErrorDescription("/^$message\$/"); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @Then response has (a) not found exception/error |
|
53
|
|
|
*/ |
|
54
|
|
View Code Duplication |
public function assertNotFoundException() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertStatusCode(404); |
|
|
|
|
|
|
57
|
|
|
$this->assertStatusMessage('Not Found'); |
|
|
|
|
|
|
58
|
|
|
$this->assertHeaderHasObject('content-type', 'ErrorMessage'); |
|
|
|
|
|
|
59
|
|
|
$this->assertResponseObject('eZ\\Publish\\Core\\REST\\Common\\Exceptions\\NotFoundException'); |
|
|
|
|
|
|
60
|
|
|
$this->assertResponseErrorStatusCode(404); |
|
|
|
|
|
|
61
|
|
|
$this->assertResponseErrorDescription("/^Could not find '([^']+)' with identifier '([^']+)'\$/"); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.