Passed
Pull Request — master (#129)
by thomas
26:40 queued 15:56
created

framework-test.php ➔ runFrameworkTest()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 3
dl 0
loc 50
rs 8.7797
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 39 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
$sdkTarget = '@dev';
4
if ($argc > 1) {
5
    $sdkTarget = $argv[1];
6
}
7
8
$builds = [
9
    'codeigniter/framework' => [
10
        '3.1.*', '3.0.*',
11
    ],
12
    'slim/slim' => [
13
        '3.7.*', '3.6.*', '3.5.*', '3.4.*', '3.3.*', '3.2.*', '3.1.*', '3.0.*', '2.6.*',
14
        '2.5.*', '2.4.*', '2.3.*'
15
    ],
16
    'laravel/framework' => [
17
        '5.3.*', '5.2.*'
18
    ],
19
    'symfony/symfony' => [
20
        '3.2.*', '3.1.*', '3.0.*', '2.8.*'
21
    ],
22
    'silex/silex' => [
23
        '2.0.*', '1.3.*',
24
    ],
25
    'fuel/fuel' => [
26
        '1.8.*'
27
    ],
28
    'yiisoft/yii' => [
29
        '1.1.*'
30
    ],
31
    'yiisoft/yii2' => [
32
        '2.0.*'
33
    ],
34
    'cakephp/cakephp' => [
35
        '3.3.*', '3.2.*',
36
    ]
37
];
38
39
function checkBuilds (array $builds) {
40
  foreach ($builds as $framework => $listedVersions) {
41
    if (!is_array($listedVersions)) {
42
      error_log('MALFORMED FRAMEWORKS MATRIX');
43
      exit(-1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
44
    }
45
  }
46
}
47
48
$outputLog = '';
49
50
function runFrameworkTest($sdkTarget, $testFramework, $testFrameworkVersion)
51
{
52
53
    $framework = "{$testFramework} {$testFrameworkVersion}";
54
55
  $composer = <<<EOF
56
{
57
  "name": "integration tester",
58
  "repositories": [
59
    {
60
      "type": "vcs",
61
      "url": "../"
62
    }
63
  ],
64
  "require": {
65
    "$testFramework": "$testFrameworkVersion"
66
  }
67
}
68
EOF;
69
70
    mkdir('framework');
71
    chdir('./framework');
72
    file_put_contents('composer.json', $composer);
73
74
    $returnCode = 0;
75
    $output = [];
76
    $outputLog = null;
77
78
    exec('composer install 2>&1', $output, $returnCode);
79
    if ($returnCode !== 0) {
80
        $outputLog .= "###################### Failure: Installing framework {$framework} ###################### \n\n" . implode("\n", $output);
81
    } else {
82
        $returnCode = 0;
83
        $output = [];
84
        exec('composer require blocktrail/blocktrail-sdk ' . $sdkTarget . ' 2>&1', $output, $returnCode);
85
        if ($returnCode !== 0) {
86
            $outputLog .= "###################### Failure: Installing SDK with {$framework} ###################### \n\n" . implode("\n", $output);
87
        }
88
    }
89
90
    cleanup();
91
92
    $ok = $returnCode === 0;
93
    echo "Testing {$framework} with target {$sdkTarget}:  " . ($ok ? 'pass' : 'FAIL') . PHP_EOL;
94
    if (!$ok) {
95
        echo $outputLog . PHP_EOL;
96
    }
97
98
    return $ok;
99
}
100
101
function cleanup() {
102
    chdir('..');
103
    exec('rm -rf framework');
104
}
105
106
function build($sdkTarget, array $builds) {
107
  checkBuilds($builds);
108
  $results = [];
109
  foreach ($builds as $framework => $testVersions) {
110
    foreach ($testVersions as $testVersion) {
111
      $results[$framework . ":" . $testVersion] = runFrameworkTest($sdkTarget, $framework, $testVersion);
112
    }
113
  }
114
115
  $ok = true;
116
  foreach ($results as $result) {
117
    $ok = $ok && $result;
118
  }
119
120
  exit($ok ? 0 : -1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
121
}
122
123
build($sdkTarget, $builds);
124