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\Messaging\Tests\Form\FormFactory; |
12
|
|
|
|
13
|
|
|
use Miliooo\Messaging\Form\FormFactory\ReplyMessageFormFactory; |
14
|
|
|
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Description of ReplyMessageFormFactoryTest |
18
|
|
|
* |
19
|
|
|
* @author Michiel Boeckaert <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class ReplyMessageFormFactoryTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* The class under test |
25
|
|
|
* |
26
|
|
|
* @var ReplyMessageFormFactory |
27
|
|
|
*/ |
28
|
|
|
private $replyFormfactory; |
29
|
|
|
private $formFactory; |
30
|
|
|
private $formType; |
31
|
|
|
private $formName; |
32
|
|
|
private $modelClassName; |
33
|
|
|
|
34
|
|
|
public function setUp() |
35
|
|
|
{ |
36
|
|
|
$this->formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
37
|
|
|
$this->formType = $this->getMockBuilder('Symfony\Component\Form\AbstractType')->disableOriginalConstructor()->getMock(); |
38
|
|
|
$this->formName = 'message'; |
39
|
|
|
$this->modelClassName = '\Miliooo\Messaging\Form\FormModel\ReplyMessage'; |
40
|
|
|
$this->replyFormfactory = new ReplyMessageFormFactory($this->formFactory, $this->formType, $this->formName, $this->modelClassName); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testCreate() |
44
|
|
|
{ |
45
|
|
|
$sender = new ParticipantTestHelper('sender'); |
46
|
|
|
$thread = $this->getMock('Miliooo\Messaging\Model\ThreadInterface'); |
47
|
|
|
|
48
|
|
|
$replyFormFactoryMock = $this->getMockBuilder('Miliooo\Messaging\Form\FormFactory\ReplyMessageFormFactory') |
49
|
|
|
->setConstructorArgs(array($this->formFactory, $this->formType, $this->formName, $this->modelClassName)) |
50
|
|
|
->setMethods(array('createNewFormModel')) |
51
|
|
|
->getMock(); |
52
|
|
|
|
53
|
|
|
$formModel = $this->getMock('Miliooo\Messaging\Form\FormModel\ReplyMessageInterface'); |
54
|
|
|
|
55
|
|
|
$replyFormFactoryMock->expects($this->once()) |
56
|
|
|
->method('createNewFormModel') |
57
|
|
|
->will($this->returnValue($formModel)); |
58
|
|
|
|
59
|
|
|
$formModel->expects($this->once()) |
60
|
|
|
->method('setSender') |
61
|
|
|
->with($sender); |
62
|
|
|
$formModel->expects($this->once()) |
63
|
|
|
->method('setThread')->with($thread); |
64
|
|
|
|
65
|
|
|
$formMock = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
66
|
|
|
$this->formFactory->expects($this->once()) |
67
|
|
|
->method('createNamed') |
68
|
|
|
->with($this->formName, $this->formType, $formModel) |
69
|
|
|
->will($this->returnValue($formMock)); |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf('Symfony\Component\Form\Form', $replyFormFactoryMock->create($thread, $sender)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
//a test without mocking that method |
75
|
|
|
public function testCreateReturnsWhatFormFactoryReturns() |
76
|
|
|
{ |
77
|
|
|
$thread = $this->getMock('Miliooo\Messaging\Model\ThreadInterface'); |
78
|
|
|
$sender = new ParticipantTestHelper('sender'); |
79
|
|
|
$formMock = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
80
|
|
|
$this->formFactory->expects($this->once()) |
81
|
|
|
->method('createNamed') |
82
|
|
|
->with($this->anything()) |
83
|
|
|
->will($this->returnValue($formMock)); |
84
|
|
|
$this->assertInstanceOf('Symfony\Component\Form\Form', $this->replyFormfactory->create($thread, $sender)); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|