Completed
Push — master ( 016a0b...25fc98 )
by Franco
12s
created

UserFormsCheckboxSetFieldTest::testValidate()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\UserForms\Tests\FormField;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\Forms\RequiredFields;
7
use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField;
8
9
class UserFormsCheckboxSetFieldTest extends SapphireTest
10
{
11
    public function testValidate()
12
    {
13
        $field = new UserFormsCheckboxSetField('Field', 'My field', ['One' => 'One', 'Two' => 'Two']);
14
        $validator = new RequiredFields();
15
16
        // String values
17
        $field->setValue('One');
18
        $this->assertTrue($field->validate($validator));
0 ignored issues
show
Documentation introduced by
$validator is of type object<SilverStripe\Forms\RequiredFields>, but the function expects a object<SilverStripe\User...ms\FormField\Validator>.

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...
19
        $field->setValue('One,Two');
20
        $this->assertTrue($field->validate($validator));
0 ignored issues
show
Documentation introduced by
$validator is of type object<SilverStripe\Forms\RequiredFields>, but the function expects a object<SilverStripe\User...ms\FormField\Validator>.

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...
21
        $field->setValue('Three,Four');
22
        $this->assertFalse($field->validate($validator));
0 ignored issues
show
Documentation introduced by
$validator is of type object<SilverStripe\Forms\RequiredFields>, but the function expects a object<SilverStripe\User...ms\FormField\Validator>.

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...
23
24
        // Array values
25
        $field->setValue(array('One'));
26
        $this->assertTrue($field->validate($validator));
0 ignored issues
show
Documentation introduced by
$validator is of type object<SilverStripe\Forms\RequiredFields>, but the function expects a object<SilverStripe\User...ms\FormField\Validator>.

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
        $field->setValue(array('One', 'Two'));
28
        $this->assertTrue($field->validate($validator));
0 ignored issues
show
Documentation introduced by
$validator is of type object<SilverStripe\Forms\RequiredFields>, but the function expects a object<SilverStripe\User...ms\FormField\Validator>.

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...
29
30
        // Invalid
31
        $field->setValue('Three');
32
        $this->assertFalse($field->validate($validator));
0 ignored issues
show
Documentation introduced by
$validator is of type object<SilverStripe\Forms\RequiredFields>, but the function expects a object<SilverStripe\User...ms\FormField\Validator>.

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...
33
        $field->setValue(array('Three', 'Four'));
34
        $this->assertFalse($field->validate($validator));
0 ignored issues
show
Documentation introduced by
$validator is of type object<SilverStripe\Forms\RequiredFields>, but the function expects a object<SilverStripe\User...ms\FormField\Validator>.

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...
35
    }
36
}
37