Completed
Branch master (0b86d9)
by Léo
02:17
created

TwitterSeoGeneratorTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 100
Duplicated Lines 17 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testTitle() 0 13 1
A testDescription() 0 13 1
A testImage() 0 13 1
A testCard() 0 9 1
A testSite() 0 9 1
A testFromResource() 17 17 1
A testRenderNothing() 0 7 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 Leogout\Bundle\SeoBundle\Tests\Seo\Twitter;
4
5
use Leogout\Bundle\SeoBundle\Builder\TagBuilder;
6
use Leogout\Bundle\SeoBundle\Factory\TagFactory;
7
use Leogout\Bundle\SeoBundle\Model\MetaTag;
8
use Leogout\Bundle\SeoBundle\Seo\Twitter\TwitterSeoGenerator;
9
use Leogout\Bundle\SeoBundle\Seo\Twitter\TwitterSeoInterface;
10
use Leogout\Bundle\SeoBundle\Tests\TestCase;
11
12
/**
13
 * Description of TwitterSeoGeneratorTest.
14
 *
15
 * @author: leogout
16
 */
17
class TwitterSeoGeneratorTest extends TestCase
18
{
19
    /**
20
     * @var TwitterSeoGenerator
21
     */
22
    protected $generator;
23
24
    protected function setUp()
25
    {
26
        $this->generator = new TwitterSeoGenerator(new TagBuilder(new TagFactory()));
27
    }
28
29
    public function testTitle()
30
    {
31
        $this->generator->setTitle('Awesome | Site');
32
33
        $this->assertEquals(
34
            '<meta name="twitter:title" content="Awesome | Site" />',
35
            $this->generator->render()
36
        );
37
38
        $this->assertInstanceOf(
39
            MetaTag::class, $this->generator->getTitle()
40
        );
41
    }
42
43
    public function testDescription()
44
    {
45
        $this->generator->setDescription('My awesome site is so cool!');
46
47
        $this->assertEquals(
48
            '<meta name="twitter:description" content="My awesome site is so cool!" />',
49
            $this->generator->render()
50
        );
51
52
        $this->assertInstanceOf(
53
            MetaTag::class, $this->generator->getDescription()
54
        );
55
    }
56
57
    public function testImage()
58
    {
59
        $this->generator->setImage('http://images.com/poney/12');
60
61
        $this->assertEquals(
62
            '<meta name="twitter:image" content="http://images.com/poney/12" />',
63
            $this->generator->render()
64
        );
65
66
        $this->assertInstanceOf(
67
            MetaTag::class, $this->generator->getImage()
68
        );
69
    }
70
71
    public function testCard()
72
    {
73
        $this->generator->setCard('summary');
74
75
        $this->assertEquals(
76
            '<meta name="twitter:card" content="summary" />',
77
            $this->generator->render()
78
        );
79
    }
80
81
    public function testSite()
82
    {
83
        $this->generator->setSite('@leogoutt');
84
85
        $this->assertEquals(
86
            '<meta name="twitter:site" content="@leogoutt" />',
87
            $this->generator->render()
88
        );
89
    }
90
91 View Code Duplication
    public function testFromResource()
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...
92
    {
93
        $resource = $this->getMockBuilder(TwitterSeoInterface::class)->getMock();
94
95
        $resource->method('getSeoTitle')->willReturn('Awesome site');
96
        $resource->method('getSeoDescription')->willReturn('My awesome site is so cool!');
97
        $resource->method('getSeoImage')->willReturn('http://images.com/poney/12');
98
99
        $this->generator->fromResource($resource);
100
101
        $this->assertEquals(
102
            "<meta name=\"twitter:title\" content=\"Awesome site\" />\n".
103
            "<meta name=\"twitter:description\" content=\"My awesome site is so cool!\" />\n".
104
            "<meta name=\"twitter:image\" content=\"http://images.com/poney/12\" />",
105
            $this->generator->render()
106
        );
107
    }
108
109
    public function testRenderNothing()
110
    {
111
        $this->assertEquals(
112
            '',
113
            $this->generator->render()
114
        );
115
    }
116
}
117