OgSeoGeneratorTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 18.89 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 17
loc 90
rs 10
c 0
b 0
f 0

7 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 testType() 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\Og;
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\Og\OgSeoGenerator;
9
use Leogout\Bundle\SeoBundle\Seo\Og\OgSeoInterface;
10
use Leogout\Bundle\SeoBundle\Tests\TestCase;
11
12
/**
13
 * Description of OgSeoGeneratorTest.
14
 *
15
 * @author: leogout
16
 */
17
class OgSeoGeneratorTest extends TestCase
18
{
19
    /**
20
     * @var OgSeoGenerator
21
     */
22
    protected $generator;
23
24
    protected function setUp()
25
    {
26
        $this->generator = new OgSeoGenerator(new TagBuilder(new TagFactory()));
27
    }
28
29
    public function testTitle()
30
    {
31
        $this->generator->setTitle('Awesome | Site');
32
33
        $this->assertEquals(
34
            '<meta name="og: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="og: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="og: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 testType()
72
    {
73
        $this->generator->setType('website');
74
75
        $this->assertEquals(
76
            '<meta name="og:type" content="website" />',
77
            $this->generator->render()
78
        );
79
    }
80
81 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...
82
    {
83
        $resource = $this->getMockBuilder(OgSeoInterface::class)->getMock();
84
85
        $resource->method('getSeoTitle')->willReturn('Awesome site');
86
        $resource->method('getSeoDescription')->willReturn('My awesome site is so cool!');
87
        $resource->method('getSeoImage')->willReturn('http://images.com/poney/12');
88
89
        $this->generator->fromResource($resource);
90
91
        $this->assertEquals(
92
            "<meta name=\"og:title\" content=\"Awesome site\" />\n".
93
            "<meta name=\"og:description\" content=\"My awesome site is so cool!\" />\n".
94
            "<meta name=\"og:image\" content=\"http://images.com/poney/12\" />",
95
            $this->generator->render()
96
        );
97
    }
98
99
    public function testRenderNothing()
100
    {
101
        $this->assertEquals(
102
            '',
103
            $this->generator->render()
104
        );
105
    }
106
}
107