Completed
Pull Request — master (#171)
by Deven
03:17
created

DevelopersTableTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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) {
83
                break;
84
            }
85
        }
86
87
        $nextId = $i;
88
89
        $githubInfo = array(
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);
0 ignored issues
show
Bug introduced by
Accessing github_id on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
106
        $this->assertEquals('PMA BOT', $savedDeveloper->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
107
        $this->assertEquals('[email protected]', $savedDeveloper->email);
0 ignored issues
show
Bug introduced by
Accessing email on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
108
        $this->assertEquals(false, $savedDeveloper->has_commit_access);
0 ignored issues
show
Bug introduced by
Accessing has_commit_access on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
109
110
        $updatedGithubInfo = array(
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);
0 ignored issues
show
Bug introduced by
Accessing github_id on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
125
        $this->assertEquals('PMA BOT', $savedDeveloper->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
126
        $this->assertEquals('[email protected]', $savedDeveloper->email);
0 ignored issues
show
Bug introduced by
Accessing email on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
127
        $this->assertEquals(true, $savedDeveloper->has_commit_access);
0 ignored issues
show
Bug introduced by
Accessing has_commit_access on the interface Cake\Datasource\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
128
129
    }
130
}
131