for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace SilverStripe\UserForms\Tests\FormField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Forms\RequiredFields;
use SilverStripe\UserForms\FormField\UserFormsCheckboxSetField;
class UserFormsCheckboxSetFieldTest extends SapphireTest
{
public function testValidate()
$field = new UserFormsCheckboxSetField('Field', 'My field', ['One' => 'One', 'Two' => 'Two']);
$validator = new RequiredFields();
// String values
$field->setValue('One');
$this->assertTrue($field->validate($validator));
$validator
object<SilverStripe\Forms\RequiredFields>
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);
$field->setValue('One,Two');
$field->setValue('Three,Four');
$this->assertFalse($field->validate($validator));
// Array values
$field->setValue(array('One'));
$field->setValue(array('One', 'Two'));
// Invalid
$field->setValue('Three');
$field->setValue(array('Three', 'Four'));
}
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: