phpunit - Symfony Form Unit Test -


how unit test formtype has parent of entity? or case class should ignored phpunit? code included below.

1) audit\receiptbundle\tests\form\type\contacttypetest::testsubmitvaliddata symfony\component\optionsresolver\exception\missingoptionsexception: required option "class" missing.

class contacttype extends abstracttype {      public function __construct()     {     }      public function setdefaultoptions(optionsresolverinterface $resolver)     {         $resolver->setdefaults(array(             'empty_value' => 'choose contact',         ));     }      public function getparent()     {         return 'entity';     }      public function getname()     {         return 'contact';     }  } 

the test code:

protected function getextensions() {     return array(new preloadedextension(array(             'entity' => $this->mockfieldentitytype(),                 ), array())); }  public function testsubmitvaliddata() {      $formdata = [     ];      $type = new contacttype();     $resolve = new \symfony\component\optionsresolver\optionsresolver();     $resolve->setdefaults([         'class' => 'foo:bar'     ]);     $type->setdefaultoptions($resolve);     $form = $this->factory->create($type);      // submit data form directly     $form->submit($formdata);      $this->asserttrue($form->issynchronized());     $this->assertequals($formdata, $form->getdata());      $view = $form->createview();     $children = $view->children;      foreach (array_keys($formdata) $key) {         $this->assertarrayhaskey($key, $children);     } } 

mockfieldentitytype() take answer provided in how load form types in tests

protected function mockfieldentitytype() {     $mockentitymanager = $this->getentitymanager();      $mockregistry = $this->getmockbuilder('doctrine\bundle\doctrinebundle\registry')         ->disableoriginalconstructor()         ->getmock();      $mockregistry->expects($this->any())->method('getmanagerforclass')         ->will($this->returnvalue($mockentitymanager));      $mockentitymanager->expects($this->any())->method('getclassmetadata')         ->withanyparameters()         ->will($this->returnvalue(new classmetadata('entity')));       $entitytype = new entitytype($mockregistry);      return $entitytype; } 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -