Completed
Push — master ( 7c757d...667317 )
by William
02:47
created

DevelopersTableTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A tearDown() 0 6 1
A testSaveFromGithub() 0 54 3
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);
0 ignored issues
show
Unused Code introduced by
$savedDeveloper is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
82
            } catch (\Cake\Datasource\Exception\RecordNotFoundException $e) {
0 ignored issues
show
Bug introduced by
The class Cake\Datasource\Exception\RecordNotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
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