Erreur phpunit __Construct must be an instance of ..

Petit nouveau ! | 5 Messages

27 avr. 2016, 01:15

Bonjour a tous
pour un projet de fin d'année je dois effectuer des tests unitaires et fonctionnelles.je suis debutant et je dois faires les tests pour mon groupe .Sauf que voila j'ai un petit soucis ,j'obtiens plusieurs fois la meme erreur en faisant mes tests pourtant les memes tests marchent sur certaine classe ,enfin la c'est des Form .je vous montre le code pour une classe par exemple :

Code : Tout sélectionner

<?php namespace AppBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use AppBundle\Entity\Bill; class BillType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('contract', EntityType::class, array( 'class' => 'AppBundle:Contract', 'choice_label' => 'numContract', 'label' => false, 'required' => true, )) ->add('tvaRate', TextType::class, array( 'label' => false, 'required' => false, )) ->add('amountIC', TextType::class, array( 'label' => false, 'required' => false, )) ->add('provider', TextType::class, array( 'label' => false, 'required' => false, )) ->add('numSupplier', TextType::class, array( 'label' => false, 'required' => false, )) ->add('numDays', TextType::class, array( 'label' => false, 'required' => false, )) ->add('marginAmount', TextType::class, array( 'label' => false, 'required' => false, )) ->add('preTaxAmount', TextType::class, array( 'label' => false, 'required' => false, )) ->add('sendingMode', TextType::class, array( 'label' => false, 'required' => false, )) ->add('deltaPayingEmission', TextType::class, array( 'label' => false, 'required' => false, )) ->add('sales', TextType::class, array( 'label' => false, 'required' => false, )) ->add('payingDatePurchase', DateType::class, array( 'label' => false, 'required' => false, 'widget' => 'single_text', )) ->add('payingDateSale', DateType::class, array( 'label' => false, 'required' => false, 'widget' => 'single_text', )) ->add('exceededDueDate', DateType::class, array( 'label' => false, 'required' => false, 'widget' => 'single_text', )) ->add('payingDateSale', DateType::class, array( 'label' => false, 'required' => false, 'widget' => 'single_text', )) ->add('paymentMethod', ChoiceType::class, array( 'label' => false, 'choices' => array_flip(Bill::getPaymentMethodLabel()), 'required' => false, )) ->add('paymentState', ChoiceType::class, array( 'label' => false, 'choices' => array_flip(Bill::getPaymentStateLabel()), 'required' => false, )) ->add('type', ChoiceType::class, array( 'label' => false, 'choices' => array_flip(Bill::getTypeLabel()), 'required' => false, )) ->add('state', ChoiceType::class, array( 'label' => false, 'choices' => array_flip(Bill::getStateLabel()), 'required' => true, )) ; } }
et voici le test

Code : Tout sélectionner

<?php namespace tests\AppBundle\Form; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\Test\TypeTestCase; use AppBundle\Form\BillType; use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension; use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; use Symfony\Component\Form\PreloadedExtension; use AppBundle\Model\TestObject; class CategoryTypeTest extends TypeTestCase { public function testSubmitValidData() { $formData =array( 'contract' => 'contract', 'tvaRate' => '', 'amountIC' =>'', 'provider' =>'', 'numSupplier'=>'', 'numDays'=>'', 'marginAmount'=>'', 'preTaxAmount'=>'', 'sendingMode'=>'', 'deltaPayingEmission'=>'', 'sales'=>'', 'payingDatePurchase'=>'', 'payingDateSale'=>'', 'exceededDueDate'=>'', 'payingDateSale'=>'', 'paymentMethod'=>'', 'paymentState'=>'', 'type'=>'', 'state'=>'' ); $form = $this->factory->create(BillType::class); $object = TestObject::fromArray($formData); // submit the data to the form directly $form->submit($formData); $this->assertTrue($form->isSynchronized()); $this->assertEquals($object, $form->getData()); //First you verify if the FormType compiles. $view = $form->createView(); $children = $view->children; //This test checks that none of your data transformers used by the form failed. //The isSynchronized() method is only set to false if a data transformer throws an exception: //Finally, check the creation of the FormView //You should check if all widgets you want to display are available in the children property: foreach (array_keys($formData) as $key) { $this->assertArrayHasKey($key, $children); } } }
j'ai suivi plein de tuto et de doc pour me renseigner.Des fois ca marches des fois ca ne marche pas et comme dans ce cas on me sort l'erreur sur la commande exe quand j'effectue le test php unit (desolé je ne sais pas comment mettre de screeshot..)
:
there was 1 error
1)tests\appbundle\form\categoryTestSubmitValidData
argument 1 passed to symphony\bridge\doctrine\form\Type\doctrineType :: __Construct() must be an instance of doctrine \common \persistence\managerRegistry,none given ,called in C:\wamp\www\project\vendor\symfony\src\symphony\Component\form\formRegistry.php on line 85 and defined
quelqu'un pourrait m'aider SVP ?
Merci beaucoup