SdkClient::testGetRepository()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 31
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 44
rs 9.424
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mapado\RestClientSdk\Tests\Units;
6
7
use atoum;
8
use Mapado\RestClientSdk\Mapping as RestMapping;
9
use Mapado\RestClientSdk\Mapping\ClassMetadata;
10
use Mapado\RestClientSdk\Model\Serializer;
11
use Mapado\RestClientSdk\UnitOfWork;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Mapado\RestClientSdk\Tests\Units\UnitOfWork. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
13
/**
14
 * SdkClient
15
 *
16
 * @uses \atoum
17
 *
18
 * @author Julien Deniau <[email protected]>
19
 */
20
class SdkClient extends atoum
21
{
22
    /**
23
     * testGetRepository
24
     */
25
    public function testGetRepository()
26
    {
27
        $this->mockGenerator->orphanize('__construct');
28
        $this->mockGenerator->shuntParentClassCalls();
29
        $restClient = new \mock\Mapado\RestClientSdk\RestClient();
0 ignored issues
show
Bug introduced by
The type mock\Mapado\RestClientSdk\RestClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
        $this->mockGenerator->unshuntParentClassCalls();
31
32
        $mapping = new RestMapping();
33
        $mapping->setMapping([
34
            new ClassMetadata(
35
                'orders',
36
                'Mapado\RestClientSdk\Tests\Model\JsonLd\Model',
37
                'Mapado\RestClientSdk\Tests\Model\JsonLd\ModelRepository'
38
            ),
39
        ]);
40
41
        $unitOfWork = new UnitOfWork($mapping);
42
        $serializer = new Serializer($mapping, $unitOfWork);
43
44
        $this
45
            ->given($testedInstance = $this->newTestedInstance($restClient, $mapping, $unitOfWork, $serializer))
46
            ->then
47
                ->object($testedInstance->getRestClient())
48
                    ->isIdenticalTo($restClient)
49
50
            ->then
51
                ->object($testedInstance->getMapping())
52
                    ->isIdenticalTo($mapping)
53
54
            ->then
55
                ->object($testedInstance->getSerializer())
56
                    ->isIdenticalTo($serializer)
57
58
            ->then
59
                ->object($testedInstance->getRepository('Mapado\RestClientSdk\Tests\Model\JsonLd\Model'))
60
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\ModelRepository')
61
62
                ->object($testedInstance->getRepository('orders'))
63
                    ->isInstanceOf('Mapado\RestClientSdk\Tests\Model\JsonLd\ModelRepository')
64
65
                ->exception(function () use ($testedInstance) {
66
                    $testedInstance->getRepository('foo');
67
                })
68
                    ->isInstanceOf('Mapado\RestClientSdk\Exception\MappingException')
69
        ;
70
    }
71
}
72