for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types = 1);
namespace Bukashk0zzz\BooleanTypeBundle\Tests;
use Bukashk0zzz\BooleanTypeBundle\Form\Type\BooleanType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\Test\TypeTestCase;
/**
* @internal
*/
final class BooleanTypeTest extends TypeTestCase
{
* @var int
protected $status;
* Test type.
public function testType(): void
$this->status = true;
$status
integer
true
boolean
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.
$answer = 42; $correct = false; $correct = (bool) $answer;
$form = $this->factory->create(BooleanType::class);
$form->submit($this->status);
$this->status
string|array|null
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);
$this->assertForm($form);
$this->status = false;
false
$form->submit('');
self::assertSame('', $form->getViewData());
}
private function assertForm(FormInterface $form): void
self::assertTrue($form->isSynchronized());
self::assertSame((string) $this->status, $form->getViewData());
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.