浏览代码

fix test. Related to https://gitlab.com/interlink-sa/flowdat3/modules/base/issues/13

Guillermo Espinoza 6 年之前
父节点
当前提交
e880c04166
共有 3 个文件被更改,包括 64 次插入55 次删除
  1. 18 16
      app/config/workflow.yml
  2. 17 8
      src/FTTHBundle/Controller/REST/ONURESTController.php
  3. 29 31
      src/FTTHBundle/tests/WorkflowOnuTest.php

+ 18 - 16
app/config/workflow.yml

@@ -12,25 +12,27 @@ framework:
                 - active
                 - pre_notice
                 - suspend
+                - cancelled
+                - not_provisioned
                 - deleted
             transitions:
-                active_to_pre_notice:
-                    from: active
-                    to:   pre_notice
-                active_to_suspend:
-                    from: active
-                    to:   suspend
-                pre_notice_to_active:
-                    from: pre_notice
-                    to:   active
-                pre_notice_to_suspend:
-                    from: pre_notice
-                    to:   suspend
-                suspend_to_active:
-                    from: suspend
-                    to:   active 
+                active:
+                    from: [pre_notice,suspend,cancelled,not_provisioned,deleted]
+                    to: active
+                pre_notice:
+                    from: [active,suspend,cancelled,not_provisioned,deleted]
+                    to: pre_notice
+                suspend:
+                    from: [active,pre_notice,cancelled,not_provisioned,deleted]
+                    to: suspend
+                cancel:
+                    from: [active,pre_notice,suspend,not_provisioned,deleted]
+                    to: cancelled
+                not_provisioned:
+                    from: [active,pre_notice,suspend,cancelled,deleted]
+                    to: not_provisioned
                 delete:
-                    from: [active,suspend,pre_notice]
+                    from: [active,suspend,pre_notice,cancelled,not_provisioned]
                     to:   deleted
         transition_state:
             type: 'state_machine'

+ 17 - 8
src/FTTHBundle/Controller/REST/ONURESTController.php

@@ -137,24 +137,33 @@ class ONURESTController extends RESTController
     {
         try {
             $tenancyService = $this->getTenancyService();
+            $tenancyService->disableFilter();
+
             $em = $this->container->get("doctrine.orm.entity_manager");
 
-            $tenancyService->disableFilter();
-            $query = $em->createQuery('SELECT o FROM FTTHBundle:ONU o WHERE o.currentState != :transition AND o.clientId = :client')->setParameter('transition', $transition)->setParameter('client', $id);
+            $query = $em->createQuery("
+                SELECT o FROM FTTHBundle:ONU o
+                WHERE o.administrativeState != :transition
+                AND o.clientId = :client
+            ")->setParameters([
+                'transition' => $transition,
+                'client' => $id,
+            ]);
             $onus = $query->getResult();
-            $tenancyService->enableFilter();
 
-            $cmd_args = array();
-            $cmd_args['entity'] = '--entity:FTTHBundle\\Entity\\ONU';
-            $cmd_args['transition'] = "--transition:{$transition}";
+            $tenancyService->enableFilter();
+            
+            $cmd_args = [
+                'entity' => '--entity:FTTHBundle\\Entity\\ONU',
+                'workflow' => '--workflow:administrative_state',
+                'transition' => "--transition:{$transition}",
+            ];
 
             $serialNumbers = array();
             if ($onus) {
                 foreach ($onus as $onu) {
                     $onuId = $onu->getId();
                     $cmd_args['id'] = "--id:{$onuId}";
-                    $workflowName = $onu->getWorkflow()->getName();
-                    $cmd_args['workflow'] = "--workflow:{$workflowName}";
                     $serialNumbers[$onuId] = $onu->getPonSerialNumber();
 
                     $this->runCommand('workflow:apply', $cmd_args);

+ 29 - 31
src/FTTHBundle/tests/WorkflowOnuTest.php

@@ -2,9 +2,8 @@
 
 namespace FTTHBundle\tests;
 
-use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
-
 use FTTHBundle\Entity\ONU;
+use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
 
 /**
  * @package FTTHBundle\tests
@@ -19,53 +18,52 @@ class WorkflowOnuTest extends KernelTestCase
         $this->em = static::$kernel->getContainer()
             ->get('doctrine')
             ->getManager();
-	$this->wr = static::$kernel->getContainer()
+        $this->wr = static::$kernel->getContainer()
             ->get('workflow.registry');
 
     }
 
-    function testAdministrative(){
+    public function testAdministrative()
+    {
         $onu = new ONU;
-	$onu->setPonSerialNumber("cafecafecafe");
-	$onu->setClientId(1);
-	$onu->setTenancyId(1);
+        $onu->setPonSerialNumber("cafecafecafe");
+        $onu->setClientId(1);
+        $onu->setTenancyId(1);
+
+        try {
+            $this->em->persist($onu);
+            $this->em->flush();
+        } catch (\Exception $e) {
+
+        }
 
-	try{
-		$this->em->persist($onu);
-		$this->em->flush();
-	}catch(\Exception $e){
-	
-	}
+        $this->assertEquals("active", $onu->getAdministrativeState());
 
-	$this->assertEquals("active", $onu->getAdministrativeState());
-            
+        $wf = $this->wr->get($onu, "administrative_state");
 
-	$wf = $this->wr->get($onu, "administrative_state");
-	
-	$wf->apply($onu, "active_to_suspend");
+        $wf->apply($onu, "suspend");
 
-	$this->assertEquals("suspend", $onu->getAdministrativeState());
+        $this->assertEquals("suspend", $onu->getAdministrativeState());
 
-	$this->em->persist($onu);
-	$this->em->flush();
+        $this->em->persist($onu);
+        $this->em->flush();
 
         $newOnu = $this->em->getRepository("FTTHBundle\Entity\ONU")->findOneByPonSerialNumber("cafecafecafe");
 
-	$this->assertEquals("suspend", $newOnu->getAdministrativeState());
+        $this->assertEquals("suspend", $newOnu->getAdministrativeState());
 
-	$wf->apply($newOnu, "suspend_to_active");
+        $wf->apply($newOnu, "active");
 
-	$this->em->persist($newOnu);
-	$this->em->flush();
+        $this->em->persist($newOnu);
+        $this->em->flush();
 
         $newOnu = $this->em->getRepository("FTTHBundle\Entity\ONU")->findOneByPonSerialNumber("cafecafecafe");
-	$this->assertEquals("active", $newOnu->getAdministrativeState());
+        $this->assertEquals("active", $newOnu->getAdministrativeState());
 
+        if ($newOnu) {
+            $newOnu = $this->em->remove($newOnu);
+            $this->em->flush();
+        }
 
-	if($newOnu){
-		$newOnu = $this->em->remove($newOnu);
-		$this->em->flush();
-	}
-	
     }
 }