Completed
Push — master ( 28b764...a7b092 )
by Michaël
02:42
created

WriterFactoryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 40 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 2
dl 14
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateWriter() 7 7 1
A testCreateWriterSingleton() 7 7 1
A testCreateWriterInvalidWriter() 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 TextFile\Tests\Factory;
4
5
use TextFile\Factory\WriterFactory;
6
use TextFile\Writer\ErasingWriter;
7
use TextFile\Writer\PrependingWriter;
8
9
/**
10
 * Class WriterFactoryTest
11
 *
12
 * @package TextFile\Tests\Factory
13
 */
14
class WriterFactoryTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @covers TextFile\Factory\WriterFactory::createWriter
18
     */
19 View Code Duplication
    public function testCreateWriter()
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...
20
    {
21
        $writerFactory = new WriterFactory();
22
23
        $this->assertInstanceOf(PrependingWriter::class, $writerFactory->createWriter(PrependingWriter::class));
24
        $this->assertInstanceOf(ErasingWriter::class, $writerFactory->createWriter(ErasingWriter::class));
25
    }
26
27
    /**
28
     * @covers TextFile\Factory\WriterFactory::createWriter
29
     */
30 View Code Duplication
    public function testCreateWriterSingleton()
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...
31
    {
32
        $writerFactory = new WriterFactory();
33
34
        $this->assertEquals($writerFactory->createWriter(PrependingWriter::class), $writerFactory->createWriter(PrependingWriter::class));
35
        $this->assertEquals($writerFactory->createWriter(ErasingWriter::class), $writerFactory->createWriter(ErasingWriter::class));
36
    }
37
38
    /**
39
     * @covers TextFile\Factory\WriterFactory::createWriter
40
     * @expectedException \TextFile\Exception\InvalidWriterException
41
     */
42
    public function testCreateWriterInvalidWriter()
43
    {
44
        $writerFactory = new WriterFactory();
45
46
        $writerFactory->createWriter(WriterFactory::class);
47
    }
48
}
49