ArrayResourceTest::it_should_transform_array()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Http\Resources;
6
7
use Illuminate\Http\JsonResponse;
8
use Illuminate\Http\Request;
9
use Longman\LaravelLodash\Http\Resources\ArrayResource;
10
use Tests\Unit\TestCase;
11
12
use function app;
13
14
class ArrayResourceTest extends TestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
15
{
16
    /** @test */
17 View Code Duplication
    public function it_should_transform_array(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        $resource = new ArrayResource([
20
            'aa'  => 1,
21
            'aa2' => 2,
22
            'aa3' => 3,
23
        ]);
24
25
        $request = app(Request::class);
26
        $response = $resource->additional(['custom' => '1'])->withResourceType('customType')->toResponse($request);
27
28
        $expected = '{"data":{"id":null,"type":"customType","attributes":{"aa":1,"aa2":2,"aa3":3}},"custom":"1"}';
29
30
        $this->assertInstanceOf(JsonResponse::class, $response);
31
        $this->assertSame($expected, $response->content());
32
    }
33
34
    /** @test */
35 View Code Duplication
    public function it_should_return_unecaped_json(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $resource = new ArrayResource([
38
            'aa'  => 'ერთი',
39
            'aa2' => 'ორი',
40
            'aa3' => 'სამი',
41
        ]);
42
43
        $request = app(Request::class);
44
        $response = $resource->additional(['custom' => '1'])->withResourceType('customType')->toResponse($request);
45
46
        $expected = '{"data":{"id":null,"type":"customType","attributes":{"aa":"ერთი","aa2":"ორი","aa3":"სამი"}},"custom":"1"}';
47
48
        $this->assertInstanceOf(JsonResponse::class, $response);
49
        $this->assertSame($expected, $response->content());
50
    }
51
}
52