Completed
Pull Request — master (#45)
by Laurent
04:03
created

CompanyControllerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

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