RowSpec::it_should_be_serializable_as_array()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace spec\Scriptotek\Alma\Analytics;
4
5
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement;
6
use PhpSpec\ObjectBehavior;
7
use Scriptotek\Alma\Analytics\Row;
8
9
class RowSpec extends ObjectBehavior
10
{
11
    public function let()
12
    {
13
        // We need to be able to handle missing data, so let's assume we have
14
        // a report with three columns, but that we for this row only got data
15
        // for two of the columns (data missing for Column2).
16
        $xml = QuiteSimpleXMLElement::make('<Row xmlns="urn:schemas-microsoft-com:xml-analysis:rowset">
17
                <Column0>0</Column0>
18
                <Column1>col1 content</Column1>
19
                <Column3>col3 content</Column3>
20
            </Row>');
21
        $xml->registerXPathNamespace('rowset', 'urn:schemas-microsoft-com:xml-analysis:rowset');
22
        $headers = ['mms_id', 'title', 'isbn'];
23
        $this->beConstructedWith($xml, $headers);
24
    }
25
26
    public function it_is_initializable()
27
    {
28
        $this->shouldHaveType(Row::class);
29
    }
30
31
    public function it_should_have_columns_accessible_by_name()
32
    {
33
        $this->mms_id->shouldBe('col1 content');
0 ignored issues
show
Documentation introduced by
The property mms_id does not exist on object<spec\Scriptotek\Alma\Analytics\RowSpec>. 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...
34
        $this->title->shouldBe(null);
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<spec\Scriptotek\Alma\Analytics\RowSpec>. 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...
35
        $this->isbn->shouldBe('col3 content');
0 ignored issues
show
Documentation introduced by
The property isbn does not exist on object<spec\Scriptotek\Alma\Analytics\RowSpec>. 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...
36
    }
37
38
    public function it_should_have_columns_accessible_by_array_key()
39
    {
40
        $this['mms_id']->shouldBe('col1 content');
41
        $this['title']->shouldBe(null);
42
        $this['isbn']->shouldBe('col3 content');
43
    }
44
45
    public function it_should_have_columns_accessible_by_array_index()
46
    {
47
        $this[0]->shouldBe('col1 content');
48
        $this[1]->shouldBe(null);
49
        $this[2]->shouldBe('col3 content');
50
    }
51
52
    public function it_should_be_traversable()
53
    {
54
        $this->shouldBeAnInstanceOf('Traversable');
55
    }
56
57
    public function it_should_be_countable()
58
    {
59
        $this->shouldHaveCount(3);
60
    }
61
62
    public function it_should_be_serializable_as_array()
63
    {
64
        $this->toArray()->shouldBeArray();
65
    }
66
}
67