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\FormHandler; |
12
|
|
|
|
13
|
|
|
use Miliooo\Messaging\Form\FormHandler\NewReplyFormHandler; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Test file for Miliooo\Messaging\Form\FormHandler\NewReplyFormHandlerTest |
17
|
|
|
* |
18
|
|
|
* @author Michiel Boeckaert <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class NewReplyFormHandlerTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The class under test |
24
|
|
|
* |
25
|
|
|
* @var NewSingleThreadFormHandler |
26
|
|
|
*/ |
27
|
|
|
private $formHandler; |
28
|
|
|
private $request; |
29
|
|
|
private $processor; |
30
|
|
|
private $form; |
31
|
|
|
private $formModel; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->processor = $this->getMock('Miliooo\Messaging\Form\FormModelProcessor\NewReplyFormProcessorInterface'); |
36
|
|
|
$this->request = $this->getMock('Symfony\Component\HttpFoundation\Request'); |
37
|
|
|
$this->form = $this->getMockBuilder('Symfony\Component\Form\Form')->disableOriginalConstructor()->getMock(); |
38
|
|
|
$this->formHandler = new NewReplyFormHandler($this->request, $this->processor); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$this->formModel = $this->getMock('Miliooo\Messaging\Form\FormModel\ReplyMessageInterface'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @expectedException \InvalidArgumentException |
45
|
|
|
* @expectedExceptionMessage Form data needs to implement ReplyMessageInterface |
46
|
|
|
*/ |
47
|
|
|
public function testDoProcessThrowsExceptionOnInvalidData() |
48
|
|
|
{ |
49
|
|
|
$this->form->expects($this->once())->method('getData')->will($this->returnValue('foo')); |
50
|
|
|
$this->formHandler->doProcess($this->form); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testDoProcess() |
54
|
|
|
{ |
55
|
|
|
$this->expectsValidFormData(); |
56
|
|
|
$this->expectsUpdatingFormModelWithCreatedAt(); |
57
|
|
|
$this->expectsCallingProcessOnProcessor(); |
58
|
|
|
$this->formHandler->doProcess($this->form); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function expectsValidFormData() |
62
|
|
|
{ |
63
|
|
|
$this->form->expects($this->once())->method('getData')->will($this->returnValue($this->formModel)); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function expectsUpdatingFormModelWithCreatedAt() |
67
|
|
|
{ |
68
|
|
|
$this->formModel->expects($this->once())->method('setCreatedAt'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function expectsCallingProcessOnProcessor() |
72
|
|
|
{ |
73
|
|
|
$this->processor->expects($this->once())->method('process')->with($this->formModel); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..