-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make compatible tests with Composer 2.3, 2.4 and 2.5
- Loading branch information
1 parent
a9ad13a
commit c474322
Showing
5 changed files
with
177 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Foxy package. | ||
* | ||
* (c) François Pluchino <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Foxy\Tests\Fixtures\Util; | ||
|
||
use Composer\Util\ProcessExecutor; | ||
|
||
/** | ||
* Mock of ProcessExecutor. | ||
* | ||
* @author François Pluchino <[email protected]> | ||
*/ | ||
abstract class AbstractProcessExecutorMock extends ProcessExecutor | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $expectedValues = array(); | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $executedCommands = array(); | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $position = 0; | ||
|
||
public function doExecute($command, &$output = null, ?string $cwd = null): int | ||
{ | ||
$expected = isset($this->expectedValues[$this->position]) | ||
? $this->expectedValues[$this->position] | ||
: array(0, $output); | ||
|
||
list($returnedCode, $output) = $expected; | ||
$this->executedCommands[] = array($command, $returnedCode, $output); | ||
++$this->position; | ||
|
||
return $returnedCode; | ||
} | ||
|
||
/** | ||
* @param int $returnedCode The returned code | ||
* @param null $output The output | ||
* | ||
* @return self | ||
*/ | ||
public function addExpectedValues($returnedCode = 0, $output = null) | ||
{ | ||
$this->expectedValues[] = array($returnedCode, $output); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the executed command. | ||
* | ||
* @param int $position The position of executed command | ||
* | ||
* @return null|string | ||
*/ | ||
public function getExecutedCommand($position) | ||
{ | ||
return $this->getExecutedValue($position, 0); | ||
} | ||
|
||
/** | ||
* Get the executed returned code. | ||
* | ||
* @param int $position The position of executed command | ||
* | ||
* @return null|int | ||
*/ | ||
public function getExecutedReturnedCode($position) | ||
{ | ||
return $this->getExecutedValue($position, 1); | ||
} | ||
|
||
/** | ||
* Get the executed command. | ||
* | ||
* @param int $position The position of executed command | ||
* | ||
* @return null|string | ||
*/ | ||
public function getExecutedOutput($position) | ||
{ | ||
return $this->getExecutedValue($position, 2); | ||
} | ||
|
||
/** | ||
* Get the last executed command. | ||
* | ||
* @return null|string | ||
*/ | ||
public function getLastCommand() | ||
{ | ||
return $this->getExecutedCommand(\count($this->executedCommands) - 1); | ||
} | ||
|
||
/** | ||
* Get the last executed returned code. | ||
* | ||
* @return null|int | ||
*/ | ||
public function getLastReturnedCode() | ||
{ | ||
return $this->getExecutedReturnedCode(\count($this->executedCommands) - 1); | ||
} | ||
|
||
/** | ||
* Get the last executed output. | ||
* | ||
* @return null|string | ||
*/ | ||
public function getLastOutput() | ||
{ | ||
return $this->getExecutedOutput(\count($this->executedCommands) - 1); | ||
} | ||
|
||
/** | ||
* Get the value of the executed command. | ||
* | ||
* @param int $position The position | ||
* @param int $index The index of value | ||
* | ||
* @return null|int|string | ||
*/ | ||
private function getExecutedValue($position, $index) | ||
{ | ||
return isset($this->executedCommands[$position]) | ||
? $this->executedCommands[$position][$index] | ||
: null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,137 +11,34 @@ | |
|
||
namespace Foxy\Tests\Fixtures\Util; | ||
|
||
use Composer\Composer; | ||
use Composer\Util\ProcessExecutor; | ||
|
||
/** | ||
/* | ||
* Mock of ProcessExecutor. | ||
* | ||
* @author François Pluchino <[email protected]> | ||
*/ | ||
class ProcessExecutorMock extends ProcessExecutor | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $expectedValues = array(); | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $executedCommands = array(); | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $position = 0; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute($command, &$output = null, $cwd = null) | ||
{ | ||
$expected = isset($this->expectedValues[$this->position]) | ||
? $this->expectedValues[$this->position] | ||
: array(null, $output); | ||
|
||
list($returnedCode, $output) = $expected; | ||
$this->executedCommands[] = array($command, $returnedCode, $output); | ||
++$this->position; | ||
|
||
return $returnedCode; | ||
} | ||
|
||
/** | ||
* @param int $returnedCode The returned code | ||
* @param null $output The output | ||
* | ||
* @return self | ||
*/ | ||
public function addExpectedValues($returnedCode = 0, $output = null) | ||
{ | ||
$this->expectedValues[] = array($returnedCode, $output); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the executed command. | ||
* | ||
* @param int $position The position of executed command | ||
* | ||
* @return null|string | ||
*/ | ||
public function getExecutedCommand($position) | ||
{ | ||
return $this->getExecutedValue($position, 0); | ||
} | ||
|
||
/** | ||
* Get the executed returned code. | ||
* | ||
* @param int $position The position of executed command | ||
* | ||
* @return null|int | ||
*/ | ||
public function getExecutedReturnedCode($position) | ||
{ | ||
return $this->getExecutedValue($position, 1); | ||
} | ||
|
||
/** | ||
* Get the executed command. | ||
* | ||
* @param int $position The position of executed command | ||
* | ||
* @return null|string | ||
*/ | ||
public function getExecutedOutput($position) | ||
{ | ||
return $this->getExecutedValue($position, 2); | ||
} | ||
|
||
/** | ||
* Get the last executed command. | ||
* | ||
* @return null|string | ||
*/ | ||
public function getLastCommand() | ||
{ | ||
return $this->getExecutedCommand(\count($this->executedCommands) - 1); | ||
} | ||
|
||
/** | ||
* Get the last executed returned code. | ||
* | ||
* @return null|int | ||
*/ | ||
public function getLastReturnedCode() | ||
{ | ||
return $this->getExecutedReturnedCode(\count($this->executedCommands) - 1); | ||
} | ||
|
||
/** | ||
* Get the last executed output. | ||
* | ||
* @return null|string | ||
*/ | ||
public function getLastOutput() | ||
{ | ||
return $this->getExecutedOutput(\count($this->executedCommands) - 1); | ||
} | ||
|
||
/** | ||
* Get the value of the executed command. | ||
* | ||
* @param int $position The position | ||
* @param int $index The index of value | ||
* | ||
* @return null|int|string | ||
*/ | ||
private function getExecutedValue($position, $index) | ||
{ | ||
return isset($this->executedCommands[$position]) | ||
? $this->executedCommands[$position][$index] | ||
: null; | ||
if (version_compare(Composer::VERSION, '2.3.0', '<')) { | ||
class ProcessExecutorMock extends AbstractProcessExecutorMock | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute($command, &$output = null, $cwd = null) | ||
{ | ||
return $this->doExecute($command, $output, $cwd); | ||
} | ||
} | ||
} else { | ||
class ProcessExecutorMock extends AbstractProcessExecutorMock | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function execute($command, &$output = null, ?string $cwd = null): int | ||
{ | ||
return $this->doExecute($command, $output, $cwd); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters