Completed
Branch master (457766)
by
unknown
02:17
created

framework-test.php ➔ checkBuilds()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 8
rs 9.4285
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
Coding Style Compatibility introduced by
The function checkBuilds() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
44
    }
45
  }
46
}
47
48
$outputLog = '';
49
50
function runFrameworkTest($sdkTarget, $testFramework, $testFrameworkVersion)
51
{
52
53
    $framework = "{$testFramework} {$testFrameworkVersion}";
54
55
    global $outputLog;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

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

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
118
      echo "\nOutput log: \n\n";
119
      echo $outputLog . PHP_EOL;
120
      exit(-1);
0 ignored issues
show
Coding Style Compatibility introduced by
The function build() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
121
  }
122
123
  exit(0);
0 ignored issues
show
Coding Style Compatibility introduced by
The function build() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
124
}
125
126
build($sdkTarget, $builds);
127