GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WebTranslateItRepositoryTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 128
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
B testPullProject() 0 29 1
A testPullFile() 0 18 1
A getPullProjectResponseString() 0 4 1
A getProjectDTO() 0 9 1
A getPullFileResponseString() 0 4 1
1
<?php
2
3
namespace Ozean12\WebTranslateItBundle\Tests\Service;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Psr7\Response;
7
use JMS\Serializer\SerializerInterface;
8
use Ozean12\WebTranslateItBundle\DTO\ProjectDTO;
9
use Ozean12\WebTranslateItBundle\DTO\PullProjectResponseDTO;
10
use Ozean12\WebTranslateItBundle\Service\WebTranslateItRepository;
11
12
/**
13
 * Class WebTranslateItRepositoryTest
14
 */
15
class WebTranslateItRepositoryTest extends \PHPUnit_Framework_TestCase
16
{
17
    const READ_KEY = 'test_key';
18
    const BASE_URL = 'test_base_url/';
19
20
    const FILE_URL = 'base_url/{token}/files/...?file_path={name}';
21
    const FILE_NAME = 'test_messages.en.yml';
22
23
    const PROJECT_URL_NORMALIZED = 'test_base_url/projects/test_key.json';
24
    const FILE_URL_NORMALIZED = 'test_base_url/projects/test_key/files/...?file_path=test_messages.en.yml';
25
26
    /**
27
     * @var WebTranslateItRepository
28
     */
29
    private $repository;
30
31
    /**
32
     * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
33
     */
34
    private $serializer;
35
36
    /**
37
     * @var Client|\PHPUnit_Framework_MockObject_MockObject
38
     */
39
    private $client;
40
41
    /**
42
     * SetUp
43
     */
44
    public function setUp()
45
    {
46
        $this->serializer = $this->getMockBuilder(SerializerInterface::class)->getMock();
47
        $this->client = $this->getMockBuilder(Client::class)->setMethods(['get'])->getMock();
48
49
        $this->repository = new WebTranslateItRepository(
50
            self::READ_KEY,
51
            self::BASE_URL,
52
            $this->client,
53
            $this->serializer
54
        );
55
56
        parent::setUp();
57
    }
58
59
    /**
60
     * Test project pull
61
     */
62
    public function testPullProject()
63
    {
64
        $responseString = $this->getPullProjectResponseString();
65
        $response = new Response(200, [], $responseString);
66
67
        $this->client
68
            ->method('get')
69
            ->willReturn($response)
70
        ;
71
72
        $this->client
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in GuzzleHttp\Client.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
73
            ->expects($this->once())
74
            ->method('get')
75
            ->with(self::PROJECT_URL_NORMALIZED)
76
        ;
77
78
        $this->serializer
79
            ->method('deserialize')
80
            ->willReturn($this->getProjectDTO())
81
        ;
82
83
        $this->serializer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in JMS\Serializer\SerializerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
84
            ->expects($this->once())
85
            ->method('deserialize')
86
            ->with($responseString, PullProjectResponseDTO::class, WebTranslateItRepository::FORMAT_JSON)
87
        ;
88
89
        $this->assertEquals($this->getProjectDTO(), $this->repository->pullProject());
90
    }
91
92
    /**
93
     * Test pull file
94
     */
95
    public function testPullFile()
96
    {
97
        $responseString = $this->getPullFileResponseString();
98
        $response = new Response(200, [], $responseString);
99
100
        $this->client
101
            ->method('get')
102
            ->willReturn($response)
103
        ;
104
105
        $this->client
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in GuzzleHttp\Client.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
106
            ->expects($this->once())
107
            ->method('get')
108
            ->with(self::FILE_URL_NORMALIZED)
109
        ;
110
111
        $this->assertEquals($responseString, $this->repository->pullFile(self::FILE_NAME));
112
    }
113
114
    /**
115
     * @return string
116
     */
117
    private function getPullProjectResponseString()
118
    {
119
        return '{"project":{"id":"45"}}';
120
    }
121
122
    /**
123
     * @return ProjectDTO
124
     */
125
    private function getProjectDTO()
126
    {
127
        $projectDTO = new ProjectDTO();
128
129
        return $projectDTO
130
            ->setId(45)
131
            ->setName('test')
132
        ;
133
    }
134
135
    /**
136
     * @return string
137
     */
138
    private function getPullFileResponseString()
139
    {
140
        return 'hello: Hello';
141
    }
142
}
143