1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Netgen\Bundle\InformationCollectionBundle\Tests\Value; |
4
|
|
|
|
5
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Content; |
6
|
|
|
use Netgen\Bundle\EzFormsBundle\Form\DataWrapper; |
7
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Event\InformationCollected; |
8
|
|
|
use Netgen\Bundle\InformationCollectionBundle\Value\TemplateData; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
use Twig_Environment; |
11
|
|
|
use Twig_Loader_Array; |
12
|
|
|
use Twig_TemplateWrapper; |
13
|
|
|
|
14
|
|
|
class TemplateDataTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \Netgen\Bundle\InformationCollectionBundle\Value\TemplateData |
18
|
|
|
*/ |
19
|
|
|
protected $templateData; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \Netgen\Bundle\InformationCollectionBundle\Event\InformationCollected |
23
|
|
|
*/ |
24
|
|
|
protected $event; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \eZ\Publish\Core\Repository\Values\Content\Content |
28
|
|
|
*/ |
29
|
|
|
protected $content; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var \Twig_TemplateWrapper |
33
|
|
|
*/ |
34
|
|
|
protected $templateWrapper; |
35
|
|
|
|
36
|
|
|
public function setUp() |
37
|
|
|
{ |
38
|
|
|
$twig = new Twig_Environment( |
39
|
|
|
new Twig_Loader_Array( |
40
|
|
|
array( |
41
|
|
|
'index' => '{% block foo %}{% endblock %}', |
42
|
|
|
) |
43
|
|
|
) |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$this->event = new InformationCollected(new DataWrapper('test', null, null)); |
47
|
|
|
$this->content = new Content(); |
48
|
|
|
$this->templateWrapper = new Twig_TemplateWrapper($twig, $twig->loadTemplate('index')); |
49
|
|
|
|
50
|
|
|
$this->templateData = new TemplateData( |
51
|
|
|
array( |
52
|
|
|
'event' => $this->event, |
53
|
|
|
'content' => $this->content, |
54
|
|
|
'templateWrapper' => $this->templateWrapper, |
55
|
|
|
) |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGetters() |
60
|
|
|
{ |
61
|
|
|
$this->assertEquals($this->event, $this->templateData->event); |
62
|
|
|
$this->assertEquals($this->content, $this->templateData->content); |
63
|
|
|
$this->assertEquals($this->templateWrapper, $this->templateData->templateWrapper); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @expectedException \Netgen\Bundle\InformationCollectionBundle\Exception\PropertyNotFoundException |
68
|
|
|
* @expectedExceptionMessage Property 'test' not found on class 'Netgen\Bundle\InformationCollectionBundle\Value\TemplateData' |
69
|
|
|
*/ |
70
|
|
|
public function testExceptionShouldBeThrownInCaseOfAccessingNonExistingProperty() |
71
|
|
|
{ |
72
|
|
|
$this->templateData->test; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @expectedException \Netgen\Bundle\InformationCollectionBundle\Exception\PropertyReadOnlyException |
77
|
|
|
* @expectedExceptionMessage Property 'event' is readonly on class 'Netgen\Bundle\InformationCollectionBundle\Value\TemplateData' |
78
|
|
|
*/ |
79
|
|
|
public function testExceptionShouldBeThrownInCaseOfSettingPropertyValue() |
80
|
|
|
{ |
81
|
|
|
$this->templateData->event = 'event'; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @expectedException \Netgen\Bundle\InformationCollectionBundle\Exception\PropertyNotFoundException |
86
|
|
|
* @expectedExceptionMessage Property 'test' not found on class 'Netgen\Bundle\InformationCollectionBundle\Value\TemplateData' |
87
|
|
|
*/ |
88
|
|
|
public function testExceptionShouldBeThrownInCaseOfSettingPropertyValueOfNonExistingProperty() |
89
|
|
|
{ |
90
|
|
|
$this->templateData->test = 'test'; |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.