raphael 3 years ago
parent
commit
53e578e701

+ 0
- 1
Controller/BackOffice/JupyterVirtualClassroomController.php View File

@@ -10,7 +10,6 @@ use Logipro\Bundle\PhoenixJupyterBundle\Components\ModalLayer;
10 10
 use Logipro\Bundle\PhoenixJupyterBundle\Components\FormLayer;
11 11
 use Logipro\Bundle\PhoenixJupyterBundle\Form\JupyterUpdateType;
12 12
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterToken;
13
-use Logipro\Bundle\PhoenixJupyterBundle\Components\ApiLayer\ApiLayer;
14 13
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterClassroomRegistration;
15 14
 use Logipro\Bundle\PhoenixJupyterBundle\Controller\JupyterVirtualClassroomTrait;
16 15
 

+ 0
- 12
Controller/JupyterVirtualClassroomTrait.php View File

@@ -1,12 +0,0 @@
1
-<?php
2
-
3
-namespace Logipro\Bundle\PhoenixJupyterBundle\Controller;
4
-
5
-use Logipro\Phoenix\Entity\Person\Person;
6
-
7
-use Logipro\Bundle\PhoenixJupyterBundle\Components\ApiLayer\ApiLayer;
8
-use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterToken;
9
-
10
-trait JupyterVirtualClassroomTrait
11
-{
12
-}

+ 1
- 2
Controller/LearningSpace/JupyterVirtualClassroomController.php View File

@@ -11,7 +11,6 @@ use Logipro\Bundle\PhoenixJupyterBundle\Components\ModalLayer;
11 11
 use Logipro\Bundle\PhoenixJupyterBundle\Components\FormLayer;
12 12
 use Logipro\Bundle\PhoenixJupyterBundle\Form\JupyterUpdateType;
13 13
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterToken;
14
-use Logipro\Bundle\PhoenixJupyterBundle\Components\ApiLayer\ApiLayer;
15 14
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterClassroomRegistration;
16 15
 use Logipro\Bundle\PhoenixJupyterBundle\Controller\JupyterVirtualClassroomTrait;
17 16
 
@@ -137,7 +136,7 @@ class JupyterVirtualClassroomController extends LearningSpaceController
137 136
 		return $this->json($response);
138 137
 	}
139 138
 
140
-    public function drawNotebookLoadingPage(Request $request,$jupyterVirtualClassroomId)
139
+    public function drawNotebookLoadingPage(Request $request,int $jupyterVirtualClassroomId)
141 140
     {
142 141
 		return $this->phxRender('@LogiproPhoenixJupyter/learning_space/notebookLoading.html.twig', array('sequenceItemId' => $jupyterVirtualClassroomId));
143 142
 	}

+ 17
- 0
Entity/JupyterVirtualClassroom.php View File

@@ -7,6 +7,9 @@ use Logipro\Phoenix\Entity\SequenceItem\SequenceItem;
7 7
 use Logipro\Phoenix\Entity\Person\Trainer;
8 8
 use Logipro\Phoenix\Entity\SequenceItem\ActivityInterface;
9 9
 
10
+use Symfony\Component\Validator\Constraints as Assert;
11
+use Symfony\Component\Validator\Mapping\ClassMetadata;
12
+
10 13
 class JupyterVirtualClassroom extends SequenceItem
11 14
 implements ActivityInterface
12 15
 {
@@ -188,4 +191,18 @@ implements ActivityInterface
188 191
 		return false;
189 192
 	}
190 193
 
194
+	/**
195
+	 * Définit les contraintes de validation des données de formulaire.
196
+	 * @param ClassMetadata $metadata
197
+	 */
198
+	public static function loadValidatorMetadata(ClassMetadata $metadata)
199
+	{
200
+		parent::loadValidatorMetadata($metadata);
201
+
202
+		// au moins trois lettres
203
+		$metadata->addPropertyConstraint('title', new Assert\Regex([
204
+            'pattern' => '/[a-zA-Z]{3,}/',
205
+		]));
206
+	}
207
+
191 208
 }

+ 10
- 5
EntityListener/JupyterEventListener.php View File

@@ -6,23 +6,28 @@ use Doctrine\ORM\Event\LifecycleEventArgs;
6 6
 use Doctrine\Common\Collections\ArrayCollection;
7 7
 
8 8
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterVirtualClassroom;
9
-use Logipro\Bundle\PhoenixJupyterBundle\Components\ApiLayer\ApiLayer;
10 9
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterToken;
11 10
 use Doctrine\ORM\Event\PostFlushEventArgs;
11
+use Logipro\Bundle\PhoenixJupyterBundle\Services\ApiLayer\ApiLayerService;
12 12
 /**
13 13
  * Event listener relatif aux entités constituant le learningPath.
14 14
  */
15 15
 class JupyterEventListener
16 16
 {
17
+
17 18
 	private $needsFlush = false;
19
+	private $layer;
20
+
21
+	public function __construct(ApiLayerService $layer)
22
+	{
23
+		$this->layer = $layer;
24
+	}
18 25
 
19 26
 	public function postPersist (LifecycleEventArgs $args)
20 27
 	{
21 28
 		$jupyterVirtualClassroom = $args->getEntity();
22 29
 		if (is_a($jupyterVirtualClassroom,JupyterVirtualClassroom::class))
23 30
 		{
24
-			$layer = ApiLayer::getInstanceIfAvalaible();
25
-
26 31
 			$trainer = $jupyterVirtualClassroom->getTrainer();
27 32
 
28 33
 			$manager = $args->getEntityManager();
@@ -34,12 +39,12 @@ class JupyterEventListener
34 39
 				$token = $repository->findOneBy(array('person' => $trainer));
35 40
 			}
36 41
 		
37
-			if ($layer && $token)
42
+			if ($this->layer && $token)
38 43
 			{
39 44
 				$learningPath = $jupyterVirtualClassroom->getLearningPath();
40 45
 				if ($learningPath->getIsClone())
41 46
 				{
42
-					$layer->cloneNotebook($token,$jupyterVirtualClassroom);
47
+					$this->layer->cloneNotebook($token,$jupyterVirtualClassroom);
43 48
 
44 49
 					$this->needsFlush = true;
45 50
 				}

+ 8
- 4
EntityListener/JupyterVirtualClassroomListener.php View File

@@ -7,8 +7,8 @@ use Doctrine\ORM\Event\PostFlushEventArgs;
7 7
 use Doctrine\Common\Collections\ArrayCollection;
8 8
 
9 9
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterVirtualClassroom;
10
-use Logipro\Bundle\PhoenixJupyterBundle\Components\ApiLayer\ApiLayer;
11 10
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterToken;
11
+use Logipro\Bundle\PhoenixJupyterBundle\Services\ApiLayer\ApiLayerService;
12 12
 
13 13
 /**
14 14
  * Event listener relatif aux entités constituant le learningPath.
@@ -17,10 +17,14 @@ class JupyterVirtualClassroomListener
17 17
 {
18 18
 	private $needsFlush = false;
19 19
 
20
+	public function __construct(ApiLayerService $layer)
21
+	{
22
+		$this->layer = $layer;
23
+	}
24
+
20 25
 	public function preRemove(JupyterVirtualClassroom $jupyterVirtualClassroom,LifecycleEventArgs $args)
21 26
 	{
22
-		$layer = ApiLayer::getInstanceIfAvalaible();
23
-		if ($layer)
27
+		if ($this->layer)
24 28
 		{
25 29
 			// supprime le notebook du formateur
26 30
 			$manager = $args->getEntityManager();
@@ -28,7 +32,7 @@ class JupyterVirtualClassroomListener
28 32
 			$token = $tokenRepository->findOneBy(array('person' => $jupyterVirtualClassroom->getTrainer()));
29 33
 			if ($token)
30 34
 			{
31
-				$layer->deleteNotebook($token,$jupyterVirtualClassroom);
35
+				$this->layer->deleteNotebook($token,$jupyterVirtualClassroom);
32 36
 			}
33 37
 		}
34 38
 	}

+ 6
- 4
Resources/config/routes.yaml View File

@@ -5,27 +5,29 @@ open_trainer_jupyter_classroom:
5 5
   path: /jupyter/trainer/open/{jupyterVirtualClassroomId}
6 6
   controller: Logipro\Bundle\PhoenixJupyterBundle\Controller\BackOffice\JupyterVirtualClassroomController::openTrainerJupyterVirtualClassroom
7 7
   requirements:
8
-    template_path: '.*'
8
+    jupyterVirtualClassroomId: '\d+'
9 9
 
10 10
 open_student_jupyter_classroom:
11 11
   path: /learning-space/jupyter/student/open/{jupyterVirtualClassroomId}
12 12
   controller: Logipro\Bundle\PhoenixJupyterBundle\Controller\LearningSpace\JupyterVirtualClassroomController::openStudentJupyterVirtualClassroom
13 13
   requirements:
14
-    template_path: '.*'
14
+    jupyterVirtualClassroomId: '\d+'
15 15
 
16 16
 send_student_jupyter_notebook:
17 17
   path: /learning-space/jupyter/student/send/{jupyterVirtualClassroomId}
18 18
   controller: Logipro\Bundle\PhoenixJupyterBundle\Controller\LearningSpace\JupyterVirtualClassroomController::sendStudentJupyterNotebook
19 19
   requirements:
20
-    template_path: '.*'
20
+    jupyterVirtualClassroomId: '\d+'
21 21
 
22 22
 draw_loading_jupyter_notebook:
23 23
   path: /learning-space/jupyter/student/loading/{jupyterVirtualClassroomId}
24 24
   controller: Logipro\Bundle\PhoenixJupyterBundle\Controller\LearningSpace\JupyterVirtualClassroomController::drawNotebookLoadingPage
25 25
   requirements:
26
-    template_path: '.*'
26
+    jupyterVirtualClassroomId: '\d+'
27 27
 
28 28
 
29 29
 reset_notebook:
30 30
   path: /learning-space/jupyter/student/reset/{jupyterVirtualClassroomId}
31 31
   controller: Logipro\Bundle\PhoenixJupyterBundle\Controller\LearningSpace\JupyterVirtualClassroomController::resetNotebook
32
+  requirements:
33
+    jupyterVirtualClassroomId: '\d+'

+ 6
- 1
Resources/config/services.yaml View File

@@ -22,7 +22,12 @@ services:
22 22
     calls:
23 23
         - [ setContainer, [ '@service_container' ]]
24 24
         
25
+  # Entity Listeners
26
+  Logipro\Bundle\PhoenixJupyterBundle\EntityListener\:
27
+    resource: '../../EntityListener/*'
28
+    tags: [doctrine.orm.entity_listener]
29
+
25 30
   Logipro\Bundle\PhoenixJupyterBundle\EntityListener\JupyterEventListener:
26 31
     tags:
27 32
        - { name: "doctrine.event_listener",  event: "postPersist" }
28
-       - { name: "doctrine.event_listener",  event: "postFlush" }
33
+       - { name: "doctrine.event_listener",  event: "postFlush" }

Components/ApiLayer/ApiLayer.php → Services/ApiLayer/ApiLayerService.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Bundle\PhoenixJupyterBundle\Components\ApiLayer;
2
+namespace Logipro\Bundle\PhoenixJupyterBundle\Services\ApiLayer;
3 3
 
4 4
 use Symfony\Component\HttpClient\HttpClient;
5 5
 use Symfony\Component\HttpClient\Exception\TransportException;
@@ -10,7 +10,7 @@ use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterToken;
10 10
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterVirtualClassroom;
11 11
 use Logipro\Phoenix\Component\PhxFileGuesser;
12 12
 
13
-class ApiLayer
13
+class ApiLayerService
14 14
 {
15 15
     private static $instance = null;
16 16
     
@@ -39,7 +39,7 @@ class ApiLayer
39 39
      */
40 40
     private $token = null;
41 41
 
42
-    private function __construct()
42
+    public function __construct()
43 43
     {
44 44
         $server = $_SERVER['JUPYTER_URL'].trim('/');
45 45
 
@@ -87,7 +87,7 @@ class ApiLayer
87 87
             {
88 88
                 /*echo 'erreur :';
89 89
                 dump($response->getContent());*/
90
-                // @FIXME peut être mettre une erreur
90
+                // FIXME peut être mettre une erreur
91 91
                 return null;
92 92
             }
93 93
             return \json_decode($this->response->getContent(),true);
@@ -301,26 +301,6 @@ class ApiLayer
301 301
         return false;
302 302
     }
303 303
     
304
-    /**
305
-     * retourne l'instance de la classe si le service est disponible
306
-     */
307
-    public static function getInstanceIfAvalaible()
308
-    {
309
-        if (!self::$instance)
310
-        {
311
-            $layer = new ApiLayer();
312
-
313
-            // test si le service http est disponible sur le distant (url à configurer dans le .env)
314
-            if (!$layer->serviceIsAvalaible())
315
-            {
316
-                return null;
317
-            }
318
-
319
-            self::$instance = $layer;
320
-        }
321
-        return self::$instance;
322
-    }
323
-
324 304
     /**
325 305
      * échappe le texte
326 306
      * et retourne le contenu échappé
@@ -624,7 +604,7 @@ class ApiLayer
624 604
     }
625 605
 
626 606
     /**
627
-     * @FIXME à dev
607
+     * FIXME à dev
628 608
      */
629 609
     public function stopServer($token)
630 610
     {

+ 64
- 59
Services/PhoenixServices.php View File

@@ -10,44 +10,30 @@ use Symfony\Component\HttpFoundation\Request;
10 10
 use Logipro\Bundle\PhoenixJupyterBundle\Components\ModalLayer;
11 11
 use Logipro\Bundle\PhoenixJupyterBundle\Components\FormLayer;
12 12
 
13
+use Symfony\Component\Form\FormFactoryInterface;
14
+use Doctrine\ORM\EntityManagerInterface;
15
+use Symfony\Component\Routing\RouterInterface;
16
+
13 17
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterToken;
14 18
 use Logipro\Phoenix\Entity\Person\Trainer;
15 19
 use Logipro\Bundle\PhoenixJupyterBundle\Form\JupyterUpdateType;
16
-use Logipro\Bundle\PhoenixJupyterBundle\Components\ApiLayer\ApiLayer;
17 20
 use Logipro\Phoenix\Entity\Person\Person;
18 21
 use Logipro\Bundle\PhoenixJupyterBundle\Entity\JupyterClassroomRegistration;
22
+use Logipro\Bundle\PhoenixJupyterBundle\Services\ApiLayer\ApiLayerService;
19 23
 
20 24
 class PhoenixServices extends Services
21 25
 {
22
-	private $apiService;
26
+	private $layer;
27
+	private $isAvalaible;
23 28
 	private $layoutPath = '@LogiproPhoenixJupyter/back-office/';
24 29
 
25
-	public function __construct(FormFactoryInterface $formFactory,EntityManagerInterface $manager,RouterInterface $router)
26
-	{
27
-        $this->layer = ApiLayer::getInstanceIfAvalaible();
28
-        $this->manager = $manager;
29
-        $this->router = $router;
30
-	}
31
-	
32
-
33
-	public function setLayer()
30
+	public function __construct(FormFactoryInterface $formFactory,EntityManagerInterface $manager,RouterInterface $router,ApiLayerService $layer)
34 31
 	{
32
+		parent::__construct($formFactory,$manager,$router);
35 33
 
34
+		$this->layer = $layer;
36 35
 	}
37 36
 
38
-    /**
39
-     * dit si le service jupyter est entièrement accessible
40
-     * @return bool
41
-     */
42
-    public static function serviceIsAvalaible() : boolval
43
-    {
44
-        // test l'api jupyter
45
-        if (ApiLayer::getInstanceIfAvalaible())
46
-        {
47
-            return true;
48
-        }
49
-        return false;
50
-    }
51 37
     /**
52 38
      * retourne le chemin de la classe de l'entité du bundle
53 39
      * @return string
@@ -55,19 +41,33 @@ class PhoenixServices extends Services
55 41
     public function getEntityClass() : string
56 42
     {
57 43
         return JupyterVirtualClassroom::class;
58
-    }
44
+	}
45
+	
46
+	public function serviceIsAvalaible()
47
+	{
48
+		if (is_null($this->isAvalaible))
49
+		{
50
+			$this->isAvalaible = $this->layer->serviceIsAvalaible();
51
+		}
52
+		return $this->isAvalaible;
53
+	}
59 54
 
60
-    private function getApiService() : ApiLayer
55
+    protected function getApiService()
61 56
     {
62
-        if (!$this->apiService)
63
-        {
64
-            $this->apiService = ApiLayer::getInstanceIfAvalaible();
65
-            if (!$this->apiService)
66
-            {
67
-                throw new \Exception();
68
-            }
69
-        }
70
-        return  $this->apiService;
57
+		if (!$this->isAvalaible)
58
+		{
59
+			$this->isAvalaible = $this->layer->serviceIsAvalaible();
60
+		}
61
+		
62
+		if ($this->isAvalaible)
63
+		{
64
+			return $this->layer;
65
+		}
66
+		else
67
+		{
68
+			throw new \Exception('Service Jupyter indisponible');
69
+		}
70
+		return null;
71 71
     }
72 72
 
73 73
     /**
@@ -243,34 +243,35 @@ class PhoenixServices extends Services
243 243
 			}
244 244
 
245 245
 			$form->handleRequest($request);
246
-			try
246
+			if ($form->isSubmitted())
247 247
 			{
248
-				if ($form->isSubmitted())
248
+				if ($form->isValid())
249 249
 				{
250
-					if ($form->isValid())
250
+					// créé la classe distante
251
+					$repository = $this->getRepository(Trainer::class);
252
+					$trainer = $jupyter->getTrainer();
253
+					if ($trainer)
251 254
 					{
252
-						// créé la classe distante
253
-						$repository = $this->getRepository(Trainer::class);
254
-						$trainer = $jupyter->getTrainer();
255
-						if ($trainer)
256
-						{
257
-							$jupyter->setTrainer($trainer);
258
-							$this->createTrainerJupyterServer($jupyter);
259
-						}
260
-
261
-						$jupyter->setItemOrder($order);
262
-
263
-						$manager = $this->getManager();
264
-						$manager->persist($jupyter);
265
-						$manager->flush();
266
-
267
-						return $jupyter->getSequenceItemId();
255
+						$jupyter->setTrainer($trainer);
256
+						$this->createTrainerJupyterServer($jupyter);
268 257
 					}
258
+
259
+					$jupyter->setItemOrder($order);
260
+
261
+					$manager = $this->getManager();
262
+					$manager->persist($jupyter);
263
+					$manager->flush();
264
+
265
+					return $jupyter->getSequenceItemId();
266
+				}
267
+				else
268
+				{
269
+					throw new \InvalidArgumentException($form->getErrors(true));
269 270
 				}
270 271
 			}
271
-			catch (\Exception $exp)
272
+			else
272 273
 			{
273
-				dump($exp->getMessage());
274
+				throw new \InvalidArgumentException($form->getErrors(true));
274 275
 			}
275 276
 		}
276 277
 		return null;
@@ -412,7 +413,11 @@ class PhoenixServices extends Services
412 413
 			// si l'item a un formateur
413 414
 			if ($currentTrainer)
414 415
 			{
415
-				$fromUrl = $oldEntityData['url'];
416
+				$fromUrl = null;
417
+				if ($oldTrainer)
418
+				{
419
+					$fromUrl = $oldEntityData['url'];
420
+				}
416 421
 				
417 422
 				// met en place le compte et le contenu du notebook
418 423
 				$url = $this->createTrainerJupyterServer($sequenceItem,$fromUrl,$content,false);
@@ -436,7 +441,7 @@ class PhoenixServices extends Services
436 441
 		}
437 442
 		foreach ($mustStopServer as $token)
438 443
 		{
439
-			// @fixme a dev
444
+			// fixme a dev
440 445
 			//$layer->stopServer($token);
441 446
 		}
442 447
     }
@@ -595,7 +600,7 @@ class PhoenixServices extends Services
595 600
 	/**
596 601
 	 * envoi le notebook de l'apprenant afin d'obtenir son évaluation
597 602
 	 * 
598
-	 * @FIXME a tester
603
+	 * FIXME a tester
599 604
 	 *
600 605
 	 * @param JupyterVirtualClassroom $sequenceItem
601 606
 	 * @return void

+ 0
- 36
Tests/Services/ApiLayer/ApiLayerMock.php View File

@@ -1,36 +0,0 @@
1
-<?php
2
-class ApiLayerMock {
3
-	/**
4
-	 * Generates a mock object on the singleton Someclass util object.
5
-	 *
6
-	 * @param array $name
7
-	 * @return void
8
-	 */
9
-	public static function expects($name, $replace) {
10
-		// Mock the object
11
-		$mock = \PHPUnit_Framework_MockObject_Generator::getMock(
12
-			'ApiLayer',
13
-			array('getInstanceIfAvalaible'),
14
-			array(),
15
-			'',
16
-			false
17
-		);
18
-		// Replace protected self reference with mock object
19
-		$ref = new \ReflectionProperty('ApiLayer', 'self');
20
-		$ref->setAccessible(true);
21
-		$ref->setValue(null, $mock);
22
-		// Set expectations and return values
23
-		$mock
24
-			->expects(new \PHPUnit_Framework_MockObject_Matcher_InvokedCount(1))
25
-			->method('getInstanceIfAvalaible')
26
-			->with(
27
-				\PHPUnit_Framework_Assert::equalTo($name)
28
-			)
29
-			->will(new \PHPUnit_Framework_MockObject_Stub_Return($replace));
30
-	}
31
-	public static function cleanup() {
32
-		$ref = new \ReflectionProperty('ApiLayer', 'self');
33
-		$ref->setAccessible(true);
34
-		$ref->setValue(null, null);
35
-	}
36
-}

+ 12
- 0
Tests/Services/PhoenixServicesMock.php View File

@@ -0,0 +1,12 @@
1
+<?php
2
+namespace Logipro\Bundle\PhoenixJupyterBundle\Tests\Services;
3
+
4
+use Logipro\Bundle\PhoenixJupyterBundle\Services\PhoenixServices;
5
+
6
+class PhoenixServicesMock extends PhoenixServices
7
+{
8
+    public function getApiService()
9
+    {
10
+        return parent::getApiService();
11
+    }
12
+}

+ 23
- 24
Tests/Services/PhoenixServicesTest.php View File

@@ -6,52 +6,51 @@ use PHPUnit\Framework\TestCase;
6 6
 use Symfony\Component\Form\FormFactoryInterface;
7 7
 use Doctrine\ORM\EntityManagerInterface;
8 8
 use Symfony\Component\Routing\RouterInterface;
9
-use Logipro\Bundle\PhoenixJupyterBundle\Components\ApiLayer\ApiLayer;
10
-use Logipro\Bundle\PhoenixJupyterBundle\Services\PhoenixServices;
9
+use Logipro\Bundle\PhoenixJupyterBundle\Repository\JupyterVirtualClassroomRepository;
10
+use Logipro\Phoenix\Entity\Person\Person;
11
+use Logipro\Bundle\PhoenixJupyterBundle\Services\ApiLayer\ApiLayerService;
11 12
 
12 13
 class PhoenixServicesTest extends TestCase
13 14
 {
14
-	/**
15
-     * @expectedException Exception
16
-     */
17 15
 	private function mockPhoenixServices($serviceIsAvalaible = true)
18 16
 	{
19 17
 		// mock FormFactoryInterface
20
-		$formFactory = $this->getMockBuilder(FormFactoryInterface::class);
18
+		$formFactory = $this->createMock(FormFactoryInterface::class);
21 19
 
22 20
 		// mock EntityManagerInterface
23
-		$entityManager = $this->getMockBuilder(EntityManagerInterface::class);
21
+		$entityManager = $this->createMock(EntityManagerInterface::class);
24 22
 
25 23
 		// mock RouterInterface
26
-		$router = $this->getMockBuilder(RouterInterface::class);
24
+		$router = $this->createMock(RouterInterface::class);
27 25
 
28 26
 		// mock layer
29
-		$layerMock = $this->getMockBuilder(ApiLayer::class)
30
-            ->disableOriginalConstructor()
31
-            ->setMethods(['getInstanceIfAvalaible'])
32
-			->getMock();
33
-			
34
-		if ($serviceIsAvalaible)
35
-		{
27
+		$layerMock = $this->createMock(ApiLayerService::class);
28
+        if (!$serviceIsAvalaible) {
36 29
 			$layerMock
37
-            	->method('getInstanceIfAvalaible');
38
-		}
30
+            	->method('serviceIsAvalaible')
31
+                ->willReturn(false);
32
+        }
39 33
 		else
40 34
 		{
41 35
 			$layerMock
42
-				->method('getInstanceIfAvalaible')
43
-				->willReturn($layerMock);
36
+            	->method('serviceIsAvalaible')
37
+                ->willReturn(true);
44 38
 		}
45 39
 		
46
-		return new PhoenixServices($formFactory,$entityManager,$router,$layerMock);
40
+		$service = new PhoenixServicesMock($formFactory,$entityManager,$router,$layerMock);
41
+		return $service;
47 42
 	}
48 43
 
49
-	public function testStartTrainerServerWhitoutApi()
44
+	/**
45
+     * @expectedException \Exception
46
+     */
47
+	public function testGetApiServiceWithoutApiService()
50 48
 	{
51 49
 		$service = $this->mockPhoenixServices(false);
52
-
53
-		$classRoom = new JupyterVirtualClassRoom();
54
-		$service->startTrainerServer($classRoom);
50
+		
51
+		$person = new Person();
52
+		
53
+		$service->getApiService($person);
55 54
 
56 55
 	}
57 56
 

Loading…
Cancel
Save