MessageFactorySpec::let()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 5
1
<?php
2
3
namespace spec\Knp\RadBundle\Mailer;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
8
class MessageFactorySpec extends ObjectBehavior
9
{
10
    /**
11
     * @param  Swift_Mailer               $mailer
12
     * @param  Twig_Environment           $twig
13
     * @param  Twig_ExistsLoaderInterface $loader
14
     * @param  Knp\RadBundle\AppBundle\BundleGuesser $bundleGuesser
15
     * @param  Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle
16
     */
17
    function let($mailer, $twig, $loader, $bundleGuesser, $bundle)
18
    {
19
        $twig->getLoader()->willReturn($loader);
20
21
        $this->beConstructedWith($mailer, $twig, $bundleGuesser);
22
23
        $bundleGuesser->getBundleForClass(Argument::any())->willReturn($bundle);
24
        $bundle->getName()->willReturn('App');
25
    }
26
27
    /**
28
     * @param  Swift_Mime_Message $message
29
     * @param  Twig_Template      $template
30
     * @param  stdClass           $subject
31
     * @param  stdClass           $body
32
     */
33
    function it_should_create_a_txt_message_if_only_txt_template_available(
0 ignored issues
show
Coding Style introduced by
Method name "MessageFactorySpec::it_should_create_a_txt_message_if_only_txt_template_available" is not in camel caps format
Loading history...
34
        $mailer, $twig, $loader, $message, $template, $subject, $body
0 ignored issues
show
Coding Style introduced by
Multi-line function declarations must define one parameter per line
Loading history...
35
    )
36
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
37
        $loader->exists('App:Mails:contact_message.txt.twig')->willReturn(true);
38
        $twig->loadTemplate('App:Mails:contact_message.txt.twig')->willReturn($template);
39
        $loader->exists('App:Mails:contact_message.html.twig')->willReturn(false);
40
41
        $template->renderBlock('subject', array('foo' => 'bar'))->willReturn($subject);
42
        $template->renderBlock('body', array('foo' => 'bar'))->willReturn($body);
43
44
        $mailer->createMessage()->willReturn($message);
45
        $message->setSubject($subject)->shouldBeCalled();
46
        $message->setBody($body, 'text/plain')->shouldBeCalled();
47
48
        $this->createMessage('App\Controller\Message', 'contact_message', array('foo' => 'bar'))->shouldReturn($message);
49
    }
50
51
    /**
52
     * @param  Swift_Mime_Message $message
53
     * @param  Twig_Template      $template
54
     * @param  stdClass           $subject
55
     * @param  stdClass           $body
56
     */
57
    function it_should_create_an_html_message_if_only_html_template_available(
0 ignored issues
show
Coding Style introduced by
Method name "MessageFactorySpec::it_should_create_an_html_message_if_only_html_template_available" is not in camel caps format
Loading history...
58
        $mailer, $twig, $loader, $message, $template, $subject, $body
0 ignored issues
show
Coding Style introduced by
Multi-line function declarations must define one parameter per line
Loading history...
59
    )
60
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
61
        $loader->exists('App:Mails:contact_message.txt.twig')->willReturn(false);
62
        $loader->exists('App:Mails:contact_message.html.twig')->willReturn(true);
63
        $twig->loadTemplate('App:Mails:contact_message.html.twig')->willReturn($template);
64
65
        $template->renderBlock('subject', array('foo' => 'bar'))->willReturn($subject);
66
        $template->renderBlock('body', array('foo' => 'bar'))->willReturn($body);
67
68
        $mailer->createMessage()->willReturn($message);
69
        $message->setSubject($subject)->shouldBeCalled();
70
        $message->setBody($body, 'text/html')->shouldBeCalled();
71
72
        $this->createMessage('App\Controller\Test', 'contact_message', array('foo' => 'bar'))->shouldReturn($message);
73
    }
74
75
    /**
76
     * @param  Swift_Message      $message
77
     * @param  Twig_Template      $template1
78
     * @param  Twig_Template      $template2
79
     * @param  stdClass           $subject1
80
     * @param  stdClass           $body1
81
     * @param  stdClass           $subject2
82
     * @param  stdClass           $body2
83
     */
84
    function it_should_create_a_multipart_message_if_both_html_and_txt_templates_available(
0 ignored issues
show
Coding Style introduced by
Method name "MessageFactorySpec::it_should_create_a_multipart_message_if_both_html_and_txt_templates_available" is not in camel caps format
Loading history...
85
        $mailer, $twig, $loader, $message, $template1, $template2, $subject1, $body1, $subject2, $body2
0 ignored issues
show
Coding Style introduced by
Multi-line function declarations must define one parameter per line
Loading history...
86
    )
87
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
88
        $loader->exists('App:Mails:contact_message.txt.twig')->willReturn(true);
89
        $twig->loadTemplate('App:Mails:contact_message.txt.twig')->willReturn($template1);
90
        $loader->exists('App:Mails:contact_message.html.twig')->willReturn(true);
91
        $twig->loadTemplate('App:Mails:contact_message.html.twig')->willReturn($template2);
92
93
        $template1->renderBlock('subject', array('foo' => 'bar'))->willReturn($subject1);
94
        $template1->renderBlock('body', array('foo' => 'bar'))->willReturn($body1);
95
96
        $template2->renderBlock('subject', array('foo' => 'bar'))->willReturn($subject2);
97
        $template2->renderBlock('body', array('foo' => 'bar'))->willReturn($body2);
98
99
        $mailer->createMessage()->willReturn($message);
100
        $message->setSubject($subject1)->shouldBeCalled();
101
        $message->setBody($body1, 'text/plain')->shouldBeCalled();
102
        $message->addPart($body2, 'text/html')->shouldBeCalled();
103
104
        $this->createMessage('App\Controller\Message', 'contact_message', array('foo' => 'bar'))->shouldReturn($message);
105
    }
106
107
    /**
108
     * @param  Swift_Mime_Message $message
109
     */
110
    function it_should_throw_exception_if_no_template_available(
0 ignored issues
show
Coding Style introduced by
Method name "MessageFactorySpec::it_should_throw_exception_if_no_template_available" is not in camel caps format
Loading history...
111
        $mailer, $twig, $loader, $message
0 ignored issues
show
Unused Code introduced by
The parameter $mailer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $twig is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $message is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Multi-line function declarations must define one parameter per line
Loading history...
112
    )
113
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
114
        $loader->exists('App:Mails:contact_message.txt.twig')->willReturn(false);
115
        $loader->exists('App:Mails:contact_message.html.twig')->willReturn(false);
116
117
        $this->shouldThrow('Twig_Error_Loader')->duringCreateMessage('App\Controller\Test', 'contact_message', array());
118
    }
119
120
    /**
121
     * @param  Swift_Mime_Message $message
122
     * @param  Twig_Template      $template1
123
     * @param  Twig_Template      $template2
124
     * @param  stdClass           $subject1
0 ignored issues
show
Bug introduced by
There is no parameter named $subject1. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
125
     * @param  stdClass           $body1
0 ignored issues
show
Bug introduced by
There is no parameter named $body1. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
126
     * @param  stdClass           $subject2
0 ignored issues
show
Bug introduced by
There is no parameter named $subject2. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
127
     * @param  stdClass           $body2
0 ignored issues
show
Bug introduced by
There is no parameter named $body2. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
128
     */
129
    function it_should_throw_exception_if_both_templates_provide_no_subject_or_body(
0 ignored issues
show
Coding Style introduced by
Method name "MessageFactorySpec::it_should_throw_exception_if_both_templates_provide_no_subject_or_body" is not in camel caps format
Loading history...
130
        $mailer, $twig, $loader, $message, $template1, $template2
0 ignored issues
show
Unused Code introduced by
The parameter $mailer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $message is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Multi-line function declarations must define one parameter per line
Loading history...
131
    )
132
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
133
        $loader->exists('App:Mails:contact_message.txt.twig')->willReturn(true);
134
        $twig->loadTemplate('App:Mails:contact_message.txt.twig')->willReturn($template1);
135
        $loader->exists('App:Mails:contact_message.html.twig')->willReturn(true);
136
        $twig->loadTemplate('App:Mails:contact_message.html.twig')->willReturn($template2);
137
138
        $template1->renderBlock('subject', array('foo' => 'bar'))->willReturn(null);
139
        $template1->renderBlock('body', array('foo' => 'bar'))->willReturn(null);
140
141
        $template2->renderBlock('subject', array('foo' => 'bar'))->willReturn(null);
142
        $template2->renderBlock('body', array('foo' => 'bar'))->willReturn(null);
143
144
        $this->shouldThrow('Twig_Error_Loader')->duringCreateMessage('App\Controller\Test', 'contact_message', array(
145
            'foo' => 'bar'
146
        ));
147
    }
148
}
149