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.
Completed
Push — master ( bb96e0...68e81a )
by luca
02:33
created

FunctionalTestCase   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 7
dl 0
loc 81
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Test;
4
5
use Audiens\AdobeClient\Auth;
6
use Audiens\AdobeClient\Authentication\AdnxStrategy;
7
use Audiens\AdobeClient\Authentication\SandboxStrategy;
8
use Audiens\AdobeClient\Repository\TraitRepository;
9
use Doctrine\Common\Cache\FilesystemCache;
10
use Dotenv\Dotenv;
11
use GuzzleHttp\Client;
12
13
/**
14
 * Class FunctionalTestCase
15
 */
16
class FunctionalTestCase extends \PHPUnit_Framework_TestCase
17
{
18
19
    const REQUIRED_ENV = [
20
        'CLIENT_ID',
21
        'SECRET_KEY',
22
        'USERNAME',
23
        'PASSWORD',
24
    ];
25
26
    protected function setUp()
27
    {
28
29
        if (!$this->checkEnv()) {
30
            $this->markTestSkipped('cannotInitialize enviroment tests will be skipped');
31
        }
32
33
        parent::setUp();
34
    }
35
36
37
    /**
38
     * @return bool
39
     */
40
    private function checkEnv()
41
    {
42
43
        try {
44
            $dotenv = new Dotenv(__DIR__.'/../');
45
            $dotenv->load();
46
        } catch (\Exception $e) {
47
        }
48
49
        $env = true;
50
51
        foreach (self::REQUIRED_ENV as $requiredEnv) {
52
            if (!getenv($requiredEnv)) {
53
                $env = false;
54
            }
55
        }
56
57
        return $env;
58
    }
59
60
61
    /**
62
     * @param bool|true $cacheToken
63
     *
64
     * @return Auth
65
     */
66
    protected function getAuth($cacheToken = true)
67
    {
68
        $cache = $cacheToken ? new FilesystemCache('build') : null;
69
        $client = new Client();
70
71
        $authStrategy = new SandboxStrategy(new Client(), $cache);
72
73
74
        $authClient = new Auth(getenv('CLIENT_ID'), getenv('SECRET_KEY'), getenv('USERNAME'), getenv('PASSWORD'), $client, $authStrategy);
75
76
        return $authClient;
77
    }
78
79
    /**
80
     * @param bool|true $cacheToken
81
     *
82
     * @return TraitRepository
83
     */
84
    protected function getTraitRepository($cacheToken = true)
85
    {
86
87
        $authClient = $this->getAuth($cacheToken);
88
89
        $traitRepository = new TraitRepository($authClient);
90
        $traitRepository->setBaseUrl(TraitRepository::SANDBOX_BASE_URL);
91
        $traitRepository->setTrendUrl(TraitRepository::SANDBOX_TREND_URL);
92
93
        return $traitRepository;
94
    }
95
96
}
97