Failed Conditions
Push — master ( b9670c...4ba57f )
by Zac
16:20 queued 37s
created

EditGroupTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 91
Duplicated Lines 13.19 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 8
dl 12
loc 91
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 12 12 1
A testDisplaysGroupAndUsers() 0 7 1
B testRenameGroup() 0 26 1
B testChangeGroupMembership() 0 33 1
A getUsers() 0 6 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 Overwatch\TestBundle\Tests\E2E;
4
5
use Facebook\WebDriver\WebDriverBy;
6
use Overwatch\TestBundle\DataFixtures\ORM\TestGroupFixtures;
7
use Overwatch\UserBundle\DataFixtures\ORM\UserFixtures;
8
use Overwatch\UserBundle\Tests\Base\WebDriverTestCase;
9
10
/**
11
 * EditGroupTest
12
 * Tests the edit group view
13
 */
14
class EditGroupTest extends WebDriverTestCase
15
{
16 View Code Duplication
    public function setUp()
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...
17
    {
18
        parent::setUp();
19
        
20
        $this->logInAsUser('user-1');
21
        $this->waitForLoadingAnimation();
22
        $this->webDriver->findElement(
23
            //First group's edit group button
24
            WebDriverBy::cssSelector('ul.groups > li:nth-child(1) > div > a:nth-child(2)')
25
        )->click();
26
        $this->waitForLoadingAnimation();
27
    }
28
    
29
    public function testDisplaysGroupAndUsers()
30
    {
31
        $this->assertEquals(TestGroupFixtures::$groups['group-1']->getName(), $this->getHeaderText());
32
        $this->assertCount(2, $this->getUsers());
33
        $this->assertContains(UserFixtures::$users['user-1']->getEmail(), $this->getUsers()[0]->getText());
34
        $this->assertContains(UserFixtures::$users['user-2']->getEmail(), $this->getUsers()[1]->getText());
35
    }
36
    
37
    public function testRenameGroup()
38
    {
39
        $this->webDriver->findElement(
40
            WebDriverBy::cssSelector('ul.users li:nth-child(3) a:nth-child(1)')
41
        )->click();
42
        
43
        $this->waitForAlert();
44
        $this->webDriver->switchTo()->alert()->dismiss();
45
        $this->assertEquals(TestGroupFixtures::$groups['group-1']->getName(), $this->getHeaderText());
46
        
47
        $this->webDriver->findElement(
48
            WebDriverBy::cssSelector('ul.users li:nth-child(3) a:nth-child(1)')
49
        )->click();
50
        
51
        $this->waitForAlert();
52
        $this->webDriver->switchTo()->alert()->sendKeys('Group Number One');
53
        $this->webDriver->switchTo()->alert()->accept();
54
        $this->waitForLoadingAnimation();
55
        $this->assertEquals('Group Number One', $this->getHeaderText());
56
        
57
        $this->webDriver->get('http://127.0.0.1:8000/#/');
58
        $this->waitForLoadingAnimation();
59
        $this->assertContains('Group Number One', $this->webDriver->findElements(
60
            WebDriverBy::cssSelector('.groups > li.ng-scope')
61
        )[0]->getText());
62
    }
63
    
64
    public function testChangeGroupMembership()
65
    {
66
        $this->getUsers()[0]->findElement(
67
            WebDriverBy::tagName('a')
68
        )->click();
69
        $this->waitForAlert();
70
        $this->webDriver->switchTo()->alert()->dismiss();
71
        $this->assertCount(2, $this->getUsers());
72
        
73
        $this->getUsers()[0]->findElement(
74
            WebDriverBy::tagName('a')
75
        )->click();
76
        $this->waitForAlert();
77
        $this->webDriver->switchTo()->alert()->accept();
78
        $this->waitForLoadingAnimation();
79
        $this->assertCount(1, $this->getUsers());
80
        
81
        $this->webDriver->findElement(
82
            WebDriverBy::cssSelector('ul.users li:last-child a:nth-child(2)')
83
        )->click();
84
        $this->waitForAlert();
85
        $this->webDriver->switchTo()->alert()->dismiss();
86
        $this->assertCount(1, $this->getUsers());
87
        
88
        $this->webDriver->findElement(
89
            WebDriverBy::cssSelector('ul.users li:last-child a:nth-child(2)')
90
        )->click();
91
        $this->waitForAlert();
92
        $this->webDriver->switchTo()->alert()->sendKeys(UserFixtures::$users['user-1']->getEmail());
93
        $this->webDriver->switchTo()->alert()->accept();
94
        $this->waitForLoadingAnimation();
95
        $this->assertCount(2, $this->getUsers());
96
    }
97
    
98
    private function getUsers()
99
    {
100
        return $this->webDriver->findElements(
101
            WebDriverBy::className('user')
102
        );
103
    }
104
}
105