Files
community.general/tests/unit/plugins/modules/test_composer.yaml
Alexei Znamensky a4bba99203 composer - make create-project idempotent, add force parameter (#11689)
* composer - make create-project idempotent, add force parameter

Adds a check for an existing composer.json in working_dir before running
create-project, so the task is skipped rather than failing on second run.
A new force parameter allows bypassing this check when needed.

Fixes #725.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* changelog fragment: rename to PR number, add PR URL

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-28 08:17:23 +13:00

81 lines
2.2 KiB
YAML

# Copyright (c) Alexei Znamensky (russoz@gmail.com)
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
---
anchors:
help_install: &help_install
command: ["/testbin/php", "/testbin/composer", "help", "install", "--working-dir", "/var/www/foo", "--no-interaction", "--format=json"]
rc: 0
out: |
{"definition": {"options": ["a", "b", "c"]}}
err: ''
help_create_project: &help_create_project
command: ["/testbin/php", "/testbin/composer", "help", "create-project", "--working-dir", "/var/www/foo", "--no-interaction", "--format=json"]
rc: 0
out: |
{"definition": {"options": ["a", "b", "c"]}}
err: ''
run_create_project: &run_create_project
command: ["/testbin/php", "/testbin/composer", "create-project", "--working-dir", "/var/www/foo", "vendor/package"]
rc: 0
out: ''
err: ''
test_cases:
- id: composer
input:
command: install
working_dir: "/var/www/foo"
output:
changed: true
mocks:
run_command:
- *help_install
- command: ["/testbin/php", "/testbin/composer", "install", "--working-dir", "/var/www/foo"]
rc: 0
out: ''
err: ''
- id: create_project_runs
input:
command: create-project
arguments: "vendor/package"
working_dir: "/var/www/foo"
output:
changed: true
mocks:
os_path_exists:
return_value: false
run_command:
- *help_create_project
- *run_create_project
- id: create_project_skips_when_exists
input:
command: create-project
arguments: "vendor/package"
working_dir: "/var/www/foo"
output:
changed: false
mocks:
os_path_exists:
return_value: true
run_command:
- *help_create_project
- id: create_project_force
input:
command: create-project
arguments: "vendor/package"
working_dir: "/var/www/foo"
force: true
output:
changed: true
mocks:
os_path_exists:
return_value: true
run_command:
- *help_create_project
- *run_create_project