Skip to content

Commit

Permalink
feat: Detect conflicting requirement in the requirement checker (#872)
Browse files Browse the repository at this point in the history
Closes #840
  • Loading branch information
theofidry authored Feb 12, 2023
1 parent e76d896 commit 567715a
Show file tree
Hide file tree
Showing 36 changed files with 1,588 additions and 128 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/requirement-checker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ jobs:
docker-image: ghcr.io/box-project/box_php725
- command: _test_e2e_pass_complete_requirement_checker_not_disabled
docker-image: ghcr.io/box-project/box_php725
- command: _test_e2e_fail_conflict
docker-image: ghcr.io/box-project/box_php81
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion requirement-checker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ terminal_copy: $(ACTUAL_TERMINAL_DIFF)
include Makefile.e2e

.PHONY: test_e2e
test_e2e: docker_images _test_e2e_pass_no_config_min_composer_php _test_e2e_pass_no_config_min_box_php _test_e2e_pass_complete_min_composer_php _test_e2e_pass_complete_min_box_php _test_e2e_fail_complete_min_composer_php _test_e2e_fail_complete_min_box_php _test_e2e_skip_min_composer_php _test_e2e_pass_complete_requirement_checker_not_disabled
test_e2e: docker_images _test_e2e_pass_no_config_min_composer_php _test_e2e_pass_no_config_min_box_php _test_e2e_pass_complete_min_composer_php _test_e2e_pass_complete_min_box_php _test_e2e_fail_complete_min_composer_php _test_e2e_fail_complete_min_box_php _test_e2e_skip_min_composer_php _test_e2e_pass_complete_requirement_checker_not_disabled _test_e2e_fail_conflict


#
Expand Down
50 changes: 49 additions & 1 deletion requirement-checker/Makefile.e2e
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ E2E_TEST_FAIL_COMPLETE_MIN_BOX_EXPECTED_STDERR_TEMPLATE := $(E2E_TEST_FAIL_COMPL
E2E_TEST_FAIL_COMPLETE_ACTUAL_STDOUT := $(E2E_TEST_FAIL_COMPLETE_OUTPUT_DIR)/actual-stdout
E2E_TEST_FAIL_COMPLETE_ACTUAL_STDERR := $(E2E_TEST_FAIL_COMPLETE_OUTPUT_DIR)/actual-stderr

E2E_TEST_FAIL_CONFLICT_DIR := fixtures/fail-conflict
E2E_TEST_FAIL_CONFLICT_OUTPUT_DIR := dist/fixtures/fail-conflict
E2E_TEST_FAIL_CONFLICT_VENDOR := $(E2E_TEST_FAIL_CONFLICT_DIR)/vendor
E2E_TEST_FAIL_CONFLICT_PHAR := $(E2E_TEST_FAIL_CONFLICT_OUTPUT_DIR)/index.phar
E2E_TEST_FAIL_CONFLICT_PHAR_SRC := $(shell find $(E2E_TEST_FAIL_CONFLICT_DIR))
E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDOUT := $(E2E_TEST_FAIL_CONFLICT_DIR)/expected-stdout
E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDERR := $(E2E_TEST_FAIL_CONFLICT_OUTPUT_DIR)/expected-boxmin-stderr
E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDERR_TEMPLATE := $(E2E_TEST_FAIL_CONFLICT_DIR)/expected-boxmin-stderr.dist
E2E_TEST_FAIL_CONFLICT_ACTUAL_STDOUT := $(E2E_TEST_FAIL_CONFLICT_OUTPUT_DIR)/actual-stdout
E2E_TEST_FAIL_CONFLICT_ACTUAL_STDERR := $(E2E_TEST_FAIL_CONFLICT_OUTPUT_DIR)/actual-stderr

E2E_TEST_SKIP_DIR := fixtures/fail-complete
E2E_TEST_SKIP_OUTPUT_DIR := dist/fixtures/skip
E2E_TEST_SKIP_PHAR := $(E2E_TEST_SKIP_OUTPUT_DIR)/index.phar
Expand Down Expand Up @@ -181,7 +192,7 @@ test_e2e_pass_complete_requirement_checker_not_disabled: docker_images _test_e2e

.PHONY: _test_e2e_pass_complete_requirement_checker_not_disabled
_test_e2e_pass_complete_requirement_checker_not_disabled: $(E2E_TEST_PASS_COMPLETE_PHAR)
@echo "$(YELLOW_COLOR)Test RequirementChecker with a project with satisfied requirements (min PHP version supported by Box).$(NO_COLOR)"
@echo "$(YELLOW_COLOR)Test RequirementChecker with a project with satisfied requirements with requirement checker not disabled.$(NO_COLOR)"
@rm \
$(E2E_TEST_PASS_COMPLETE_ACTUAL_STDOUT) \
$(E2E_TEST_PASS_COMPLETE_ACTUAL_STDERR) \
Expand Down Expand Up @@ -256,6 +267,31 @@ _test_e2e_fail_complete_min_box_php: $(E2E_TEST_FAIL_COMPLETE_PHAR)
$(E2E_TEST_FAIL_COMPLETE_ACTUAL_STDOUT)


.PHONY: test_e2e_fail_conflict
test_e2e_fail_conflict: docker_images _test_e2e_fail_conflict

.PHONY: _test_e2e_fail_conflict
_test_e2e_fail_conflict: $(E2E_TEST_FAIL_CONFLICT_PHAR)
@echo "$(YELLOW_COLOR)Test RequirementChecker with a project with non-satisfied requirements (conflicting extension loaded).$(NO_COLOR)"
@rm \
$(E2E_TEST_FAIL_CONFLICT_ACTUAL_STDOUT) \
$(E2E_TEST_FAIL_CONFLICT_ACTUAL_STDERR) \
$(E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDERR) || true
@$(MAKE) $(E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDERR)

$(DOCKER_RUN) \
--volume="$$PWD/$(E2E_TEST_FAIL_CONFLICT_OUTPUT_DIR)":/opt/box \
$(DOCKER_MIN_BOX_PHP_VERSION_RUN_COMMAND) 1>$(E2E_TEST_FAIL_CONFLICT_ACTUAL_STDOUT) 2>$(E2E_TEST_FAIL_CONFLICT_ACTUAL_STDERR) \
|| true

$(DIFF) \
$(E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDERR) \
$(E2E_TEST_FAIL_CONFLICT_ACTUAL_STDERR)
$(DIFF) \
$(E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDOUT) \
$(E2E_TEST_FAIL_CONFLICT_ACTUAL_STDOUT)


#
# Skip the requirement check
#---------------------------------------------------------------------------
Expand Down Expand Up @@ -345,6 +381,18 @@ $(E2E_TEST_FAIL_COMPLETE_MIN_BOX_EXPECTED_STDERR): $(E2E_TEST_FAIL_COMPLETE_OUTP
$(E2E_TEST_FAIL_COMPLETE_MIN_BOX_EXPECTED_STDERR_TEMPLATE) \
> $@

$(E2E_TEST_FAIL_CONFLICT_PHAR): $(SCOPED_BOX_BIN) $(E2E_TEST_FAIL_CONFLICT_PHAR_SRC)
$(SCOPED_BOX) compile --ansi --working-dir=$(E2E_TEST_FAIL_CONFLICT_DIR) --no-parallel
mkdir -p $(E2E_TEST_FAIL_CONFLICT_OUTPUT_DIR)
mv $(E2E_TEST_FAIL_CONFLICT_DIR)/index.phar $(E2E_TEST_FAIL_CONFLICT_PHAR)
touch -c $(E2E_TEST_FAIL_CONFLICT_PHAR)
$(E2E_TEST_FAIL_CONFLICT_VENDOR): $(E2E_TEST_FAIL_CONFLICT_DIR)/composer.lock
$(E2E_TEST_FAIL_CONFLICT_DIR)/composer.lock: $(E2E_TEST_FAIL_CONFLICT_DIR)/composer.json
$(E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDERR): $(E2E_TEST_FAIL_CONFLICT_OUTPUT_DIR) $(E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDERR_TEMPLATE)
sed "s/PHP_VERSION/$$($(DOCKER_RUN) $(DOCKER_MIN_BOX_PHP_VERSION_IMAGE_TAG) php -r 'echo PHP_VERSION;')/" \
$(E2E_TEST_FAIL_CONFLICT_MIN_BOX_EXPECTED_STDERR_TEMPLATE) \
> $@

$(E2E_TEST_SKIP_OUTPUT_DIR):
mkdir -p $@
touch -c $@
Expand Down
8 changes: 8 additions & 0 deletions requirement-checker/fixtures/fail-conflict/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"require": {
"ext-phar": "*"
},
"conflict": {
"ext-pdo" : "*"
}
}
20 changes: 20 additions & 0 deletions requirement-checker/fixtures/fail-conflict/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

Box Requirements Checker
========================

> Using PHP PHP_VERSION
> PHP is using the following php.ini file:
WARNING: No configuration file (php.ini) used by PHP!

> Checking Box requirements:
✔ The application requires the extension "phar".
✘ The application conflicts with the extension "pdo".


[ERROR] Your system is not ready to run the application.


Fix the following mandatory requirements:
=========================================

* The application conflicts with the extension "pdo".

Empty file.
13 changes: 13 additions & 0 deletions requirement-checker/fixtures/fail-conflict/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <[email protected]>
* Théo Fidry <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

throw new Exception('Should not be executed!');
25 changes: 25 additions & 0 deletions requirement-checker/fixtures/fail-conflict/vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitb25b42e01280328343dc4cbf40125bce::getLoader();
Loading

0 comments on commit 567715a

Please sign in to comment.