Completed
Push — 3.8.x ( 75343b...2cd6fd )
by Tim
04:11
created

RoboFile::runTestsAcceptance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * RoboFile.php
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-cli-simple
18
 * @link      http://www.techdivision.com
19
 */
20
21
use Lurker\Event\FilesystemEvent;
22
use Symfony\Component\Finder\Finder;
23
24
/**
25
 * Defines the available build tasks.
26
 *
27
 * @author    Tim Wagner <[email protected]>
28
 * @copyright 2016 TechDivision GmbH <[email protected]>
29
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
30
 * @link      https://github.com/techdivision/import-cli-simple
31
 * @link      http://www.techdivision.com
32
 */
33
class RoboFile extends \Robo\Tasks
34
{
35
36
    /**
37
     * The build properties.
38
     *
39
     * @var array
40
     */
41
    protected $properties = array(
42
        'base.dir' => __DIR__,
43
        'etc.dir' => __DIR__ . '/etc',
44
        'dist.dir' => __DIR__ . '/dist',
45
        'vendor.dir' => __DIR__ . '/vendor',
46
        'target.dir' => __DIR__ . '/target',
47
        'symfony.dir' => __DIR__ . '/symfony',
48
        'webapp.name' => 'import-cli-simple',
49
        'webapp.version' => '3.8.0'
50
    );
51
52
    /**
53
     * Run's the composer install command.
54
     *
55
     * @return void
56
     */
57
    public function composerInstall()
58
    {
59
        // optimize autoloader with custom path
60
        $this->taskComposerInstall()
0 ignored issues
show
Bug introduced by
The method preferDist does only exist in Robo\Task\Composer\Install, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
61
             ->preferDist()
62
             ->optimizeAutoloader()
63
             ->run();
64
    }
65
66
    /**
67
     * Run's the composer update command.
68
     *
69
     * @return void
70
     */
71
    public function composerUpdate()
72
    {
73
        // optimize autoloader with custom path
74
        $this->taskComposerUpdate()
0 ignored issues
show
Bug introduced by
The method preferDist does only exist in Robo\Task\Composer\Update, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
75
             ->preferDist()
76
             ->optimizeAutoloader()
77
             ->run();
78
    }
79
80
    /**
81
     * Clean up the environment for a new build.
82
     *
83
     * @return void
84
     */
85
    public function clean()
86
    {
87
        $this->taskDeleteDir($this->properties['target.dir'])->run();
88
    }
89
90
    /**
91
     * Prepare's the environment for a new build.
92
     *
93
     * @return void
94
     */
95
    public function prepare()
96
    {
97
        $this->taskFileSystemStack()
0 ignored issues
show
Bug introduced by
The method mkdir does only exist in Robo\Task\Filesystem\FilesystemStack, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
98
             ->mkdir($this->properties['dist.dir'])
99
             ->mkdir($this->properties['target.dir'])
100
             ->mkdir(sprintf('%s/reports', $this->properties['target.dir']))
101
             ->run();
102
    }
103
104
    /**
105
     * Creates the a PHAR archive from the sources.
106
     *
107
     * @return void
108
     */
109
    public function createPhar()
110
    {
111
112
        // run the build process
113
        $this->build();
114
115
        // prepare the PHAR archive name
116
        $archiveName = sprintf(
117
            '%s/%s.phar',
118
            $this->properties['target.dir'],
119
            $this->properties['webapp.name']
120
        );
121
122
        // prepare the target directory
123
        $targetDir = $this->properties['target.dir'] . DIRECTORY_SEPARATOR . $this->properties['webapp.version'];
124
125
        // copy the composer.json file
126
        $this->taskFilesystemStack()
0 ignored issues
show
Bug introduced by
The method copy does only exist in Robo\Task\Filesystem\FilesystemStack, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
127
             ->copy(
128
                  __DIR__ . DIRECTORY_SEPARATOR . 'composer.json',
129
                  $targetDir. DIRECTORY_SEPARATOR. 'composer.json'
130
             )->run();
131
132
          // copy the .semver file
133
          $this->taskFilesystemStack()
134
               ->copy(
135
                   __DIR__ . DIRECTORY_SEPARATOR . '.semver',
136
                   $targetDir. DIRECTORY_SEPARATOR. '.semver'
137
               )->run();
138
139
          // copy the bootstrap.php file
140
          $this->taskFilesystemStack()
141
               ->copy(
142
                  __DIR__ . DIRECTORY_SEPARATOR . 'bootstrap.php',
143
                  $targetDir. DIRECTORY_SEPARATOR. 'bootstrap.php'
144
               )->run();
145
146
        // install the composer dependencies
147
        $this->taskComposerInstall()
0 ignored issues
show
Bug introduced by
The method dir does only exist in Robo\Task\Composer\Install, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
148
            ->dir($targetDir)
149
            ->noDev()
150
            ->optimizeAutoloader()
151
            ->run();
152
153
        // prepare the task
154
        $pharTask = $this->taskPackPhar($archiveName)
0 ignored issues
show
Bug introduced by
The method compress does only exist in Robo\Task\Development\PackPhar, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
155
            ->compress()
156
            ->stub('stub.php');
157
158
        // load a list with all the source files from the vendor directory
159
        $finder = Finder::create()->files()
160
            ->name('*.php')
161
            ->name('*.json')
162
            ->name('.semver')
163
            ->name('services.xml')
164
            ->name('services-1.0.xsd')
165
            ->in($targetDir)
166
            ->ignoreDotFiles(false);
167
168
        // iterate over the source files of the vendor directory and add them to the PHAR archive
169
        foreach ($finder as $file) {
170
            $pharTask->addFile($file->getRelativePathname(), $file->getRealPath());
171
        }
172
173
        // create the PHAR archive
174
        $pharTask->run();
175
176
        // verify PHAR archive is packed correctly
177
        $this->_exec(sprintf('php %s', $archiveName));
178
179
        // prepare the PHAR archive distribution name
180
        $distArchiveName = sprintf('%s/%s.phar', $this->properties['dist.dir'], $this->properties['webapp.name']);
181
182
        // clean up the dist directory
183
        $this->taskCleanDir($this->properties['dist.dir'])->run();
184
185
        // copy the latest PHAR archive to the dist directory
186
        $this->taskFilesystemStack()->copy($archiveName, $distArchiveName)->run();
187
    }
188
189
    /**
190
     * Run's the PHPUnit testsuite.
191
     *
192
     * @return void
193
     */
194
    public function runTestsUnit()
195
    {
196
197
        // run PHPUnit
198
        $this->taskPHPUnit(sprintf('%s/bin/phpunit --testsuite "techdivision/import-cli-simple PHPUnit testsuite"', $this->properties['vendor.dir']))
0 ignored issues
show
Bug introduced by
The method configFile does only exist in Robo\Task\Testing\PHPUnit, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
199
             ->configFile('phpunit.xml')
200
             ->run();
201
    }
202
203
    /**
204
     * Run's the integration testsuite.
205
     *
206
     * This task uses the Magento 2 docker image generator from https://github.com/techdivision/magento2-docker-imgen. To execute
207
     * this task, it is necessary that you've setup a running container with the domain name, passed as argument.
208
     *
209
     * @return void
210
     */
211
    public function runTestsIntegration($containerName, $domainName)
212
    {
213
214
        // prepare the filesystem
215
        $this->prepare();
216
217
        // initialize the variables to query whether or not the docker container has been started successfully
218
        $counter = 0;
219
        $magentoNotAvailable = true;
220
221
        do {
222
            // reset the result of the CURL request
223
            $res = null;
224
225
            // query whether or not the image already has been loaded
226
            exec(
227
                str_replace(
228
                    array('{domain-name}'),
229
                    array($domainName),
230
                    'curl --resolve {domain-name}:80:127.0.0.1 http://{domain-name}/magento_version'
231
                ),
232
                $res
233
            );
234
235
            // query whether or not the Docker has been started
236
            foreach ($res as $val) {
0 ignored issues
show
Bug introduced by
The expression $res of type null|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
237
                if (strstr($val, 'Magento/')) {
238
                    $magentoNotAvailable = false;
239
                }
240
            }
241
242
            // raise the counter
243
            $counter++;
244
245
            // sleep while the docker container is not available
246
            if ($magentoNotAvailable === true) {
247
                sleep(1);
248
            }
249
250
        } while ($magentoNotAvailable && $counter < 30);
251
252
        // grant the privilieges to connection from outsite the container
253
        $this->taskDockerExec($containerName)
0 ignored issues
show
Bug introduced by
The method interactive does only exist in Robo\Task\Docker\Exec, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
254
             ->interactive()
255
             ->exec('mysql -uroot -proot -e \'GRANT ALL ON *.* TO "magento"@"%" IDENTIFIED BY "magento"\'')
256
             ->run();
257
258
        // flush the privileges
259
        $this->taskDockerExec($containerName)
260
             ->interactive()
261
             ->exec('mysql -uroot -proot -e "FLUSH PRIVILEGES"')
262
             ->run();
263
264
        // run the integration testsuite
265
        $this->taskPHPUnit(
0 ignored issues
show
Bug introduced by
The method configFile does only exist in Robo\Task\Testing\PHPUnit, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
266
                sprintf(
267
                    '%s/bin/phpunit --testsuite "techdivision/import-cli-simple PHPUnit integration testsuite"',
268
                    $this->properties['vendor.dir']
269
                )
270
             )
271
             ->configFile('phpunit.xml')
272
             ->run();
273
    }
274
275
    /**
276
     * Run's the integration testsuite.
277
     *
278
     * This task uses the Magento 2 docker image generator from https://github.com/techdivision/magento2-docker-imgen. To execute
279
     * this task, it is necessary that you've setup a running container with the domain name, passed as argument.
280
     *
281
     * @return void
282
     */
283
    public function runTestsAcceptance()
284
    {
285
286
287
        // prepare the filesystem
288
        $this->prepare();
289
290
        $editions = array(
291
            'http://magento-ce-233.test' => 'instances/ce/2.3.3',
292
            'http://magento-ee-232.test' => 'instances/ee/2.3.2',
293
            'http://magento-ee-233.test' => 'instances/ee/2.3.3'
294
        );
295
296
        foreach ($editions as $baseUrl => $installDir) {
297
            $this->_exec(sprintf("BASE_URL=%s INSTALL_DIR=%s vendor/bin/behat --tags='@product&&@add-update'", $baseUrl, $installDir));
298
        }
299
    }
300
301
    /**
302
     * Raising the semver version number.
303
     *
304
     * @return void
305
     */
306
    public function semver()
307
    {
308
        $this->taskSemVer('.semver')
0 ignored issues
show
Bug introduced by
The method prerelease does only exist in Robo\Task\Development\SemVer, but not in Robo\Collection\CollectionBuilder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
309
             ->prerelease('beta')
310
             ->run();
311
    }
312
313
    /**
314
     * The complete build process.
315
     *
316
     * @return void
317
     */
318
    public function build()
319
    {
320
        $this->clean();
321
        $this->prepare();
322
        $this->runTestsUnit();
323
    }
324
}
325