GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 14d611...55e41a )
by Mario
05:29
created

TemplateDataTest::testGetters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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;
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Netgen\Bundle\Inf...dle\Value\TemplateData>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
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';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'event' of type string is incompatible with the declared type object<Netgen\Bundle\Inf...t\InformationCollected> of property $event.

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..

Loading history...
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';
0 ignored issues
show
Documentation introduced by
The property test does not exist on object<Netgen\Bundle\Inf...dle\Value\TemplateData>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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.

Loading history...
91
    }
92
}
93