Repository navigation
Expand file tree
/
Copy pathcastor.php
More file actions
64 lines (52 loc) · 2.39 KB
/
Copy pathcastor.php
File metadata and controls
64 lines (52 loc) · 2.39 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
<?php
namespace ua_detector;
use Castor\Attribute\AsTask;
use function Castor\context;
use function Castor\run;
/**
* Commit of matomo-org/device-detector the test fixtures are taken from.
*
* Only the fixtures are: they say what a user agent means, which is the specification this
* library answers. How matomo goes about answering it is its own business, and its regexes are
* under a licence we do not want to carry.
*/
const MATOMO_REVISION = 'eaafe3725acea466d8ba39f38c2b56d4f5ffa2c0';
#[AsTask(description: 'Syncs the matomo device-detector test fixtures', name: 'sync', namespace: 'matomo')]
function sync()
{
$gitRepository = 'https://github.com/matomo-org/device-detector.git';
$tempDir = sys_get_temp_dir() . '/device-detector-' . uniqid();
run("git clone --quiet $gitRepository $tempDir");
run('git checkout --quiet ' . MATOMO_REVISION, context()->withWorkingDirectory($tempDir));
$fixturesDir = __DIR__ . '/tests/matomo-device-detector/fixtures';
run("rm -rf $fixturesDir");
run("mkdir -p $fixturesDir");
run("cp -r $tempDir/Tests/fixtures/* $fixturesDir");
// Matomo also tests each of its parsers on its own, and those fixtures name one thing each:
// a client, or an operating system, and nothing else. That is the shape of `src/devices`'s
// axis files, so they are worth having even though they say less than the ones above.
$axisDir = __DIR__ . '/tests/matomo-device-detector/axis';
run("rm -rf $axisDir");
run("mkdir -p $axisDir");
foreach (['Parser', 'Parser/Client', 'Parser/Device'] as $parser) {
$from = "$tempDir/Tests/$parser/fixtures";
if (is_dir($from)) {
$into = $axisDir . '/' . str_replace('/', '-', strtolower($parser));
run("mkdir -p $into");
run("cp -r $from/* $into");
}
}
run("rm -rf $tempDir");
}
/**
* Rewrites `src/warm.txt`, the user agents the crate ships to warm itself on.
*
* The heaviest rows of a dump of production traffic, which is not in this repository and has no
* bearing on the corpus: this is run when there is a fresher dump to run it on, and not with
* `matomo:sync`.
*/
#[AsTask(description: 'Rewrites the user agents the crate warms itself on', name: 'build', namespace: 'warm')]
function warm(string $dump)
{
run("cargo run --release --no-default-features --example warmlist -- $dump", context()->withWorkingDirectory(__DIR__));
}