AlertSpec   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 18
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 113
rs 10

18 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_not_initializable() 0 5 1
A it_can_be_created() 0 5 1
A it_throws_exception_when_created_without_type() 0 5 1
A it_throws_exception_when_created_without_content() 0 5 1
A it_can_return_type() 0 5 1
A it_can_return_type_variable() 0 5 1
A it_can_return_content() 0 5 1
A it_can_return_content_variable() 0 5 1
A it_throws_exception_when_requesting_undefined_variable() 0 5 1
A it_can_be_created_as_a_type_error() 0 5 1
A it_can_be_created_as_a_type_info() 0 5 1
A it_can_be_created_as_a_type_warning() 0 5 1
A it_can_be_created_as_a_type_success() 0 5 1
A it_can_be_created_as_a_type_none() 0 5 1
A it_throws_exception_when_displaying_with_invalid_view_path() 0 6 1
A it_throws_exception_when_displaying_with_invalid_view() 0 6 1
A it_can_be_displayed() 0 5 1
A it_can_be_displayed_with_bootstrap_view() 0 6 1
1
<?php
2
3
namespace spec\Cornford\Alerter;
4
5
use Cornford\Alerter\Alert;
6
use Cornford\Alerter\AlertDisplay;
7
use PhpSpec\ObjectBehavior;
8
9
class AlertSpec extends ObjectBehavior
10
{
11
	function it_is_not_initializable()
12
	{
13
		$this->shouldHaveType('Cornford\Alerter\Alert');
14
		$this->shouldThrow('\PhpSpec\Exception\Example\ErrorException');
15
	}
16
17
	function it_can_be_created()
18
	{
19
		$this->beConstructedThrough('create', [null, null]);
20
		$this->shouldHaveType('Cornford\Alerter\Alert');
21
	}
22
23
	function it_throws_exception_when_created_without_type()
24
	{
25
		$this->beConstructedThrough('create', [Alert::TYPE_NONE, 'None']);
26
		$this->shouldThrow('Cornford\Alerter\Exceptions\AlertTypeException')->during('create', [null, 'Message']);
27
	}
28
29
	function it_throws_exception_when_created_without_content()
30
	{
31
		$this->beConstructedThrough('create', [Alert::TYPE_NONE, 'None']);
32
		$this->shouldThrow('Cornford\Alerter\Exceptions\AlertContentException')->during('create', [Alert::TYPE_ERROR, null]);
33
	}
34
35
	function it_can_return_type()
36
	{
37
		$this->beConstructedThrough('create', [Alert::TYPE_INFO, 'Info message']);
38
		$this->getType()->shouldEqual(Alert::TYPE_INFO);
39
	}
40
41
	function it_can_return_type_variable()
42
	{
43
		$this->beConstructedThrough('create', [Alert::TYPE_INFO, 'Info message']);
44
		$this->type->shouldEqual(Alert::TYPE_INFO);
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<spec\Cornford\Alerter\AlertSpec>. 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...
45
	}
46
47
	function it_can_return_content()
48
	{
49
		$this->beConstructedThrough('create', [Alert::TYPE_ERROR, 'Error message']);
50
		$this->getContent()->shouldEqual('Error message');
51
	}
52
53
	function it_can_return_content_variable()
54
	{
55
		$this->beConstructedThrough('create', [Alert::TYPE_ERROR, 'Error message']);
56
		$this->content->shouldEqual('Error message');
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<spec\Cornford\Alerter\AlertSpec>. 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...
57
	}
58
59
	function it_throws_exception_when_requesting_undefined_variable()
60
	{
61
		$this->beConstructedThrough('create', [Alert::TYPE_WARNING, 'Waring message']);
62
		$this->shouldThrow('\Cornford\Alerter\Exceptions\AlertVariableException')->during('__get', ['undefined']);
63
	}
64
65
	function it_can_be_created_as_a_type_error()
66
	{
67
		$this->beConstructedThrough('error', ['Error message']);
68
		$this->content->shouldEqual('Error message');
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<spec\Cornford\Alerter\AlertSpec>. 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...
69
	}
70
71
	function it_can_be_created_as_a_type_info()
72
	{
73
		$this->beConstructedThrough('info', ['Info message']);
74
		$this->content->shouldEqual('Info message');
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<spec\Cornford\Alerter\AlertSpec>. 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...
75
	}
76
77
	function it_can_be_created_as_a_type_warning()
78
	{
79
		$this->beConstructedThrough('warning', ['Warning message']);
80
		$this->content->shouldEqual('Warning message');
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<spec\Cornford\Alerter\AlertSpec>. 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...
81
	}
82
83
	function it_can_be_created_as_a_type_success()
84
	{
85
		$this->beConstructedThrough('success', ['Success message']);
86
		$this->content->shouldEqual('Success message');
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<spec\Cornford\Alerter\AlertSpec>. 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...
87
	}
88
89
	function it_can_be_created_as_a_type_none()
90
	{
91
		$this->beConstructedThrough('none', ['Message']);
92
		$this->content->shouldEqual('Message');
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<spec\Cornford\Alerter\AlertSpec>. 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...
93
	}
94
95
	function it_throws_exception_when_displaying_with_invalid_view_path()
96
	{
97
		$this->beConstructedThrough('success', ['Success message']);
98
		$this->useViewPath('none directory');
99
		$this->shouldThrow('\Cornford\Alerter\Exceptions\AlertDisplayViewPathException')->during('display', []);
100
	}
101
102
	function it_throws_exception_when_displaying_with_invalid_view()
103
	{
104
		$this->beConstructedThrough('success', ['Success message']);
105
		$this->useView('none view');
106
		$this->shouldThrow('\Cornford\Alerter\Exceptions\AlertDisplayViewException')->during('display', []);
107
	}
108
109
	function it_can_be_displayed()
110
	{
111
		$this->beConstructedThrough('success', ['Success message']);
112
		$this->display()->shouldEqual('<p class="alert alert-success">Success message</p>');
113
	}
114
115
	function it_can_be_displayed_with_bootstrap_view()
116
	{
117
		$this->beConstructedThrough('info', ['Info message']);
118
		$this->useView(AlertDisplay::VIEW_BOOTSTRAP);
119
		$this->display()->shouldEqual('<div class="alert alert-info">Info message</div>');
120
	}
121
}
122