1
|
|
|
<?php |
2
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Tests for Developer Table model |
6
|
|
|
* |
7
|
|
|
* phpMyAdmin Error reporting server |
8
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
9
|
|
|
* |
10
|
|
|
* Licensed under The MIT License |
11
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
13
|
|
|
* |
14
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
15
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
16
|
|
|
* |
17
|
|
|
* @see https://www.phpmyadmin.net/ |
18
|
|
|
*/ |
19
|
|
|
namespace App\Test\TestCase\Model\Table; |
20
|
|
|
|
21
|
|
|
use App\Model\Table\DevelopersTable; |
22
|
|
|
use Cake\ORM\TableRegistry; |
23
|
|
|
use Cake\TestSuite\TestCase; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* App\Model\Table\DevelopersTable Test Case |
27
|
|
|
*/ |
28
|
|
|
class DevelopersTableTest extends TestCase |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Test subject |
33
|
|
|
* |
34
|
|
|
* @var \App\Model\Table\DevelopersTable |
35
|
|
|
*/ |
36
|
|
|
public $Developers; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Fixtures |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
public $fixtures = [ |
44
|
|
|
'app.Developers' |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* setUp method |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function setUp() |
53
|
|
|
{ |
54
|
|
|
parent::setUp(); |
55
|
|
|
$this->Developers = TableRegistry::get('Developers'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* tearDown method |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
public function tearDown() |
64
|
|
|
{ |
65
|
|
|
unset($this->Developers); |
66
|
|
|
|
67
|
|
|
parent::tearDown(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Test saveFromGithub method |
72
|
|
|
* |
73
|
|
|
* @return void |
74
|
|
|
*/ |
75
|
|
|
public function testSaveFromGithub() |
76
|
|
|
{ |
77
|
|
|
$i = 0; |
78
|
|
|
while (1) { |
79
|
|
|
try { |
80
|
|
|
$i++; |
81
|
|
|
$savedDeveloper = $this->Developers->get($i); |
|
|
|
|
82
|
|
|
} catch (\Cake\Datasource\Exception\RecordNotFoundException $e) { |
|
|
|
|
83
|
|
|
break; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$nextId = $i; |
88
|
|
|
|
89
|
|
|
$githubInfo = [ |
90
|
|
|
'login' => 'pma-bot', |
91
|
|
|
'id' => 1231231, |
92
|
|
|
'gravatar_id' => '', |
93
|
|
|
'url' => 'https://api.github.com/users/pma-bot', |
94
|
|
|
'name' => 'PMA BOT', |
95
|
|
|
'email' => '[email protected]', |
96
|
|
|
'has_commit_access' => 0, |
97
|
|
|
]; |
98
|
|
|
$developer = $this->Developers->newEntity(); |
99
|
|
|
$access_token = 'abc'; |
100
|
|
|
|
101
|
|
|
$this->Developers->saveFromGithub($githubInfo, $access_token, $developer); |
102
|
|
|
|
103
|
|
|
$savedDeveloper = $this->Developers->get($nextId); |
104
|
|
|
$this->assertNotEquals(null, $savedDeveloper); |
105
|
|
|
$this->assertEquals(1231231, $savedDeveloper->github_id); |
106
|
|
|
$this->assertEquals('PMA BOT', $savedDeveloper->full_name); |
107
|
|
|
$this->assertEquals('[email protected]', $savedDeveloper->email); |
108
|
|
|
$this->assertEquals(false, $savedDeveloper->has_commit_access); |
109
|
|
|
|
110
|
|
|
$updatedGithubInfo = [ |
111
|
|
|
'login' => 'pma-bot', |
112
|
|
|
'id' => 1231231, |
113
|
|
|
'gravatar_id' => '', |
114
|
|
|
'url' => 'https://api.github.com/users/pma-bot', |
115
|
|
|
'name' => 'PMA BOT', |
116
|
|
|
'email' => '[email protected]', |
117
|
|
|
'has_commit_access' => 1,// changed |
118
|
|
|
]; |
119
|
|
|
|
120
|
|
|
$this->Developers->saveFromGithub($updatedGithubInfo, $access_token, $developer); |
121
|
|
|
|
122
|
|
|
$savedDeveloper = $this->Developers->get($nextId); |
123
|
|
|
$this->assertNotEquals(null, $savedDeveloper); |
124
|
|
|
$this->assertEquals(1231231, $savedDeveloper->github_id); |
125
|
|
|
$this->assertEquals('PMA BOT', $savedDeveloper->full_name); |
126
|
|
|
$this->assertEquals('[email protected]', $savedDeveloper->email); |
127
|
|
|
$this->assertEquals(true, $savedDeveloper->has_commit_access); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.