Completed
Pull Request — master (#37)
by Vitaliy
06:49 queued 04:18
created

AbstractAPITest::setUpBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Xsolla\SDK\Tests\Integration\API;
4
5
use Xsolla\SDK\API\XsollaClient;
6
use Xsolla\SDK\Tests\Helper\XsollaClientHelper;
7
8
abstract class AbstractAPITest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @var XsollaClient
12
     */
13
    protected static $xsollaClient;
14
15
    /**
16
     * @var int
17
     */
18
    protected static $projectId;
19
20
    /**
21
     * @var int
22
     */
23
    protected static $merchantId;
24
25
    /**
26
     * @var string
27
     */
28
    protected static $userId;
29
30
    public static function setUpBeforeClass()
0 ignored issues
show
Coding Style introduced by
setUpBeforeClass uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
31
    {
32
        static::$projectId = (int) $_SERVER['PROJECT_ID'];
33
        static::$merchantId = (int) $_SERVER['MERCHANT_ID'];
34
        static::$userId = $_SERVER['USER_ID'];
35
        static::$xsollaClient = XsollaClientHelper::getXsollaClient(static::$merchantId, $_SERVER['API_KEY']);
36
    }
37
}
38