|
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\NewThreadMessageFormFactory; |
|
14
|
|
|
use Miliooo\Messaging\TestHelpers\ParticipantTestHelper; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Test file for Miliooo\Messaging\Form\FormFactory\NewThreadMessageFormFactory |
|
18
|
|
|
* |
|
19
|
|
|
* @author Michiel Boeckaert <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class NewThreadMessageFormFactoryTest extends \PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* The class under test |
|
25
|
|
|
* |
|
26
|
|
|
* @var NewThreadMessageFormFactory |
|
27
|
|
|
*/ |
|
28
|
|
|
private $newThreadFormfactory; |
|
29
|
|
|
private $formFactory; |
|
30
|
|
|
private $formType; |
|
31
|
|
|
private $formName; |
|
32
|
|
|
private $modelClassName; |
|
33
|
|
|
private $transformer; |
|
34
|
|
|
|
|
35
|
|
|
public function setUp() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->formFactory = $this->getMock('Symfony\Component\Form\FormFactoryInterface'); |
|
38
|
|
|
$this->formType = $this->getMockBuilder('Symfony\Component\Form\AbstractType')->disableOriginalConstructor()->getMock(); |
|
39
|
|
|
$this->formName = 'message'; |
|
40
|
|
|
$this->modelClassName = '\Miliooo\Messaging\Form\FormModel\NewThreadSingleRecipient'; |
|
41
|
|
|
$this->transformer = $this->getMock('Symfony\Component\Form\DataTransformerInterface'); |
|
42
|
|
|
$this->newThreadFormfactory = new NewThreadMessageFormFactory( |
|
43
|
|
|
$this->formFactory, |
|
44
|
|
|
$this->formType, |
|
45
|
|
|
$this->formName, |
|
46
|
|
|
$this->modelClassName, |
|
47
|
|
|
$this->transformer |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function testCreateCallsFormFactoryWithRightArguments() |
|
52
|
|
|
{ |
|
53
|
|
|
$sender = new ParticipantTestHelper('sender'); |
|
54
|
|
|
|
|
55
|
|
|
$newThreadFormFactoryMock = $this->getMockBuilder('Miliooo\Messaging\Form\FormFactory\NewThreadMessageFormFactory') |
|
56
|
|
|
->setConstructorArgs( |
|
57
|
|
|
[ |
|
58
|
|
|
$this->formFactory, |
|
59
|
|
|
$this->formType, |
|
60
|
|
|
$this->formName, |
|
61
|
|
|
$this->modelClassName, |
|
62
|
|
|
$this->transformer |
|
63
|
|
|
] |
|
64
|
|
|
) |
|
65
|
|
|
->setMethods(array('createNewFormModel')) |
|
66
|
|
|
->getMock(); |
|
67
|
|
|
|
|
68
|
|
|
$formModel = $this->getMock('Miliooo\Messaging\Form\FormModel\NewThreadSingleRecipient'); |
|
69
|
|
|
|
|
70
|
|
|
$newThreadFormFactoryMock->expects($this->once()) |
|
71
|
|
|
->method('createNewFormModel') |
|
72
|
|
|
->will($this->returnValue($formModel)); |
|
73
|
|
|
|
|
74
|
|
|
$formModel->expects($this->once()) |
|
75
|
|
|
->method('setSender') |
|
76
|
|
|
->with($sender); |
|
77
|
|
|
|
|
78
|
|
|
$formMock = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
|
79
|
|
|
$this->formFactory->expects($this->once()) |
|
80
|
|
|
->method('createNamed') |
|
81
|
|
|
->with($this->formName, $this->formType, $formModel) |
|
82
|
|
|
->will($this->returnValue($formMock)); |
|
83
|
|
|
|
|
84
|
|
|
$this->assertInstanceOf('Symfony\Component\Form\Form', $newThreadFormFactoryMock->create($sender)); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function testCreateReturnsWhatFormFactoryReturns() |
|
88
|
|
|
{ |
|
89
|
|
|
$sender = new ParticipantTestHelper('sender'); |
|
90
|
|
|
$formMock = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
|
91
|
|
|
$this->formFactory->expects($this->once()) |
|
92
|
|
|
->method('createNamed') |
|
93
|
|
|
->with($this->anything()) |
|
94
|
|
|
->will($this->returnValue($formMock)); |
|
95
|
|
|
$this->assertInstanceOf('Symfony\Component\Form\Form', $this->newThreadFormfactory->create($sender)); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|