Completed
Push — master ( 804c7f...1d2ba7 )
by Dan Michael O.
01:59
created

RepresentationSpec::it_has_files()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace spec\Scriptotek\Alma\Bibs;
4
5
use Scriptotek\Alma\Bibs\Bib;
6
use Scriptotek\Alma\Bibs\File;
7
use Scriptotek\Alma\Bibs\Representations;
8
use Scriptotek\Alma\Bibs\Representation;
9
use Scriptotek\Alma\Client as AlmaClient;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
use spec\Scriptotek\Alma\SpecHelper;
13
14
class RepresentationSpec extends ObjectBehavior
15
{
16
    public function let(AlmaClient $client, Bib $bib)
17
    {
18
        $bib->mms_id = 'abc';
19
        $representation_id = '123';
20
        $this->beConstructedWith($client, $bib, $representation_id);
21
    }
22
23
    protected function expectRequest($client)
24
    {
25
        $client->getJSON('/bibs/abc/representations/123')
26
            ->shouldBeCalled()
27
            ->willReturn(SpecHelper::getDummyData('representation_response.json'));
28
    }
29
30
    public function it_is_initializable()
31
    {
32
        $this->shouldHaveType(Representation::class);
33
    }
34
35
    public function it_fetches_data_when_needed(AlmaClient $client)
36
    {
37
        $this->expectRequest($client);
38
39
        $this->label->shouldBe('High resolution TIFF images');
0 ignored issues
show
Documentation introduced by
The property label does not exist on object<spec\Scriptotek\A...ibs\RepresentationSpec>. 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...
40
    }
41
42 View Code Duplication
    public function it_has_files(AlmaClient $client)
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...
43
    {
44
        $client->getJSON('/bibs/abc/representations/123/files')
45
            ->shouldBeCalled()
46
            ->willReturn(SpecHelper::getDummyData('files_response.json'));
47
48
        $files = $this->files;
0 ignored issues
show
Documentation introduced by
The property files does not exist on object<spec\Scriptotek\A...ibs\RepresentationSpec>. 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...
49
        $files->shouldHaveCount(96);
50
51
        $files->rewind();
52
        $files->valid()->shouldBe(true);
53
        $files->current()->shouldHaveType(File::class);
54
    }
55
56
}
57