-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationTest.php
More file actions
126 lines (100 loc) · 3.48 KB
/
ApplicationTest.php
File metadata and controls
126 lines (100 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
declare(strict_types=1);
namespace Keboola\GoogleAnalyticsExtractor;
use Generator;
use JsonException;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\Process\Process;
class ApplicationTest extends TestCase
{
private array $config;
private string $dataDir;
private string $configDir;
public function setUp(): void
{
$this->dataDir = '/tmp/data-test';
$this->configDir = __DIR__ . '/../../../tests/data';
$this->config = $this->getConfig();
$filesystem = new Filesystem();
$filesystem->remove($this->dataDir . '/out/tables');
$filesystem->mkdir($this->dataDir . '/out/tables');
}
private function getConfig(string $suffix = ''): array
{
$config = json_decode(
(string) file_get_contents($this->configDir . '/config' . $suffix . '.json'),
true,
);
$config['authorization']['oauth_api']['credentials'] = [
'appKey' => getenv('CLIENT_ID'),
'#appSecret' => getenv('CLIENT_SECRET'),
'#data' => json_encode([
'access_token' => getenv('ACCESS_TOKEN'),
'refresh_token' => getenv('REFRESH_TOKEN'),
]),
];
return $config;
}
public function testAppProfilesProperties(): void
{
$this->config = $this->getConfig('_empty');
$this->config['action'] = 'getProfilesProperties';
$result = json_decode($this->runProcess()->getOutput(), true);
Assert::assertArrayHasKey('profiles', $result);
Assert::assertArrayHasKey('properties', $result);
}
public function testAppRunProperties(): void
{
$this->config = $this->getConfig('_properties');
$this->runProcess();
$properties = $this->getOutputFiles('properties');
$propertiesManifests = $this->getManifestFiles('properties');
$users = $this->getOutputFiles('users');
$usersManifests = $this->getManifestFiles('users');
Assert::assertEquals(1, count($properties));
Assert::assertEquals(1, count($propertiesManifests));
Assert::assertEquals(1, count($users));
Assert::assertEquals(1, count($usersManifests));
}
private function runProcess(): Process
{
$fs = new Filesystem();
$fs->remove($this->dataDir);
$fs->mkdir($this->dataDir);
$fs->mkdir($this->dataDir . '/out/tables');
file_put_contents($this->dataDir . '/config.json', json_encode($this->config));
$process = new Process(['php', 'src/run.php']);
$process->setEnv([
'KBC_DATADIR' => $this->dataDir,
]);
$process->setTimeout(900);
$process->run();
return $process;
}
private function getOutputFiles(string $queryName): Finder
{
$finder = new Finder();
return $finder->files()
->in($this->dataDir . '/out/tables')
->name('/^' . $queryName . '.*\.csv$/i')
;
}
private function getManifestFiles(string $queryName): Finder
{
$finder = new Finder();
return $finder->files()
->in($this->dataDir . '/out/tables')
->name('/^' . $queryName . '.*\.csv.manifest$/i')
;
}
public function appRunDataProvider(): Generator
{
yield 'configRow' => [
'',
];
}
}