Skip to content
This repository was archived by the owner on Nov 12, 2024. It is now read-only.

Commit 9583e5f

Browse files
Initial code.
1 parent 19cdce0 commit 9583e5f

File tree

8 files changed

+285
-0
lines changed

8 files changed

+285
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/composer.lock
2+
/vendor/
3+
/runner.yml
4+
/tests/sandbox/

.travis.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
language: php
2+
sudo: false
3+
4+
php:
5+
- 7.1
6+
- 7.2
7+
- 7.3
8+
- 7.4
9+
10+
env:
11+
- TEST_SUITE=PHP_CodeSniffer
12+
- TEST_SUITE=PHPUnit
13+
14+
# Only run the coding standards check once.
15+
matrix:
16+
exclude:
17+
- php: 7.1
18+
env: TEST_SUITE=PHP_CodeSniffer
19+
- php: 7.2
20+
env: TEST_SUITE=PHP_CodeSniffer
21+
- php: 7.3
22+
env: TEST_SUITE=PHP_CodeSniffer
23+
24+
before_script:
25+
- composer self-update
26+
- composer install --no-interaction --prefer-source
27+
28+
script:
29+
- test ${TEST_SUITE} == "PHP_CodeSniffer" || ./vendor/bin/phpunit tests/
30+
- test ${TEST_SUITE} == "PHPUnit" || ./vendor/bin/phpcs

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[![Build Status](https://travis-ci.com/php-task-runner/composer.svg?branch=master)](https://travis-ci.com/php-task-runner/composer)
2+
3+
This repository provides Composer commands for OpenEuropa [Task Runner](
4+
https://github.com/openeuropa/task-runner).
5+
6+
## Commands
7+
8+
* `composer:install`: Run Composer install.

composer.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "php-task-runner/composer",
3+
"description": "Provides Composer commands for OpenEuropa Task Runner",
4+
"keywords": ["task-runner"],
5+
"type": "library",
6+
"require": {
7+
"php": "~7.1",
8+
"ext-json": "*",
9+
"consolidation/robo": "^1.4.11",
10+
"openeuropa/task-runner": "^1.0.0-beta6"
11+
},
12+
"require-dev": {
13+
"phpunit/phpunit": "~7 || ~8 || ~9",
14+
"slevomat/coding-standard": "~6",
15+
"squizlabs/php_codesniffer": "~3",
16+
"composer/composer": "^1"
17+
},
18+
"license": "EUPL-1.2",
19+
"authors": [
20+
{
21+
"name": "Claudiu Cristea",
22+
"email": "[email protected]"
23+
}
24+
],
25+
"autoload": {
26+
"psr-4": {
27+
"TaskRunner\\Composer\\": "./src/"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"TaskRunner\\Composer\\Tests\\": "./tests/src/"
33+
}
34+
},
35+
"config": {
36+
"sort-packages": true
37+
},
38+
"minimum-stability": "dev",
39+
"prefer-stable": true,
40+
"repositories": [
41+
{
42+
"type": "path",
43+
"url": "./tests/fixtures/dependency"
44+
}
45+
]
46+
}

phpcs.xml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="TaskRunner/Scss">
3+
<description>PHP CodeSniffer configuration for the php-task-runner/scss library.</description>
4+
<config name="installed_paths" value="../../slevomat/coding-standard"/>
5+
<rule ref="PSR12">
6+
<exclude name="Generic.Files.LineLength.TooLong" />
7+
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody" />
8+
</rule>
9+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
10+
<properties>
11+
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2" />
12+
<property name="newlinesCountAfterDeclare" value="2" />
13+
<property name="spacesCountAroundEqualsSign" value="0" />
14+
</properties>
15+
</rule>
16+
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation" />
17+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowContinueWithoutIntegerOperandInSwitch" />
18+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />
19+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators" />
20+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses" />
21+
<rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace" />
22+
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses" />
23+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable" />
24+
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma" />
25+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses" />
26+
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceDeclaration" />
27+
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing" />
28+
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility" />
29+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing" />
30+
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
31+
<rule ref="SlevomatCodingStandard.Namespaces.UseDoesNotStartWithBackslash" />
32+
<file>src</file>
33+
<file>tests</file>
34+
<arg name="report" value="full"/>
35+
<arg value="p"/>
36+
</ruleset>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TaskRunner\Composer\TaskRunner\Commands;
6+
7+
use OpenEuropa\TaskRunner\Commands\AbstractCommands;
8+
use Robo\Collection\CollectionBuilder;
9+
use Robo\Task\Composer\loadTasks;
10+
11+
/**
12+
* Provides Composer commands.
13+
*/
14+
class ComposerCommands extends AbstractCommands
15+
{
16+
use loadTasks;
17+
18+
/**
19+
* Options to be used with most of Composer commands.
20+
*
21+
* @var array
22+
*/
23+
protected const DEFAULT_OPTIONS = [
24+
'prefer-source' => false,
25+
'prefer-dist' => false,
26+
'dev' => true,
27+
'optimize-autoloader' => false,
28+
'ignore-platform-reqs' => false,
29+
'no-plugins' => false,
30+
'no-scripts' => false,
31+
];
32+
33+
/**
34+
* Install one or more modules.
35+
*
36+
* @param array $options
37+
* The command line options.
38+
*
39+
* @return \Robo\Collection\CollectionBuilder
40+
* The Robo collection builder.
41+
*
42+
* @command composer:install
43+
*/
44+
public function install(array $options = self::DEFAULT_OPTIONS): CollectionBuilder
45+
{
46+
$task = $this->taskComposerInstall(
47+
$this->getConfig()->get('composer.bin')
48+
);
49+
$this->applyOptions($task, $options);
50+
51+
return $this->collectionBuilder()->addTask($task);
52+
}
53+
54+
/**
55+
* Applies Composer options.
56+
*
57+
* @param \Robo\Collection\CollectionBuilder $task
58+
* The Composer Robo task.
59+
* @param array $options
60+
* The command line options.
61+
*/
62+
protected function applyOptions(
63+
CollectionBuilder $task,
64+
array $options
65+
): void {
66+
/** @var \Robo\Task\Composer\Base $task */
67+
if ($options['prefer-source']) {
68+
$task->preferSource();
69+
}
70+
71+
$task
72+
->preferDist($options['prefer-dist'])
73+
->optimizeAutoloader($options['optimize-autoloader'])
74+
->disablePlugins($options['no-plugins'])
75+
->noScripts($options['no-scripts']);
76+
77+
if (!$options['dev']) {
78+
$task->noDev();
79+
}
80+
if ($options['ignore-platform-reqs']) {
81+
$task->ignorePlatformRequirements($options['ignore-platform-reqs']);
82+
}
83+
}
84+
}
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "foo/bar"
3+
}

tests/src/ComposerCommandsTest.php

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TaskRunner\Composer\Tests;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Symfony\Component\Filesystem\Filesystem;
9+
use Symfony\Component\Yaml\Yaml;
10+
11+
/**
12+
* @coversDefaultClass \TaskRunner\Composer\TaskRunner\Commands\ComposerCommands
13+
*/
14+
class ComposerCommandsTest extends TestCase
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
protected function setUp(): void
20+
{
21+
parent::setUp();
22+
mkdir(__DIR__ . '/../sandbox');
23+
}
24+
25+
/**
26+
* @covers ::install
27+
*/
28+
public function testInstall(): void
29+
{
30+
$sandboxDir = realpath(__DIR__ . '/../sandbox');
31+
// Composer commands needs the path to the executable.
32+
$config = [
33+
'composer' => ['bin' => __DIR__ . '/../../vendor/bin/composer'],
34+
];
35+
file_put_contents(__DIR__ . '/../../runner.yml', Yaml::dump($config));
36+
37+
$composer = [
38+
'require' => [
39+
'foo/bar' => '*',
40+
],
41+
'repositories' => [
42+
[
43+
'type' => 'path',
44+
'url' => './../fixtures/dependency',
45+
],
46+
],
47+
'minimum-stability' => 'dev',
48+
];
49+
file_put_contents(
50+
"{$sandboxDir}/composer.json",
51+
json_encode(
52+
$composer,
53+
JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
54+
)
55+
);
56+
57+
$this->assertFileNotExists("{$sandboxDir}/composer.lock");
58+
$this->assertDirectoryNotExists("{$sandboxDir}/vendor/foo/bar");
59+
exec(
60+
__DIR__ . "/../../vendor/bin/run composer:install --working-dir={$sandboxDir}"
61+
);
62+
$this->assertFileExists("{$sandboxDir}/composer.lock");
63+
$this->assertDirectoryExists("{$sandboxDir}/vendor/foo/bar");
64+
}
65+
66+
/**
67+
* {@inheritdoc}
68+
*/
69+
public function tearDown(): void
70+
{
71+
(new Filesystem())->remove(__DIR__ . '/../sandbox');
72+
parent::tearDown();
73+
}
74+
}

0 commit comments

Comments
 (0)