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.

TransportTest::testChangingToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 64
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 64
rs 9.3956
cc 1
eloc 39
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace prgTW\BaseCRM\Tests\Transport;
4
5
use prgTW\BaseCRM\BaseCrm;
6
use prgTW\BaseCRM\Client\GuzzleClient;
7
use prgTW\BaseCRM\Resource\Resource;
8
use prgTW\BaseCRM\Tests\AbstractTest;
9
use prgTW\BaseCRM\Transport\Transport;
10
11
class TransportTest extends AbstractTest
12
{
13
	public function testChangingToken()
14
	{
15
		$accountResponse = '
16
			{
17
				"account": {
18
					"id": 123,
19
					"name": "myaccount",
20
					"timezone": "UTC",
21
					"currency_name": "US Dollar"
22
				}
23
			}
24
		';
25
26
		$client = \Mockery::mock(GuzzleClient::class);
27
		$client
28
			->shouldReceive('request')
29
			->once()
30
			->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), [
31
				'headers' => [
32
					Transport::TOKEN_PIPEJUMP_NAME     => '',
33
					Transport::TOKEN_FUTUERSIMPLE_NAME => '',
34
				],
35
			])
36
			->andReturn($this->getResponse(200, $accountResponse));
37
		$baseCrm = new BaseCrm('', $client);
38
39
		$baseCrm->getAccount()->get();
40
41
		$client
42
			->shouldReceive('request')
43
			->once()
44
			->with('GET', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), [
45
				'headers' => [
46
					Transport::TOKEN_PIPEJUMP_NAME     => 'astalavista',
47
					Transport::TOKEN_FUTUERSIMPLE_NAME => 'astalavista',
48
				],
49
			])
50
			->andReturn($this->getResponse(200, $accountResponse));
51
52
		$baseCrm->setToken('astalavista');
53
		$this->assertEquals('astalavista', $baseCrm->getToken());
54
		$account = $baseCrm->getAccount()->get();
55
56
		$client
57
			->shouldReceive('request')
58
			->once()
59
			->with('PUT', sprintf('%s/%s/account.json', Resource::ENDPOINT_SALES, Resource::PREFIX), [
60
				'headers' => [
61
					Transport::TOKEN_PIPEJUMP_NAME     => 'baby',
62
					Transport::TOKEN_FUTUERSIMPLE_NAME => 'baby',
63
				],
64
				'query' => [
65
					'account' => [
66
						'name' => 'new_name',
67
					],
68
				],
69
			])
70
			->andReturn($this->getResponse(200, $accountResponse));
71
72
		$account->name = 'new_name';
73
		$account->getTransport()->setToken('baby');
74
		$this->assertEquals('baby', $account->getTransport()->getToken());
75
		$account->save(['name']);
76
	}
77
}
78