Completed
Push — master ( 376ce2...d23e95 )
by Laurent
04:08
created

UnitStorageControllerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 19.28 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 2
dl 16
loc 83
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreate() 16 16 1
A testCreateError() 0 9 1
A testEdit() 0 19 1
A testEditError() 0 12 1
A testDelete() 0 11 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 AppBundle\Tests\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
7
class UnitStorageControllerTest extends WebTestCase
8
{
9 View Code Duplication
    public function testCreate()
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...
10
    {
11
        $client = static::createClient();
12
        $crawler = $client->request('GET', '/admin/Settings/Divers/UnitStorage/');
13
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr'));
14
        $crawler = $client->click($crawler->filter('.new_entry a')->link());
15
        $form = $crawler->filter('form button[type="submit"]')->form(array(
16
            'unitstorage[name]' => 'Lorem ipsum dolor sit amet',
17
            'unitstorage[abbr]' => 'Lorem ipsum dolor sit amet',
18
            'unitstorage[slug]' => 'Lorem ipsum dolor sit amet',
19
                    ));
20
        $client->submit($form);
21
        $crawler = $client->followRedirect();
22
        $crawler = $client->click($crawler->filter('.record_actions a')->link());
23
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr'));
24
    }
25
26
    public function testCreateError()
27
    {
28
        $client = static::createClient();
29
        $crawler = $client->request('GET', '/admin/Settings/Divers/UnitStorage/new');
30
        $form = $crawler->filter('form button[type="submit"]')->form();
31
        $crawler = $client->submit($form);
32
        $this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count());
33
        $this->assertTrue($client->getResponse()->isSuccessful());
34
    }
35
36
    /**
37
     * @depends testCreate
38
     */
39
    public function testEdit()
40
    {
41
        $client = static::createClient();
42
        $crawler = $client->request('GET', '/admin/Settings/Divers/UnitStorage/');
43
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("First value")'));
44
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("Changed")'));
45
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link());
46
        $form = $crawler->filter('form button[type="submit"]')->form(array(
47
            'unitstorage[name]' => 'Changed',
48
            'unitstorage[abbr]' => 'Changed',
49
            'unitstorage[slug]' => 'Changed',
50
            // ... adapt fields value here ...
51
        ));
52
        $client->submit($form);
53
        $crawler = $client->followRedirect();
54
        $crawler = $client->click($crawler->filter('.record_actions a')->link());
55
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr:contains("First value")'));
56
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr:contains("Changed")'));
57
    }
58
59
    /**
60
     * @depends testCreate
61
     */
62
    public function testEditError()
63
    {
64
        $client = static::createClient();
65
        $crawler = $client->request('GET', '/admin/Settings/Divers/UnitStorage/');
66
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(1)->link());
67
        $form = $crawler->filter('form button[type="submit"]')->form(array(
68
            'unitstorage[field_name]' => '',
69
            // ... use a required field here ...
70
        ));
71
        $crawler = $client->submit($form);
72
        $this->assertGreaterThan(0, $crawler->filter('form div.has-error')->count());
73
    }
74
75
    /**
76
     * @depends testCreate
77
     */
78
    public function testDelete()
79
    {
80
        $client = static::createClient();
81
        $crawler = $client->request('GET', '/admin/Settings/Divers/UnitStorage/');
82
        $this->assertTrue($client->getResponse()->isSuccessful());
83
        $this->assertCount(1, $crawler->filter('table.records_list tbody tr'));
84
        $crawler = $client->click($crawler->filter('table.records_list tbody tr td .btn-group a')->eq(0)->link());
85
        $client->submit($crawler->filter('form#delete button[type="submit"]')->form());
86
        $crawler = $client->followRedirect();
87
        $this->assertCount(0, $crawler->filter('table.records_list tbody tr'));
88
    }
89
}
90