1 | <?php |
||
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 |