Completed
Push — master ( 4896ac...e378d5 )
by Łukasz
24:08
created

BookmarkTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 103
Duplicated Lines 65.05 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 67
loc 103
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateBookmark() 0 18 1
A testCreateBookmarkIfAlreadyExists() 10 10 1
A testIsBookmarked() 10 10 1
A testIsBookmarkedReturnsNotFound() 12 12 1
A testDeleteBookmark() 10 10 1
A testLoadBookmarks() 13 13 1
A testDeleteBookmarkReturnNotFound() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional;
10
11
use eZ\Bundle\EzPublishRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase;
12
use Symfony\Component\HttpFoundation\Response;
13
14
class BookmarkTest extends RESTFunctionalTestCase
15
{
16
    public function testCreateBookmark(): int
17
    {
18
        $content = $this->createFolder(__FUNCTION__, '/api/ezp/v2/content/locations/1/2');
19
        $contentLocations = $this->getContentLocations($content['_href']);
20
21
        $locationPathParts = explode('/', $contentLocations['LocationList']['Location'][0]['_href']);
22
        $locationId = (int) array_pop($locationPathParts);
23
24
        $request = $this->createHttpRequest(
25
            'POST', '/api/ezp/v2/bookmark/' . $locationId
26
        );
27
28
        $response = $this->sendHttpRequest($request);
29
30
        self::assertHttpResponseCodeEquals($response, Response::HTTP_CREATED);
31
32
        return $locationId;
33
    }
34
35
    /**
36
     * @depends testCreateBookmark
37
     */
38 View Code Duplication
    public function testCreateBookmarkIfAlreadyExists(int $locationId): void
39
    {
40
        $request = $this->createHttpRequest(
41
            'POST', '/api/ezp/v2/bookmark/' . $locationId
42
        );
43
44
        $response = $this->sendHttpRequest($request);
45
46
        self::assertHttpResponseCodeEquals($response, Response::HTTP_CONFLICT);
47
    }
48
49
    /**
50
     * @depends testCreateBookmark
51
     */
52 View Code Duplication
    public function testIsBookmarked(int $locationId): void
53
    {
54
        $request = $this->createHttpRequest(
55
            'HEAD', '/api/ezp/v2/bookmark/' . $locationId
56
        );
57
58
        $response = $this->sendHttpRequest($request);
59
60
        self::assertHttpResponseCodeEquals($response, Response::HTTP_OK);
61
    }
62
63 View Code Duplication
    public function testIsBookmarkedReturnsNotFound(): void
64
    {
65
        $locationId = 43;
66
67
        $request = $this->createHttpRequest(
68
            'HEAD', '/api/ezp/v2/bookmark/' . $locationId
69
        );
70
71
        $response = $this->sendHttpRequest($request);
72
73
        self::assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND);
74
    }
75
76
    /**
77
     * @depends testCreateBookmark
78
     */
79 View Code Duplication
    public function testDeleteBookmark(int $locationId): void
80
    {
81
        $request = $this->createHttpRequest(
82
            'DELETE', '/api/ezp/v2/bookmark/' . $locationId
83
        );
84
85
        $response = $this->sendHttpRequest($request);
86
87
        self::assertHttpResponseCodeEquals($response, Response::HTTP_NO_CONTENT);
88
    }
89
90 View Code Duplication
    public function testLoadBookmarks(): void
91
    {
92
        $request = $this->createHttpRequest(
93
            'GET',
94
            '/api/ezp/v2/bookmark?offset=1&limit=100',
95
            'BookmarkList+xml',
96
            'BookmarkList+xml'
97
        );
98
99
        $response = $this->sendHttpRequest($request);
100
101
        self::assertHttpResponseCodeEquals($response, Response::HTTP_OK);
102
    }
103
104 View Code Duplication
    public function testDeleteBookmarkReturnNotFound(): void
105
    {
106
        $locationId = 43;
107
108
        $request = $this->createHttpRequest(
109
            'DELETE', '/api/ezp/v2/bookmark/' . $locationId
110
        );
111
112
        $response = $this->sendHttpRequest($request);
113
114
        self::assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND);
115
    }
116
}
117