DeterminesAssertions::shouldAssertUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Digitonic\ApiTestSuite\Concerns;
4
5
use Illuminate\Http\Response;
6
7
trait DeterminesAssertions
8
{
9
    /**
10
     * @return bool
11
     */
12
    protected function shouldAssertAuthentication()
13
    {
14
        return $this->shouldReturnsStatus(Response::HTTP_UNAUTHORIZED);
15
    }
16
17
    /**
18
     * @param int $statusCode
19
     * @return bool
20
     */
21
    protected function shouldReturnsStatus($statusCode)
22
    {
23
        return collect($this->statusCodes())->contains($statusCode);
0 ignored issues
show
Bug introduced by
It seems like statusCodes() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        return collect($this->/** @scrutinizer ignore-call */ statusCodes())->contains($statusCode);
Loading history...
24
    }
25
26
    /**
27
     * @return bool
28
     */
29
    protected function shouldAssertNotFound()
30
    {
31
        return $this->shouldReturnsStatus(Response::HTTP_NOT_FOUND);
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    protected function shouldAssertValidation()
38
    {
39
        return $this->shouldReturnsStatus(Response::HTTP_UNPROCESSABLE_ENTITY);
40
    }
41
42
    /**
43
     * @return bool
44
     */
45
    protected function shouldAssertForbiddenAction()
46
    {
47
        return $this->shouldReturnsStatus(Response::HTTP_FORBIDDEN);
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    protected function shouldAssertCreation()
54
    {
55
        return $this->shouldReturnsStatus(Response::HTTP_CREATED);
56
    }
57
58
    /**
59
     * @return bool
60
     */
61
    protected function shouldAssertUpdate()
62
    {
63
        return $this->shouldReturnsStatus(Response::HTTP_ACCEPTED);
64
    }
65
66
    /**
67
     * @param $httpAction
68
     * @return bool
69
     */
70
    protected function shouldAssertRetrieve($httpAction)
71
    {
72
        return $this->shouldReturnsStatus(Response::HTTP_OK) && !$this->isListAction($httpAction);
73
    }
74
75
    /**
76
     * @param $httpAction
77
     * @return bool
78
     */
79
    protected function isListAction($httpAction)
80
    {
81
        return !$this->shouldReturnsStatus(Response::HTTP_NOT_FOUND) && $httpAction == 'get';
82
    }
83
84
    /**
85
     * @param $httpAction
86
     * @return bool
87
     */
88
    protected function shouldAssertListAll($httpAction)
89
    {
90
        return $this->shouldReturnsStatus(Response::HTTP_OK) && $this->isListAction($httpAction);
91
    }
92
93
    /**
94
     * @return bool
95
     */
96
    protected function shouldAssertDeletion()
97
    {
98
        return $this->shouldReturnsStatus(Response::HTTP_NO_CONTENT);
99
    }
100
}
101