通過作曲家更新我的代碼之前,我的表單單元測試正在工作。現在在延期模擬上失敗了。 繼承人的錯誤:Symfony單元測試表單擴展模擬
Argument 1 passed to Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension::__construct() must be an instance of Symfony\Component\Validator\ValidatorInterface, instance of Mock_ValidatorInterface_14b95ba0 given
我的繼承人作曲家需要部分:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.3",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.3",
"symfony/monolog-bridge": "~2.4",
"sensio/distribution-bundle": "~2.3",
"sensio/framework-extra-bundle": "~2.3"
}
繼承人在單元測試設置方法驗證模擬:
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Form\Forms;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Form\Extension\Core\CoreExtension;
class TestedTypeTest extends TypeTestCase
{
protected function setUp()
{
parent::setUp();
$validator = $this->getMock('\Symfony\Component\Validator\Validator\ValidatorInterface');
$validator->method('validate')->will($this->returnValue(new ConstraintViolationList()));
$formTypeExtension = new FormTypeValidatorExtension($validator);
$coreExtension = new CoreExtension();
$this->factory = Forms::createFormFactoryBuilder()
->addExtensions($this->getExtensions())
->addExtension($coreExtension)
->addTypeExtension($formTypeExtension)
->getFormFactory();
}
有誰知道什麼可能是錯誤的與模擬?任何意見是極大的讚賞。
必須是\ Symfony \ Component \ Validator \ ValidatorInterface「vs」\ Symfony \ Component \ Validator \ Validator \ ValidatorInterface「的實例似乎在模擬中有太多的'驗證器'。 – 2015-01-31 23:54:48
[Symfony 2.5中的ValidatorConstraint問題]的可能重複(http://stackoverflow.com/questions/24009719/problems-with-validatorconstraint-in-symfony-2-5) – Brejk 2015-01-31 23:58:01
@AlisterBulman是的,這就是它。刪除第二個驗證工作。我使用Symphony〜2.3而不是2.5,所以Symfony \ Component \ Validator \ Validator的棄用在這裏不適用。 – pfwd 2015-02-01 08:01:48