Message from discussion
Testing form, validation is not called
Received: by 10.14.215.136 with SMTP id e8mr38768005eep.6.1351770978048;
Thu, 01 Nov 2012 04:56:18 -0700 (PDT)
X-BeenThere: symfony2@googlegroups.com
Received: by 10.14.184.67 with SMTP id r43ls1843862eem.2.gmail; Thu, 01 Nov
2012 04:56:05 -0700 (PDT)
Received: by 10.14.216.197 with SMTP id g45mr40925885eep.3.1351770965871;
Thu, 01 Nov 2012 04:56:05 -0700 (PDT)
Received: by 10.14.216.197 with SMTP id g45mr40925883eep.3.1351770965859;
Thu, 01 Nov 2012 04:56:05 -0700 (PDT)
Return-Path: <da...@liip.ch>
Received: from eu1sys200aog106.obsmtp.com (eu1sys200aog106.obsmtp.com [207.126.144.121])
by gmr-mx.google.com with SMTP id u8si639188een.1.2012.11.01.04.56.05
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 01 Nov 2012 04:56:05 -0700 (PDT)
Received-SPF: pass (google.com: domain of da...@liip.ch designates 207.126.144.121 as permitted sender) client-ip=207.126.144.121;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of da...@liip.ch designates 207.126.144.121 as permitted sender) smtp.mail=da...@liip.ch
Received: from mail-la0-f70.google.com ([209.85.215.70]) (using TLSv1) by eu1sys200aob106.postini.com ([207.126.147.11]) with SMTP
ID DSNKUJJjVdcDnuKO/7bGS65i3/dYuRe7N...@postini.com; Thu, 01 Nov 2012 11:56:05 UTC
Received: by mail-la0-f70.google.com with SMTP id w12so1872939lag.9
for <symfony2@googlegroups.com>; Thu, 01 Nov 2012 04:56:05 -0700 (PDT)
d=google.com; s=20120113;
h=message-id:date:from:user-agent:mime-version:to:subject:references
:in-reply-to:content-type:content-transfer-encoding
:x-gm-message-state;
bh=TumyJCfhSJXGL8s8rEGdwgR+Xfy/iG12rHkmN5cVVxQ=;
b=Zb5lKr8JIS0UytanSHx2wAl3PfAfcXNqgyjhhCXLHjjP0ISqfyzgghTmfnIipA6XgW
oBqLGsNVehXLg4B79x/zCXZ4p5xdO6L7RQYwAu1S3yJVi4ll8/JPkcIz5E0rCYENw6xi
+zi7fsVK+q/ZIyAaNNp3O7ju4basnoDWVsDFMvNpjfMWjRXpDpvoq0VoG+fThqaCPZlt
wm0VCGduJJkobfcskDMfhEFXa4E+l667ZZp/qdR+2Inxx1dOPdGbIk3bArv/dkCtu8d6
peYI0bA42FrAxRUwR1l0Cf3bKvq1f/z91MGlvdStLleBn1s4Q5W2QNsdIOi77xsLfOll
eHfg==
Received: by 10.14.203.69 with SMTP id e45mr96473059eeo.38.1351770965130;
Thu, 01 Nov 2012 04:56:05 -0700 (PDT)
Received: by 10.14.203.69 with SMTP id e45mr96473037eeo.38.1351770965029;
Thu, 01 Nov 2012 04:56:05 -0700 (PDT)
Return-Path: <da...@liip.ch>
Received: from [192.168.2.2] (217-162-118-173.dynamic.hispeed.ch. [217.162.118.173])
by mx.google.com with ESMTPS id o49sm14102837eep.5.2012.11.01.04.56.03
(version=SSLv3 cipher=OTHER);
Thu, 01 Nov 2012 04:56:04 -0700 (PDT)
Message-ID: <50926351.7020...@liip.ch>
Date: Thu, 01 Nov 2012 12:56:01 +0100
From: David Buchmann <da...@liip.ch>
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version: 1.0
To: symfony2@googlegroups.com
Subject: Re: [Symfony2] Testing form, validation is not called
References: <e6c5d08b-be6e-42ad-88e5-4557cd8c724d@googlegroups.com>
In-Reply-To: <e6c5d08b-be6e-42ad-88e5-4557cd8c724d@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Gm-Message-State: ALoCoQmF613HdKLjyoHxhL9xxKXRBOF/ZUV0kaXBiMXc+/0vXnwMo5ZH5Q/K3Rqfo+39M7ZZIU9jF7L3FfdcURrZ6BJ9BBfTcDZqVvJdyGY0jniIXc38ZCzHCJI9bO9bgViuhIC2+L9vxYZQsuocuYnorG+8ULFG06P4BsoGOmtuu7ZK0g5dqRA=
hi,
to test the validation, you can access the validator directly.
$this->getContainer()->get('validator')->validate($entity);
otherwise you have to build a request and let the form parse that
request and call isValid on the form. but rather than do that, i would
write a real functional test where you simulate the web request with the
WebClient and fill out the form.
cheers,david
Am 31.10.2012 14:03, schrieb Hossein Zolfi:
> Hello,
>
> I develop new type, but I don't know can I test it.
> Assert annotation is not load and validations is not called.
> Could any one please help me?
>
>
> class BarcodeType extends AbstractType
> {
> public function buildForm(FormBuilderInterface $builder, array
> $options)
> {
> $builder->
> add('price');
> }
>
> public function setDefaultOptions(OptionsResolverInterface
> $resolver)
> {
> $resolver->setDefaults(array(
> 'data_class' => 'Bundles\MyBundle\Form\Model\Barcode',
> 'intention' => 'enable_barcode',
> ));
> }
>
> public function getName()
> {
> return 'enable_barcode';
> }
> }
>
>
> namepspace Bundles\MyBundle\Form\Model;
> class Barcode
> {
> /**
> * @Assert\Range(
> * min = "100",
> * max = "100000",
> * minMessage = "...",
> * maxMessage = "..."
> * )
> */
> public $price;
> }
>
> I develop some test like this, the form didn't get valid data but it is
> valid! (Because annotation is not applied)
> I try adding ValidatorExtension but I dont know how can I set
> constructor paramaters
>
> function test...()
> {
> $field = $this->factory->createNamed('name', 'barcode');
> $field->bind(
> array(
> 'price' => 'hello',
> ));
>
> $data = $field->getData();
>
> $this->assertTrue($field->isValid()); // Must not be valid
>
> }
>
>
>
> --
> If you want to report a vulnerability issue on symfony, please send it
> to security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "Symfony2" group.
> To post to this group, send email to symfony2@googlegroups.com
> To unsubscribe from this group, send email to
> symfony2+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony2?hl=en
--
Liip AG // Agile Web Development // T +41 26 422 25 11
CH-1700 Fribourg // PGP 0xA581808B // www.liip.ch