Skip to content
This repository has been archived by the owner on Mar 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from PrestaShop/improve-quality-build
Browse files Browse the repository at this point in the history
Improved quality build
  • Loading branch information
Mickaël Andrieu committed Jan 25, 2019
2 parents ce368d1 + c60f3d2 commit b1bd276
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 19 deletions.
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -13,7 +13,6 @@ composer require prestashop/composer-script-handler --dev

In your Shop, you can now declare modules into "prestashop.modules" in the "extras" section of Composer.

Once you do that, on "install" and "update" processes, every module will be installed
so you will always get the most "up to date" version of each module!
Once you do that, on "install" and "update" processes, every module will be installed so you will always get the most "up to date" version of each module!

> This project is under MIT license
2 changes: 1 addition & 1 deletion src/ConfigurationProcessor.php
Expand Up @@ -79,6 +79,6 @@ public function processInstallation(array $configuration)
$processManager->add($command, $this->modulesLocation);
}

$processManager->run();
$this->io->write($processManager->run());
}
}
24 changes: 24 additions & 0 deletions src/Contracts/ProcessManagerInterface.php
@@ -0,0 +1,24 @@
<?php

namespace PrestaShop\Composer\Contracts;

/**
* Define an implementation to manage
* multiple calls of Process, for performance
* mainly.
*/
interface ProcessManagerInterface
{
/**
* @param string $command the Process command to execute
* @param string $location the working directory of command to execute
*/
public function add($command, $location);

/**
* Execute all processes and output the results
*
* @return string
*/
public function run();
}
23 changes: 17 additions & 6 deletions src/ProcessManager/ProcessManager.php
Expand Up @@ -26,36 +26,41 @@ final class ProcessManager implements ProcessManagerInterface
*/
private $processes;

/**
* @var int
*/
private $runningProcesses;

public function __construct($timestamp, $maxParallelProcesses)
{
$this->timestamp = $timestamp;
$this->maxParallelProcesses = $maxParallelProcesses;
}

/**
* {@inheritdoc}
*/
public function add($command, $location)
{
$this->processes[] = (new Process($command))
->setWorkingDirectory($location)
;
}

/**
* {@inheritdoc}
*/
public function run()
{
$batchOfProcesses = array_chunk($this->processes, $this->maxParallelProcesses);
$output = '';

foreach ($batchOfProcesses as $processes) {
$this->runProcesses($processes);
$output .= $this->runProcesses($processes);
}

return $output;
}

private function runProcesses(array $processes)
{
$runningProcesses = count($processes);
$outputResult = '';

foreach ($processes as $process) {
$process->start();
Expand All @@ -70,5 +75,11 @@ private function runProcesses(array $processes)
usleep($this->timestamp);
}
}

foreach ($processes as $process) {
$outputResult = $process->getOutput();
}

return $outputResult;
}
}
15 changes: 11 additions & 4 deletions tests/Actions/CreateProjectTest.php
Expand Up @@ -22,16 +22,23 @@ public function testGetName()
$this->assertSame('create-project', $action->getName());
}

public function testGetArguments()
public function testGetArgumentsWithoutArguments()
{
$actionsWithoutArguments = new CreateProject();

$this->assertSame([
$currentArgs = [
'--no-scripts',
'--no-progress',
'--no-interaction',
], $actionsWithoutArguments->getArguments());
];

$this->assertSame(
$currentArgs,
$actionsWithoutArguments->getArguments()
);
}

public function testGetArguments()
{
$action = new CreateProject(['foo' => 'bar']);

$this->assertSame(['foo' => 'bar'], $action->getArguments());
Expand Down
22 changes: 16 additions & 6 deletions tests/Actions/UpdateTest.php
Expand Up @@ -10,9 +10,12 @@ final class UpdateTest extends TestCase
public function testCreation()
{
$this->assertInstanceOf(Update::class, new Update());
$this->assertInstanceOf(Update::class, new Update(
['foo' => 'bar']
));
$arguments = ['foo' => 'bar'];

$this->assertInstanceOf(
Update::class,
new Update($arguments)
);
}

public function testGetName()
Expand All @@ -22,14 +25,21 @@ public function testGetName()
$this->assertSame('update', $action->getName());
}

public function testGetArguments()
public function testGetArgumentsWithoutArguments()
{
$actionsWithoutArguments = new Update();

$this->assertSame([], $actionsWithoutArguments->getArguments());
}

$action = new Update(['foo' => 'bar']);
public function testGetArguments()
{
$arguments = ['foo' => 'bar'];
$action = new Update($arguments);

$this->assertSame(['foo' => 'bar'], $action->getArguments());
$this->assertSame(
$arguments,
$action->getArguments()
);
}
}

0 comments on commit b1bd276

Please sign in to comment.