SelfRecipientValidatorTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 60
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testSenderIsRecipient() 0 7 1
A testSenderIsNotRecipient() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the MilioooMessageBundle package.
5
 *
6
 * (c) Michiel boeckaert <[email protected]>
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Miliooo\MessagingBundle\Tests\Validator\Constraint;
12
13
use Miliooo\Messaging\User\ParticipantInterface;
14
use Miliooo\MessagingBundle\Validator\Constraint\SelfRecipient;
15
use Miliooo\MessagingBundle\Validator\Constraint\SelfRecipientValidator;
16
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper;
17
18
/**
19
 * Test file for SelfRecipientValidator
20
 *
21
 * @author Michiel Boeckaert <[email protected]>
22
 */
23
class SelfRecipientValidatorTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var SelfRecipient
27
     */
28
    private $constraint;
29
30
    /**
31
     * @var ParticipantInterface
32
     */
33
    private $sender;
34
35
    /**
36
     * @var ParticipantInterface
37
     */
38
    private $recipient;
39
40
    /**
41
     * @var SelfRecipientValidator
42
     */
43
    private $validator;
44
45
    /**
46
     * @var \PHPUnit_Framework_MockObject_MockObject
47
     */
48
    private $context;
49
50
    /**
51
     * @var \PHPUnit_Framework_MockObject_MockObject
52
     */
53
    private $participantProvider;
54
55
    public function setUp()
56
    {
57
        $this->sender = new ParticipantTestHelper('sender');
58
        $this->recipient = new ParticipantTestHelper('recipient');
59
        $this->constraint = new SelfRecipient();
60
61
        $this->context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface');
62
        $this->participantProvider = $this->getMock('Miliooo\Messaging\User\ParticipantProviderInterface');
63
        $this->validator = new SelfRecipientValidator($this->participantProvider);
64
        $this->validator->initialize($this->context);
65
    }
66
67
    public function testSenderIsRecipient()
68
    {
69
        $this->participantProvider->expects($this->once())->method('getAuthenticatedParticipant')
70
            ->will($this->returnValue($this->sender));
71
        $this->context->expects($this->once())->method('addViolation')->with($this->constraint->message);
72
        $this->validator->validate($this->sender, $this->constraint);
73
    }
74
75
    public function testSenderIsNotRecipient()
76
    {
77
        $this->participantProvider->expects($this->once())->method('getAuthenticatedParticipant')
78
            ->will($this->returnValue($this->sender));
79
        $this->context->expects($this->never())->method('addViolation');
80
        $this->validator->validate($this->recipient, $this->constraint);
81
    }
82
}
83