فهرست منبع

Implementacion del webservicemock

gabriel 7 سال پیش
والد
کامیت
80fab5b360
2فایلهای تغییر یافته به همراه72 افزوده شده و 56 حذف شده
  1. 56 53
      src/FTTHBundle/Form/ONUType.php
  2. 16 3
      src/FTTHBundle/tests/ONURESTControllerTest.php

+ 56 - 53
src/FTTHBundle/Form/ONUType.php

@@ -15,13 +15,17 @@ class ONUType extends AbstractType
 {
 
     protected $webservice = null;
-    public function setWebService($ws){
-	$this->webservice = $ws;
+
+    public function setWebService($ws)
+    {
+        $this->webservice = $ws;
     }
 
     protected $em = null;
-    public function setEntityManager($em){
-	$this->em = $em;
+
+    public function setEntityManager($em)
+    {
+        $this->em = $em;
     }
 
     /**
@@ -30,65 +34,64 @@ class ONUType extends AbstractType
     public function buildForm(FormBuilderInterface $builder, array $options)
     {
         $builder->add('ip')
-                ->add('mac')
-                ->add('serialNumber')
-                ->add('profile')
-                ->add('model')
-                ->add('nap')
-                ->add('ponSerialNumber')
-                ->add('clientId')
-                ->add('tenancyId')
-                ;
-
-	$builder->addEventListener(
+            ->add('mac')
+            ->add('serialNumber')
+            ->add('profile')
+            ->add('model')
+            ->add('nap')
+            ->add('ponSerialNumber')
+            ->add('clientId')
+            ->add('tenancyId');
+
+        $builder->addEventListener(
             FormEvents::PRE_SUBMIT,
             function (FormEvent $event) {
                 $form = $event->getForm();
 
                 $data = $event->getData();
 
-		$clientID = $data['clientId'];
-
-		if(is_array($clientID) and $this->webservice){
-		$clientID["disableTenancy"] = 1;
-			$remote_data = $this->webservice->getData("client", $clientID);
-			if(count($remote_data) === 1){
-				$data["clientId"] = $remote_data[0]["id"];
-			}else{
-				unset($data["clientId"]);
-			}
-		}
-
-		if(isset($data["profile"]) and is_array($data["profile"]) and $this->em){
-			$profile = $this->em->getRepository("FTTHBundle\Entity\Profile")->findOneBy($data["profile"]);
-			unset($data["profile"]);
-			if($profile){
-				$data["profile"] = $profile->getId();
-			}
-		}
-
-		if(isset($data["model"]) and is_array($data["model"]) and $this->em){
-			$model = $this->em->getRepository("FTTHBundle\Entity\ONUModel")->findOneBy($data["model"]);
-			unset($data["model"]);
-			if($model){
-				$data["model"] = $model->getId();
-			}
-		}
-
-		if(isset($data["nap"]) and is_array($data["nap"]) and $this->em){
-			$nap= $this->em->getRepository("FTTHBundle\Entity\NAP")->findOneBy($data["nap"]);
-			unset($data["nap"]);
-			if($nap){
-				$data["nap"] = $nap->getId();
-			}
-		}
-
-		$event->setData($data);
+                $clientID = $data['clientId'];
+
+                if (is_array($clientID) and $this->webservice) {
+                    $clientID["disableTenancy"] = 1;
+                    $remote_data = $this->webservice->getData("client", $clientID);
+                    if (count($remote_data) === 1) {
+                        $data["clientId"] = $remote_data[0]["id"];
+                    } else {
+                        unset($data["clientId"]);
+                    }
+                }
+
+                if (isset($data["profile"]) and is_array($data["profile"]) and $this->em) {
+                    $profile = $this->em->getRepository("FTTHBundle\Entity\Profile")->findOneBy($data["profile"]);
+                    unset($data["profile"]);
+                    if ($profile) {
+                        $data["profile"] = $profile->getId();
+                    }
+                }
+
+                if (isset($data["model"]) and is_array($data["model"]) and $this->em) {
+                    $model = $this->em->getRepository("FTTHBundle\Entity\ONUModel")->findOneBy($data["model"]);
+                    unset($data["model"]);
+                    if ($model) {
+                        $data["model"] = $model->getId();
+                    }
+                }
+
+                if (isset($data["nap"]) and is_array($data["nap"]) and $this->em) {
+                    $nap = $this->em->getRepository("FTTHBundle\Entity\NAP")->findOneBy($data["nap"]);
+                    unset($data["nap"]);
+                    if ($nap) {
+                        $data["nap"] = $nap->getId();
+                    }
+                }
+
+                $event->setData($data);
 
             }
         );
     }
-    
+
     /**
      * {@inheritdoc}
      */

+ 16 - 3
src/FTTHBundle/tests/ONURESTControllerTest.php

@@ -30,6 +30,18 @@ class ONURESTControllerTest extends WebTestCaseBase
         return '/api/onus/';
     }
 
+    /**
+     * Contiene los datos que debe retornar el webservice. La key es nombre del webservice y el
+     * value son los datos a retornar.
+     */
+    protected function obtainDataWebService()
+    {
+        $datos = array();
+        $datos['client'] =
+            json_encode(array(array("name" => "Stock", "id" => 1)));
+        return $datos;
+    }
+
     /**
      * Genera los datos a manipular.
      * @param string $key Contiene la key a buscar en los datos.
@@ -41,11 +53,12 @@ class ONURESTControllerTest extends WebTestCaseBase
         $datos = array();
         $datos['oltId'] = '';
         $datos['modelId'] = '1';
-        $datos['napId'] = '1'; 
+        $datos['napId'] = '1';
         $datos['profileId'] = '1';
         $datos['mac'] = '00:11:22:33';
         $datos['ponSerialNumber'] = 'pon';
-        $datos['clientId'] = '1';
+        $datos['clientId'] = array('name' => 'Stock GZ [pruebass]');
+//        $datos['clientId'] = '1';
         $datos['transitionState'] = 'ts';
         $datos['tenancyId'] = 1;
 
@@ -93,7 +106,7 @@ class ONURESTControllerTest extends WebTestCaseBase
     public function testPOST()
     {
         echo "\n";
-        $this->initDefault();
+        $this->initDefault($this->obtainDataWebService());
         $this->getClient()->request('POST', $this->getUri(), $this->obtainData());
         // obtengo la respuesta
         $response = $this->getClient()->getResponse();