GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

testParseXmlWithAllValidValuesNotLocalized()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.4109
c 0
b 0
f 0
cc 1
eloc 26
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
4
namespace Hautzi\SystemMailBundle\Tests\SystemMailer\MailDefinition;
5
6
use Hautzi\SystemMailBundle\SystemMailer\MailDefinition\MailDefinitionParserXml;
7
use Hautzi\SystemMailBundle\SystemMailer\XML\XsdValidator;
8
9
class MailDefinitionParserXmlTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var MailDefinitionParserXml
13
     */
14
    protected $fixture;
15
16
    /**
17
     * @var XsdValidator
18
     */
19
    protected $xsdValidator;
20
21
    protected function setUp()
22
    {
23
        $this->xsdValidator = $this->prophesize(XsdValidator::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(\Hautz...ML\XsdValidator::class) of type object<Prophecy\Prophecy\ObjectProphecy> is incompatible with the declared type object<Hautzi\SystemMail...ailer\XML\XsdValidator> of property $xsdValidator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
24
25
        $this->fixture = new MailDefinitionParserXml($this->xsdValidator->reveal(), 'pathtoxsd.xsd');
26
    }
27
28
    public function testParseXmlWithAllValidValuesNotLocalized()
29
    {
30
        $xml = <<<XML
31
<email>
32
    <from name="from_name">[email protected]</from>
33
    <replyTo>[email protected]</replyTo>
34
    <to name="to_name1">[email protected]</to>
35
    <to name="to_name2">[email protected]</to>
36
    <to>[email protected]</to>
37
    <cc name="cc_name1">[email protected]</cc>
38
    <cc name="cc_name2">[email protected]</cc>
39
    <cc>[email protected]</cc>
40
    <bcc name="bcc_name1">[email protected]</bcc>
41
    <bcc name="bcc_name2">[email protected]</bcc>
42
    <bcc>[email protected]</bcc>
43
    <subject>_subject</subject>
44
    <messageText>_text_message</messageText>
45
    <messageHtml><![CDATA[<p>_html_message</p>]]></messageHtml>
46
</email>
47
XML;
48
        $this->xsdValidator->validate($xml, 'pathtoxsd.xsd')->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->xsdValidator->val...($xml, 'pathtoxsd.xsd') (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
49
50
        $parsedMessage = $this->fixture->parseMailDefinition($xml);
51
52
        // from
53
        $this->assertEquals(['[email protected]' => 'from_name'], $parsedMessage->getFrom());
54
        // reply-to
55
        $this->assertEquals('[email protected]', $parsedMessage->getReplyTo());
56
        // to
57
        $this->assertEquals([
58
            '[email protected]' => 'to_name1',
59
            '[email protected]' => 'to_name2',
60
            '[email protected]',
61
        ], $parsedMessage->getTo());
62
        // cc
63
        $this->assertEquals([
64
            '[email protected]' => 'cc_name1',
65
            '[email protected]' => 'cc_name2',
66
            '[email protected]',
67
        ], $parsedMessage->getCc());
68
        // bcc
69
        $this->assertEquals([
70
            '[email protected]' => 'bcc_name1',
71
            '[email protected]' => 'bcc_name2',
72
            '[email protected]',
73
        ], $parsedMessage->getBcc());
74
75
        $this->assertEquals('_subject', $parsedMessage->getSubject());
76
        $this->assertEquals('_text_message', $parsedMessage->getMessageText());
77
        $this->assertEquals('<p>_html_message</p>', $parsedMessage->getMessageHtml());
78
    }
79
80
    /**
81
     * @dataProvider localizedSubjectMessageTextProvider()
82
     *
83
     * @param $_locale
84
     * @param $_subject
85
     * @param $_messageText
86
     * @param $_messageHtml
87
     */
88
    public function testParseXmlLocalizedFields($_locale, $_subject, $_messageText, $_messageHtml)
89
    {
90
        $xml = <<<XML
91
<email>
92
    <from name="from_name">[email protected]</from>
93
    <to name="to_name1">[email protected]</to>
94
    <subject locale="de">_subject_de</subject>
95
    <subject locale="en">_subject_en</subject>
96
    <messageText locale="de">_text_message_de</messageText>
97
    <messageText locale="en">_text_message_en</messageText>
98
    <messageHtml locale="de"><![CDATA[<p>_html_message_de</p>]]></messageHtml>
99
    <messageHtml locale="en"><![CDATA[<p>_html_message_en</p>]]></messageHtml>
100
</email>
101
XML;
102
        $this->xsdValidator->validate($xml, 'pathtoxsd.xsd')->shouldBeCalled();
0 ignored issues
show
Bug introduced by
The method shouldBeCalled cannot be called on $this->xsdValidator->val...($xml, 'pathtoxsd.xsd') (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
103
104
        $parsedMessage = $this->fixture->parseMailDefinition($xml, $_locale);
105
106
        $this->assertEquals($_subject, $parsedMessage->getSubject());
107
        $this->assertEquals($_messageText, $parsedMessage->getMessageText());
108
        $this->assertEquals($_messageHtml, $parsedMessage->getMessageHtml());
109
    }
110
111
    public function localizedSubjectMessageTextProvider()
112
    {
113
        return [
114
            ['de', '_subject_de', '_text_message_de', '<p>_html_message_de</p>'],
115
            ['en', '_subject_en', '_text_message_en', '<p>_html_message_en</p>'],
116
        ];
117
    }
118
}
119