Completed
Push — develop ( f3c189...e92436 )
by Alejandro
08:55
created

BodyOptionsTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testSetTemplateWithInvalidValueThrowsException() 0 4 1
A testDefaultValue() 0 7 1
A testSetCharset() 0 6 1
A testSetTemplate() 0 9 1
1
<?php
2
namespace AcMailerTest\Options;
3
4
use AcMailer\Options\BodyOptions;
5
use AcMailer\Options\TemplateOptions;
6
use AcMailer\Service\MailServiceInterface;
7
use PHPUnit_Framework_TestCase as TestCase;
8
9
class BodyOptionsTest extends TestCase
10
{
11
    /**
12
     * @var BodyOptions
13
     */
14
    private $bodyOptions;
15
16
    public function setUp()
17
    {
18
        $this->bodyOptions = new BodyOptions();
19
    }
20
21
    public function testDefaultValue()
22
    {
23
        $this->assertFalse($this->bodyOptions->getUseTemplate());
24
        $this->assertEquals('', $this->bodyOptions->getContent());
25
        $this->assertEquals(MailServiceInterface::DEFAULT_CHARSET, $this->bodyOptions->getCharset());
26
        $this->assertInstanceOf('AcMailer\Options\TemplateOptions', $this->bodyOptions->getTemplate());
27
    }
28
29
    public function testSetCharset()
30
    {
31
        $expected = 'CP-1252';
32
        $this->assertSame($this->bodyOptions, $this->bodyOptions->setCharset($expected));
33
        $this->assertEquals($expected, $this->bodyOptions->getCharset());
34
    }
35
36
    public function testSetTemplate()
37
    {
38
        $expected = new TemplateOptions();
39
        $this->assertSame($this->bodyOptions, $this->bodyOptions->setTemplate($expected));
40
        $this->assertSame($expected, $this->bodyOptions->getTemplate());
41
42
        $this->bodyOptions->setTemplate([]);
43
        $this->assertInstanceOf('AcMailer\Options\TemplateOptions', $this->bodyOptions->getTemplate());
44
    }
45
46
    /**
47
     * @expectedException \AcMailer\Exception\InvalidArgumentException
48
     */
49
    public function testSetTemplateWithInvalidValueThrowsException()
50
    {
51
        $this->bodyOptions->setTemplate('foobar');
0 ignored issues
show
Documentation introduced by
'foobar' is of type string, but the function expects a array|object<AcMailer\Options\TemplateOptions>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
    }
53
}
54