Skip to content

Instantly share code, notes, and snippets.

@lugecy
Last active January 4, 2016 13:37
Show Gist options
  • Save lugecy/b2477755000d15950405 to your computer and use it in GitHub Desktop.
Save lugecy/b2477755000d15950405 to your computer and use it in GitHub Desktop.
SymfonyでFormTypeのunittestする場合の雛形 (getExtensionsで設定しないと、Validaterが読み込まれず、repeatedフォームを使っているとエラーになる)
<?php
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
class PasswordFormType extends TypeTestCase
{
protected function getExtensions()
{
return [new ValidatorExtension(Validation::createValidator())];
}
public function testPasswordLengthValid()
{
$formData = [
"userID" => "lugecy",
"password" => "passwd",
"newPassword" => [
// "first" => "pass",
// "second" => "pass",
"first" => "p0ssw0rd",
"second" => "p0ssw0rd",
],
];
$type = new App\PasswordFormType();
$form = $this->factory->create($type);
$form->submit($formData);
// Something Code...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment