diff --git a/.circleci/config.yml b/.circleci/config.yml index f13e205..63cd55f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,29 +1,180 @@ +# PHPUnit Composer min/max test. +# TODO: Make our own orb out of this. + version: 2.1 +orbs: + php: circleci/php@1.1.0 + +commands: + update-packages: + description: | + Update your composer packages with automated caching and best practices applied. + parameters: + app-dir: + default: ~/project + description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root. + type: string + cache-files-dir: + default: /home/circleci/.composer/cache/files + description: Absolute path to the file cache folder. This should be inline with "composer global config cache-files-dir --absolute". + type: string + cache-key: + default: composer.lock + description: If this file is updated a new cache bucket will be created. Recommended to use composer.lock. Use composer.json when composer.lock is absent. + type: string + cache-version: + default: v1 + description: Change the default cache version if you need to clear the cache for any reason. + type: string + install-flags: + default: --no-interaction --prefer-dist + description: | + By default, packages will be installed with "composer install --no-interaction --prefer-dist", use this to override the standard install flags. + type: string + vendor-dir: + default: vendor + description: Relative path to the vendor folder. Relative to "app-dir". This should be inline with "composer config vendor-dir". + type: string + with-cache: + default: true + description: Enable automatic caching of your dependencies for increased speed. + type: boolean + steps: + - when: + condition: << parameters.with-cache >> + steps: + - restore_cache: + keys: + - composer-deps-<>-{{ checksum "<>/<>" }} + - run: + command: | + if [ ! -f "composer.json" ] && [ ! -f "composer.lock" ]; then + echo + echo "---" + echo "Unable to find your composer.json and composer.lock files. Did you forget to set the app-dir parameter?" + echo "---" + echo + echo "Current directory: $(pwd)" + echo + echo + echo "List directory: " + echo + ls + exit 1 + fi + name: Verify composer.json and/or composer.lock exist + working_directory: <> + - run: + command: composer update <> + name: Updating Composer Packages + working_directory: <> + - when: + condition: << parameters.with-cache >> + steps: + - save_cache: + key: composer-deps-<>-{{ checksum "<>/<>" }} + paths: + - <>/<> + - <> + install-xdebug: + steps: + - run: + name: Install XDebug + command: sudo -E install-php-extensions xdebug && sudo -E docker-php-ext-enable xdebug + + install-cc-test-reporter: + # TODO: Parameterize location. + steps: + - run: + name: Install Codeclimate test reporter + command: | + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + + run-phpunit-tests: + description: | + Run PHPUnit tests. + parameters: + app-dir: + default: ~/project + description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root. + type: string + install-flags: + default: "" + description: Arguments to `composer update`. + type: string + test-command: + default: test + description: The name of the script within your composer.json which will run your tests. + type: string + report-to-codeclimate: + type: boolean + default: false + description: Report coverage info to Codeclimate. + steps: + - checkout + - update-packages: + app-dir: <> + cache-key: composer.json + install-flags: <> + - when: + condition: <> + steps: + - install-xdebug + - install-cc-test-reporter + - run: | + ./cc-test-reporter before-build + XDEBUG_MODE=coverage composer <> -- --coverage-clover clover.xml + ./cc-test-reporter after-build --coverage-input-type clover --exit-code $? + - when: + condition: + not: <> + steps: + - run: | + XDEBUG_MODE=off composer <> + jobs: - test: - docker: - - image: cimg/php:8.0 - steps: - - checkout - - run: - name: composer install - command: composer install - - run: - name: Setup Code Climate test-reporter - command: | - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build - - run: - name: PHPUnit Tests - environment: - XDEBUG_MODE: coverage - command: phpdbg -qrr vendor/bin/phpunit --coverage-clover clover.xml - - run: - name: Report test coverage - command: ./cc-test-reporter after-build --coverage-input-type clover --exit-code $? + matrix-conditions: + environment: + CC_TEST_REPORTER_ID: 05b97154cabfafb769fb0afb99744dca1b5b1bdc6436657c0ac32887cfa599da + description: Run tests for matrix + executor: + name: php/default + tag: << parameters.version >> + parameters: + version: + default: "7.4" + description: The `cimg/php` Docker image version tag. + type: string + install-flags: + default: "" + description: Arguments to `composer update`. + type: string + steps: + - when: + condition: + and: + - equal: [ "8.1", <> ] + - equal: [ "", <> ] + steps: + - run-phpunit-tests: + report-to-codeclimate: true + install-flags: << parameters.install-flags >> + - when: + condition: + not: + and: + - equal: [ "8.1", <> ] + - equal: [ "", <> ] + steps: + - run-phpunit-tests: + install-flags: << parameters.install-flags >> workflows: - test-workflow: - jobs: - - test + all-tests: + jobs: + - matrix-conditions: + matrix: + parameters: + version: ["7.4", "8.0", "8.1"] + install-flags: ["", "--prefer-lowest"] diff --git a/.ddev/config.yaml b/.ddev/config.yaml deleted file mode 100644 index 7ceeb62..0000000 --- a/.ddev/config.yaml +++ /dev/null @@ -1,171 +0,0 @@ -name: file-fetcher -type: php -docroot: "" -php_version: "8.0" -webserver_type: nginx-fpm -router_http_port: "80" -router_https_port: "443" -xdebug_enabled: false -additional_hostnames: [] -additional_fqdns: [] -mariadb_version: "10.4" -mysql_version: "" -provider: default -use_dns_when_possible: true -composer_version: "2" - - -# This config.yaml was created with ddev version v1.16.5 -# webimage: drud/ddev-webserver:v1.16.3 -# dbimage: drud/ddev-dbserver-mariadb-10.2:v1.16.0 -# dbaimage: phpmyadmin:5 -# However we do not recommend explicitly wiring these images into the -# config.yaml as they may break future versions of ddev. -# You can update this config.yaml using 'ddev config'. - -# Key features of ddev's config.yaml: - -# name: # Name of the project, automatically provides -# http://projectname.ddev.site and https://projectname.ddev.site - -# type: # drupal6/7/8, backdrop, typo3, wordpress, php - -# docroot: # Relative path to the directory containing index.php. - -# php_version: "7.3" # PHP version to use, "5.6", "7.0", "7.1", "7.2", "7.3", "7.4" "8.0" - -# You can explicitly specify the webimage, dbimage, dbaimage lines but this -# is not recommended, as the images are often closely tied to ddev's' behavior, -# so this can break upgrades. - -# webimage: # nginx/php docker image. -# dbimage: # mariadb docker image. -# dbaimage: - -# mariadb_version and mysql_version -# ddev can use many versions of mariadb and mysql -# However these directives are mutually exclusive -# mariadb_version: 10.2 -# mysql_version: 8.0 - -# router_http_port: # Port to be used for http (defaults to port 80) -# router_https_port: # Port for https (defaults to 443) - -# xdebug_enabled: false # Set to true to enable xdebug and "ddev start" or "ddev restart" -# Note that for most people the commands -# "ddev xdebug" to enable xdebug and "ddev xdebug off" to disable it work better, -# as leaving xdebug enabled all the time is a big performance hit. - -# webserver_type: nginx-fpm # or apache-fpm - -# timezone: Europe/Berlin -# This is the timezone used in the containers and by PHP; -# it can be set to any valid timezone, -# see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones -# For example Europe/Dublin or MST7MDT - -# composer_version: "2" -# if composer_version:"" it will use the current ddev default composer release. -# It can also be set to "1", to get most recent composer v1 -# or "2" for most recent composer v2. -# It can be set to any existing specific composer version. -# After first project 'ddev start' this will not be updated until it changes - -# additional_hostnames: -# - somename -# - someothername -# would provide http and https URLs for "somename.ddev.site" -# and "someothername.ddev.site". - -# additional_fqdns: -# - example.com -# - sub1.example.com -# would provide http and https URLs for "example.com" and "sub1.example.com" -# Please take care with this because it can cause great confusion. - -# upload_dir: custom/upload/dir -# would set the destination path for ddev import-files to custom/upload/dir. - -# working_dir: -# web: /var/www/html -# db: /home -# would set the default working directory for the web and db services. -# These values specify the destination directory for ddev ssh and the -# directory in which commands passed into ddev exec are run. - -# omit_containers: [db, dba, ddev-ssh-agent] -# Currently only these containers are supported. Some containers can also be -# omitted globally in the ~/.ddev/global_config.yaml. Note that if you omit -# the "db" container, several standard features of ddev that access the -# database container will be unusable. - -# nfs_mount_enabled: false -# Great performance improvement but requires host configuration first. -# See https://ddev.readthedocs.io/en/stable/users/performance/#using-nfs-to-mount-the-project-into-the-container - -# host_https_port: "59002" -# The host port binding for https can be explicitly specified. It is -# dynamic unless otherwise specified. -# This is not used by most people, most people use the *router* instead -# of the localhost port. - -# host_webserver_port: "59001" -# The host port binding for the ddev-webserver can be explicitly specified. It is -# dynamic unless otherwise specified. -# This is not used by most people, most people use the *router* instead -# of the localhost port. - -# host_db_port: "59002" -# The host port binding for the ddev-dbserver can be explicitly specified. It is dynamic -# unless explicitly specified. - -# phpmyadmin_port: "8036" -# phpmyadmin_https_port: "8037" -# The PHPMyAdmin ports can be changed from the default 8036 and 8037 - -# mailhog_port: "8025" -# mailhog_https_port: "8026" -# The MailHog ports can be changed from the default 8025 and 8026 - -# webimage_extra_packages: [php7.3-tidy, php-bcmath] -# Extra Debian packages that are needed in the webimage can be added here - -# dbimage_extra_packages: [telnet,netcat] -# Extra Debian packages that are needed in the dbimage can be added here - -# use_dns_when_possible: true -# If the host has internet access and the domain configured can -# successfully be looked up, DNS will be used for hostname resolution -# instead of editing /etc/hosts -# Defaults to true - -# project_tld: ddev.site -# The top-level domain used for project URLs -# The default "ddev.site" allows DNS lookup via a wildcard -# If you prefer you can change this to "ddev.local" to preserve -# pre-v1.9 behavior. - -# ngrok_args: --subdomain mysite --auth username:pass -# Provide extra flags to the "ngrok http" command, see -# https://ngrok.com/docs#http or run "ngrok http -h" - -# disable_settings_management: false -# If true, ddev will not create CMS-specific settings files like -# Drupal's settings.php/settings.ddev.php or TYPO3's AdditionalSettings.php -# In this case the user must provide all such settings. - -# no_project_mount: false -# (Experimental) If true, ddev will not mount the project into the web container; -# the user is responsible for mounting it manually or via a script. -# This is to enable experimentation with alternate file mounting strategies. -# For advanced users only! - -# provider: default # Currently either "default" or "pantheon" -# -# Many ddev commands can be extended to run tasks before or after the -# ddev command is executed, for example "post-start", "post-import-db", -# "pre-composer", "post-composer" -# See https://ddev.readthedocs.io/en/stable/users/extending-commands/ for more -# information on the commands that can be extended and the tasks you can define -# for them. Example: -#hooks: diff --git a/.ddev/docker-compose.environment.yml b/.ddev/docker-compose.environment.yml deleted file mode 100644 index 5f892ef..0000000 --- a/.ddev/docker-compose.environment.yml +++ /dev/null @@ -1,5 +0,0 @@ -services: - web: - environment: - XDEBUG_MODE: 'coverage' - PHP_IDE_CONFIG: 'serverName=myproject.ddev.local' diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d9d308c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# This is the top-most .editorconfig file; do not search in parent directories. +root = true + +# All files. +[*] +end_of_line = LF +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[composer.{json,lock}] +indent_size = 4 diff --git a/.gitignore b/.gitignore index d387159..9409c10 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /vendor/ composer.lock +.ddev .idea .vscode .phpunit* diff --git a/composer.json b/composer.json index ea563dc..e222551 100644 --- a/composer.json +++ b/composer.json @@ -1,35 +1,47 @@ { "name": "getdkan/file-fetcher", - "type": "library", "license": "GPL-3.0-only", - "minimum-stability": "dev", - "require-dev": { - "phpunit/phpunit": "^9.0", - "getdkan/mock-chain": "dev-master", - "squizlabs/php_codesniffer": "@stable", - "mikey179/vfsstream": "^2.0@dev" - }, + "type": "library", "authors": [ { "name": "fmizzell", "email": "fmizzell.dev@gmail.com" } ], + "require": { + "php": ">=7.4 <8.2", + "ext-curl": "*", + "getdkan/procrastinator": "^4.0.2", + "guzzlehttp/guzzle": "^6.5.8 || ^7.4.5" + }, + "require-dev": { + "getdkan/mock-chain": "^1.3.5", + "mikey179/vfsstream": "^1.6.10", + "phpunit/phpunit": "^9.6", + "rector/rector": "^0.15.18", + "squizlabs/php_codesniffer": "^3.7" + }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { - "FileFetcher\\": "src/", + "FileFetcher\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { "FileFetcherTests\\": "test/" } }, - "require": { - "getdkan/procrastinator": "^4.0.0", - "ext-curl": "*", - "guzzlehttp/guzzle": "^6.3" + "config": { + "sort-packages": true }, "scripts": { - "phpunit": "./vendor/bin/phpunit", - "phpunit-coverage": "./vendor/bin/phpunit --coverage-html ./coverage", + "phpcbf": "./vendor/bin/phpcbf -p", "phpcs": "./vendor/bin/phpcs -ps", - "phpcbf": "./vendor/bin/phpcbf -p" + "rector": "./vendor/bin/rector process", + "rector-dry-run": "./vendor/bin/rector process --dry-run", + "test": "./vendor/bin/phpunit", + "test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html ./coverage" } } diff --git a/phpcs.xml b/phpcs.xml index d9f7afc..45200cd 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,14 +1,14 @@ - - - PHP CodeSniffer configuration for File Fetcher + - .circleci/ - .ddev/ - vendor/ + + PHP CodeSniffer configuration for GetDKAN. - . + src + test + rector.php + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..dc1c6df --- /dev/null +++ b/rector.php @@ -0,0 +1,22 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/test', + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_74, + ]); + + $rectorConfig->skip([ + JsonThrowOnErrorRector::class, + ]); +}; diff --git a/src/FileFetcher.php b/src/FileFetcher.php index 032d075..e7973e0 100644 --- a/src/FileFetcher.php +++ b/src/FileFetcher.php @@ -17,7 +17,7 @@ class FileFetcher extends AbstractPersistentJob { - private $customProcessorClasses = []; + private array $customProcessorClasses = []; /** * Constructor. diff --git a/test/Processor/RemoteTest.php b/test/Processor/RemoteTest.php index ebdaa4f..5d96b89 100644 --- a/test/Processor/RemoteTest.php +++ b/test/Processor/RemoteTest.php @@ -6,7 +6,7 @@ use FileFetcher\FileFetcher; use FileFetcher\Processor\Remote; use FileFetcherTests\Mock\FakeRemote; -use bovigo\vfs\vfsStream; +use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; use Procrastinator\Result; @@ -70,6 +70,6 @@ public function testCopyException() $remote->copy($state, $result); $this->assertSame(Result::ERROR, $result->getStatus()); - $this->assertStringContainsString('Failed to open stream', $result->getError()); + $this->assertStringContainsString('ailed to open stream', $result->getError()); } }