Completed
Pull Request — master (#15)
by John
02:41
created

FixedTextParserTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 6
c 3
b 1
f 0
lcom 1
cbo 5
dl 0
loc 72
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 29 1
A testGetFontSize() 0 4 1
A testGetFontFace() 0 4 1
A testGetOrientation() 0 4 1
A testGetTextFixed() 0 4 1
A testGetTextMerged() 0 4 1
1
<?php
2
3
namespace Graze\CiffRenderer\Test;
4
5
use \Mockery as m;
6
use Graze\CiffRenderer\Field\Parser\FixedTextParser;
7
use Graze\CiffRenderer\Field\Parser\ParserManager;
8
9
class FixedTextParserTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var \Graze\CiffRenderer\Field\Parser\ParserInterface
13
     */
14
    protected $parser1;
15
16
    /**
17
     * @var \Graze\CiffRenderer\Field\Parser\ParserInterface
18
     */
19
    protected $parser2;
20
21
    /**
22
     * @var \Graze\CiffRenderer\Field\Parser\ParserInterface
23
     */
24
    protected $parser3;
25
26
    public function setUp()
27
    {
28
        $pwd = dirname(__FILE__);
29
30
        $pathToFixture1 = sprintf('%s/Fixture/FixedTextParserFixture1.xml', $pwd);
31
        $pathToFixture2 = sprintf('%s/Fixture/FixedTextParserFixture2.xml', $pwd);
32
        $pathToFixture3 = sprintf('%s/Fixture/FixedTextParserFixture3.xml', $pwd);
33
34
        $xml1 = simplexml_load_file($pathToFixture1);
35
        $xml2 = simplexml_load_file($pathToFixture2);
36
        $xml3 = simplexml_load_file($pathToFixture3);
37
38
        $this->parser1 = new FixedTextParser();
39
        $this->parser2 = new FixedTextParser();
40
        $this->parser3 = new FixedTextParser();
41
42
        // parser 1 and 2 container fixed text, parser 3 contains merge text
43
        $this->parser1->setXmlField($xml1);
44
        $this->parser2->setXmlField($xml2);
45
        $this->parser3->setXmlField($xml3);
46
47
        // parser manager required for testing merge text fields
48
        $parserManager = m::mock(ParserManager::class)
49
            ->shouldReceive('getParser')
50
            ->andReturn($this->parser1, $this->parser2)
51
            ->getMock();
52
53
        $this->parser3->setParserManager($parserManager);
54
    }
55
56
    public function testGetFontSize()
57
    {
58
        $this->assertSame(7.0, $this->parser1->getFontSize());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Graze\CiffRenderer\Field\Parser\ParserInterface as the method getFontSize() does only exist in the following implementations of said interface: Graze\CiffRenderer\Field\Parser\BarcodeParser, Graze\CiffRenderer\Field...rser\AbstractDateParser, Graze\CiffRenderer\Field...r\DateParser\DateParser, Graze\CiffRenderer\Field...Parser\OffsetDateParser, Graze\CiffRenderer\Field\Parser\FixedTextParser.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
59
    }
60
61
    public function testGetFontFace()
62
    {
63
        $this->assertSame('Arial', $this->parser1->getFontFace());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Graze\CiffRenderer\Field\Parser\ParserInterface as the method getFontFace() does only exist in the following implementations of said interface: Graze\CiffRenderer\Field\Parser\BarcodeParser, Graze\CiffRenderer\Field...rser\AbstractDateParser, Graze\CiffRenderer\Field...r\DateParser\DateParser, Graze\CiffRenderer\Field...Parser\OffsetDateParser, Graze\CiffRenderer\Field\Parser\FixedTextParser.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
64
    }
65
66
    public function testGetOrientation()
67
    {
68
        $this->assertSame(270, $this->parser1->getOrientation());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Graze\CiffRenderer\Field\Parser\ParserInterface as the method getOrientation() does only exist in the following implementations of said interface: Graze\CiffRenderer\Field\Parser\BarcodeParser, Graze\CiffRenderer\Field...rser\AbstractDateParser, Graze\CiffRenderer\Field...r\DateParser\DateParser, Graze\CiffRenderer\Field...Parser\OffsetDateParser, Graze\CiffRenderer\Field\Parser\FixedTextParser.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
69
    }
70
71
    public function testGetTextFixed()
72
    {
73
        $this->assertSame('some text', $this->parser1->getText());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Graze\CiffRenderer\Field\Parser\ParserInterface as the method getText() does only exist in the following implementations of said interface: Graze\CiffRenderer\Field\Parser\BarcodeParser, Graze\CiffRenderer\Field...rser\AbstractDateParser, Graze\CiffRenderer\Field...r\DateParser\DateParser, Graze\CiffRenderer\Field...Parser\OffsetDateParser, Graze\CiffRenderer\Field\Parser\FixedTextParser.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
74
    }
75
76
    public function testGetTextMerged()
77
    {
78
        $this->assertSame('some text other text', $this->parser3->getText());
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Graze\CiffRenderer\Field\Parser\ParserInterface as the method getText() does only exist in the following implementations of said interface: Graze\CiffRenderer\Field\Parser\BarcodeParser, Graze\CiffRenderer\Field...rser\AbstractDateParser, Graze\CiffRenderer\Field...r\DateParser\DateParser, Graze\CiffRenderer\Field...Parser\OffsetDateParser, Graze\CiffRenderer\Field\Parser\FixedTextParser.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
79
    }
80
}
81