Completed
Push — fix-2494 ( 3153ee...40d9bb )
by Sam
13:43 queued 06:38
created

testCallsActionOnFormHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Forms\Tests;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\FormAction;
10
use SilverStripe\Forms\FormRequestHandler;
11
use SilverStripe\Forms\Tests\FormRequestHandlerTest\TestForm;
12
use SilverStripe\Forms\Tests\FormRequestHandlerTest\TestFormRequestHandler;
13
14
class FormRequestHandlerTest extends SapphireTest
15
{
16 View Code Duplication
    public function testCallsActionOnFormHandler()
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...
17
    {
18
        $form = new TestForm(
19
            new Controller(),
20
            'Form',
21
            new FieldList(),
22
            new FieldList(new FormAction('mySubmitOnFormHandler'))
23
        );
24
        $form->disableSecurityToken();
25
        $handler = new TestFormRequestHandler($form);
26
        $request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnFormHandler' => 1]);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a 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...
27
        $response = $handler->httpSubmission($request);
28
        $this->assertFalse($response->isError());
29
    }
30
31 View Code Duplication
    public function testCallsActionOnForm()
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...
32
    {
33
        $form = new TestForm(
34
            new Controller(),
35
            'Form',
36
            new FieldList(),
37
            new FieldList(new FormAction('mySubmitOnForm'))
38
        );
39
        $form->disableSecurityToken();
40
        $handler = new FormRequestHandler($form);
41
        $request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnForm' => 1]);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a 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...
42
        $response = $handler->httpSubmission($request);
43
        $this->assertFalse($response->isError());
44
    }
45
}
46