diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa1dc96a..5c871b33 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -178,6 +178,16 @@ jobs: run: | ! $BLUEPRINT $CMD_VALIDATE $INVALID_TEST + - name: Test as composer package + run: | + mkdir -pv ./build/composer-test + cd ./build/composer-test + composer init --no-interaction --name="test/test" + composer require jbzoo/csv-blueprint + ./vendor/bin/csv-blueprint || true + ./vendor/bin/csv-blueprint $CMD_VALIDATE $VALID_TEST || true + ./vendor/bin/csv-blueprint $CMD_VALIDATE $INVALID_TEST || true + verify-phar-binary: name: Verify Phar diff --git a/csv-blueprint.php b/csv-blueprint.php index 6ebb2bd6..76b788ae 100644 --- a/csv-blueprint.php +++ b/csv-blueprint.php @@ -17,7 +17,25 @@ namespace JBZoo\CsvBlueprint; \define('PATH_ROOT', __DIR__); -require_once PATH_ROOT . '/vendor/autoload.php'; + +foreach ( + [ + PATH_ROOT . '/../../autoload.php', + PATH_ROOT . '/../vendor/autoload.php', + PATH_ROOT . '/vendor/autoload.php', + ] as $file +) { + if (\file_exists($file)) { + \define('JBZOO_AUTOLOAD_FILE', $file); + break; + } +} + +if (\defined('JBZOO_AUTOLOAD_FILE')) { + require_once JBZOO_AUTOLOAD_FILE; +} else { + throw new Exception('Cannot find composer autoload file'); +} if ('cli' !== \PHP_SAPI) { throw new Exception('This script must be run from the command line.');