Completed
Push — master ( cfe99f...9a5934 )
by Dan Michael O.
02:13
created

BibSpec::it_can_be_edited()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace spec\Scriptotek\Alma\Bibs;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Scriptotek\Alma\Bibs\Bib;
8
use Scriptotek\Alma\Bibs\Bibs;
9
use Scriptotek\Alma\Bibs\Holding;
10
use Scriptotek\Alma\Bibs\Holdings;
11
use Scriptotek\Alma\Client as AlmaClient;
12
use Scriptotek\Marc\Record;
13
use spec\Scriptotek\Alma\SpecHelper;
14
15
class BibSpec extends ObjectBehavior
16
{
17 View Code Duplication
    public function let(AlmaClient $almaClient)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
    {
19
        $mms_id = '999104760474702204';
20
        $this->beConstructedWith($almaClient, $mms_id);
21
22
        $almaClient->getXML(Argument::containingString('999104760474702204'), Argument::any())
23
            ->willReturn(SpecHelper::getDummyData('bib_response_iz.xml'));
24
    }
25
26
    public function it_is_initializable()
27
    {
28
        $this->shouldHaveType(Bib::class);
29
    }
30
31
    public function it_provides_bib_record_data(AlmaClient $almaClient)
0 ignored issues
show
Unused Code introduced by
The parameter $almaClient is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33
        $this->created_date->shouldBe('2015-11-05Z');
0 ignored issues
show
Documentation introduced by
The property created_date does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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
    }
35
36
    public function it_links_to_network_zone(AlmaClient $almaClient, AlmaClient $nz, Bibs $bibs, Bib $nz_bib)
37
    {
38
        $almaClient->nz = $nz;
0 ignored issues
show
Documentation Bug introduced by
It seems like $nz of type object<Scriptotek\Alma\Client> is incompatible with the declared type string of property $nz.

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...
39
        $nz->bibs = $bibs;
40
        $bibs->get('999104760474702201')
41
            ->shouldBeCalled()
42
            ->willReturn($nz_bib);
43
44
        $this->getNzRecord()->shouldHaveType(Bib::class);
45
    }
46
47
    public function it_has_holdings(AlmaClient $almaClient, AlmaClient $nz, Bibs $bibs)
0 ignored issues
show
Unused Code introduced by
The parameter $almaClient is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $nz is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $bibs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        $this->holdings->shouldHaveType(Holdings::class);
0 ignored issues
show
Documentation introduced by
The property holdings does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
50
    }
51
52
    public function it_allows_looking_up_a_single_holding(AlmaClient $almaClient, AlmaClient $nz, Bibs $bibs)
0 ignored issues
show
Unused Code introduced by
The parameter $almaClient is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $nz is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $bibs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54
        $this->getHolding('123')->shouldHaveType(Holding::class);
55
    }
56
57
    public function it_has_a_MARC_record(AlmaClient $almaClient)
0 ignored issues
show
Unused Code introduced by
The parameter $almaClient is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        $this->record->shouldHaveType(Record::class);
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
60
        $this->record->getField('245')->getSubfield('a')->getData()->shouldBe('Lonely hearts of the cosmos :');
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
61
    }
62
63
    public function it_can_be_edited(AlmaClient $almaClient)
64
    {
65
        $this->record->getField('245')->getSubfield('a')->setData('New title');
0 ignored issues
show
Documentation introduced by
The property record does not exist on object<spec\Scriptotek\Alma\Bibs\BibSpec>. 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...
66
67
        $almaClient->putXML('/bibs/999104760474702204', Argument::containingString('New title'))
68
            ->shouldBeCalled();
69
        $this->save();
70
    }
71
}
72