Symfony 4. Formtype IntegerType在单元测试中不起作用

时间:2019-04-11 10:35:43

标签: phpunit symfony4

在表单中,我定义了字段:

$builder->add('sum_of_rates', IntegerType::class, [
    'empty_data' => '',
    'constraints' => [
        new NotBlank(),
        new Range(RangeValues\DefaultNumberRange::getValues())
    ]
])

我的单元测试:

public function setUp() {
    parent::setUp();
    self::bootKernel();
    $this->formFactory = self::$kernel->getContainer()->get('form.factory');
}

public function testValidateForm() 
{
.
.
.

    $form = $this->formFactory->create(CreditContractFormType::class, 
CreditContractDocument::class);
    $form->submit($testData["data"]);
    $form->isValid() returns here true

.
.
.
}

$ testData [“ data”]看起来像这样:

array:13 [
  "correct_file" => true
  "readable" => true
  "complete" => true
  "correct_aligned" => true
  "date" => "2010-01-01"
  "customer_name" => "kaktus"
  "bank_name" => "kaktus"
  "purchase_price" => 10000
  "done_deposit" => 10000
  "monthly_rate" => 10000
  "sum_of_rates" => 123.45
  "annual_interest" => 10000
  "financeable" => true
]

$form->isValid()返回true。为什么行为如此奇怪?字段sum_of_rates没有整数值。如果sum_of_rates包含字符串sum_of_rates =“ abcde”,则$form->isValid()返回正确的false。

0 个答案:

没有答案