소스 검색

:recycle: Add test on new feature, try to improve code coverage.

Signed-off-by: Lloric Mayuga Garcia <lloricode@gmail.com>
Lloric Mayuga Garcia 6 년 전
부모
커밋
70df4c9bed
3개의 변경된 파일26개의 추가작업 그리고 5개의 파일을 삭제
  1. 1 1
      config/apidoc.php
  2. 1 1
      src/Tools/ResponseStrategies/TransformerTagsStrategy.php
  3. 24 3
      tests/Unit/GeneratorTestCase.php

+ 1 - 1
config/apidoc.php

@@ -17,7 +17,7 @@ return [
      */
     'postman' => true,
 
-     /**
+     /*
      * Fractal Transformer Config
      *
      * must install

+ 1 - 1
src/Tools/ResponseStrategies/TransformerTagsStrategy.php

@@ -47,7 +47,7 @@ class TransformerTagsStrategy
 
             $fractal = new Manager();
  
-            if (!is_null(config('apidoc.fractal.serializer'))) {
+            if (! is_null(config('apidoc.fractal.serializer'))) {
                 $fractal->setSerializer(app(config('apidoc.fractal.serializer')));
             }
 

+ 24 - 3
tests/Unit/GeneratorTestCase.php

@@ -224,9 +224,16 @@ abstract class GeneratorTestCase extends TestCase
         ], json_decode($parsed['response'][1]['content'], true));
     }
 
-    /** @test */
-    public function can_parse_transformer_tag()
+    /**
+     * @param $serializer
+     * @param $expected
+     *
+     * @test
+     * @dataProvider dataResources
+     */
+    public function can_parse_transformer_tag($serializer, $expected)
     {
+        config(['apidoc.fractal.serializer' => $serializer]);
         $route = $this->createRoute('GET', '/transformerTag', 'transformerTag');
         $parsed = $this->generator->processRoute($route);
         $response = array_first($parsed['response']);
@@ -238,10 +245,24 @@ abstract class GeneratorTestCase extends TestCase
         $this->assertEquals(200, $response['status']);
         $this->assertSame(
             $response['content'],
-            '{"data":{"id":1,"description":"Welcome on this test versions","name":"TestName"}}'
+            $expected
         );
     }
 
+    public function dataResources()
+    {
+        return [
+            [
+                null,
+                '{"data":{"id":1,"description":"Welcome on this test versions","name":"TestName"}}'
+            ],
+            [
+                'League\Fractal\Serializer\JsonApiSerializer',
+                '{"data":{"type":null,"id":"1","attributes":{"description":"Welcome on this test versions","name":"TestName"}}}'
+            ],
+        ];
+    }
+
     /** @test */
     public function can_parse_transformer_tag_with_model()
     {