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