Passed
Push — master ( ddbf8b...086098 )
by Robbie
11:17
created

HttpMethodBypassTest::testBypass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 20
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Control\Tests\Middleware\ConfirmationMiddleware;
4
5
use SilverStripe\Control\HTTPRequest;
6
use SilverStripe\Control\Middleware\ConfirmationMiddleware\HttpMethodBypass;
7
use SilverStripe\Dev\SapphireTest;
8
9
class HttpMethodBypassTest extends SapphireTest
10
{
11
    public function testBypass()
12
    {
13
        $getRequest = $this->createMock(HTTPRequest::class);
14
        $getRequest->method('httpMethod')->willReturn('GET');
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

14
        $getRequest->/** @scrutinizer ignore-call */ 
15
                     method('httpMethod')->willReturn('GET');

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...
15
16
        $postRequest = $this->createMock(HTTPRequest::class);
17
        $postRequest->method('httpMethod')->willReturn('POST');
18
19
        $putRequest = $this->createMock(HTTPRequest::class);
20
        $putRequest->method('httpMethod')->willReturn('PUT');
21
22
        $delRequest = $this->createMock(HTTPRequest::class);
23
        $delRequest->method('httpMethod')->willReturn('DELETE');
24
25
        $bypass = new HttpMethodBypass('GET', 'POST');
26
27
        $this->assertTrue($bypass->checkRequestForBypass($getRequest));
28
        $this->assertTrue($bypass->checkRequestForBypass($postRequest));
29
        $this->assertFalse($bypass->checkRequestForBypass($putRequest));
30
        $this->assertFalse($bypass->checkRequestForBypass($delRequest));
31
    }
32
}
33