BatchUpdaterTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 61.22 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 5
dl 30
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A testUpdate() 15 15 1
A testDelete() 15 15 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
namespace CouchDB\Tests\Util;
4
5
use CouchDB\Tests\TestCase;
6
use CouchDB\Util\BatchUpdater;
7
use GuzzleHttp\Psr7\Response;
8
9
/**
10
 * @author Markus Bachmann <[email protected]>
11
 */
12
class BatchUpdaterTest extends TestCase
13
{
14
    protected function setUp()
15
    {
16
        parent::setUp();
17
18
        $this->database = $this->getMockBuilder('CouchDB\Database')
19
            ->disableOriginalConstructor()
20
            ->getMock();
21
22
        $this->database->expects($this->any())
23
            ->method('getName')
24
            ->willReturn('test');
25
26
        $this->updater = new BatchUpdater($this->client, $this->database);
27
    }
28
29 View Code Duplication
    public function testUpdate()
30
    {
31
        $this->updater->update(['_id' => 'bar1']);
32
        $this->updater->update(['_id' => 'bar2']);
33
34
        $this->mock->append(new Response(200, [], '{}'));
35
36
        $this->updater->execute();
37
38
        $request = $this->mock->getLastRequest();
39
40
        $this->assertEquals('POST', $request->getMethod());
41
        $this->assertEquals('/test/_bulk_docs', $request->getUri()->getPath());
42
        $this->assertEquals('{"docs":[{"_id":"bar1"},{"_id":"bar2"}]}', (string) $request->getBody());
43
    }
44
45 View Code Duplication
    public function testDelete()
46
    {
47
        $this->updater->delete('bar1', 'rev');
48
        $this->updater->delete('bar2', 'rev');
49
50
        $this->mock->append(new Response(200, [], '{}'));
51
52
        $this->updater->execute();
53
54
        $request = $this->mock->getLastRequest();
55
56
        $this->assertEquals('POST', $request->getMethod());
57
        $this->assertEquals('/test/_bulk_docs', $request->getUri()->getPath());
58
        $this->assertEquals('{"docs":[{"_id":"bar1","_rev":"rev","_deleted":true},{"_id":"bar2","_rev":"rev","_deleted":true}]}', (string) $request->getBody());
59
    }
60
}
61