|
1 |
| -version: 2.0 |
| 1 | +# PHPUnit Composer min/max test. |
| 2 | +# TODO: Make our own orb out of this. |
| 3 | + |
| 4 | +version: 2.1 |
| 5 | +orbs: |
| 6 | + |
| 7 | + |
| 8 | +commands: |
| 9 | + update-packages: |
| 10 | + description: | |
| 11 | + Update your composer packages with automated caching and best practices applied. |
| 12 | + parameters: |
| 13 | + app-dir: |
| 14 | + default: ~/project |
| 15 | + description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root. |
| 16 | + type: string |
| 17 | + cache-files-dir: |
| 18 | + default: /home/circleci/.composer/cache/files |
| 19 | + description: Absolute path to the file cache folder. This should be inline with "composer global config cache-files-dir --absolute". |
| 20 | + type: string |
| 21 | + cache-key: |
| 22 | + default: composer.lock |
| 23 | + 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. |
| 24 | + type: string |
| 25 | + cache-version: |
| 26 | + default: v1 |
| 27 | + description: Change the default cache version if you need to clear the cache for any reason. |
| 28 | + type: string |
| 29 | + install-flags: |
| 30 | + default: --no-interaction --prefer-dist |
| 31 | + description: | |
| 32 | + By default, packages will be installed with "composer install --no-interaction --prefer-dist", use this to override the standard install flags. |
| 33 | + type: string |
| 34 | + vendor-dir: |
| 35 | + default: vendor |
| 36 | + description: Relative path to the vendor folder. Relative to "app-dir". This should be inline with "composer config vendor-dir". |
| 37 | + type: string |
| 38 | + with-cache: |
| 39 | + default: true |
| 40 | + description: Enable automatic caching of your dependencies for increased speed. |
| 41 | + type: boolean |
| 42 | + steps: |
| 43 | + - when: |
| 44 | + condition: << parameters.with-cache >> |
| 45 | + steps: |
| 46 | + - restore_cache: |
| 47 | + keys: |
| 48 | + - composer-deps-<<parameters.cache-version>>-{{ checksum "<<parameters.app-dir>>/<<parameters.cache-key>>" }} |
| 49 | + - run: |
| 50 | + command: | |
| 51 | + if [ ! -f "composer.json" ] && [ ! -f "composer.lock" ]; then |
| 52 | + echo |
| 53 | + echo "---" |
| 54 | + echo "Unable to find your composer.json and composer.lock files. Did you forget to set the app-dir parameter?" |
| 55 | + echo "---" |
| 56 | + echo |
| 57 | + echo "Current directory: $(pwd)" |
| 58 | + echo |
| 59 | + echo |
| 60 | + echo "List directory: " |
| 61 | + echo |
| 62 | + ls |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + name: Verify composer.json and/or composer.lock exist |
| 66 | + working_directory: <<parameters.app-dir>> |
| 67 | + - run: |
| 68 | + command: composer update <<parameters.install-flags>> |
| 69 | + name: Updating Composer Packages |
| 70 | + working_directory: <<parameters.app-dir>> |
| 71 | + - when: |
| 72 | + condition: << parameters.with-cache >> |
| 73 | + steps: |
| 74 | + - save_cache: |
| 75 | + key: composer-deps-<<parameters.cache-version>>-{{ checksum "<<parameters.app-dir>>/<<parameters.cache-key>>" }} |
| 76 | + paths: |
| 77 | + - <<parameters.app-dir>>/<<parameters.vendor-dir>> |
| 78 | + - <<parameters.cache-files-dir>> |
| 79 | + install-xdebug: |
| 80 | + steps: |
| 81 | + - run: |
| 82 | + name: Install XDebug |
| 83 | + command: sudo -E install-php-extensions xdebug && sudo -E docker-php-ext-enable xdebug |
| 84 | + |
| 85 | + install-cc-test-reporter: |
| 86 | + # TODO: Parameterize location. |
| 87 | + steps: |
| 88 | + - run: |
| 89 | + name: Install Codeclimate test reporter |
| 90 | + command: | |
| 91 | + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter |
| 92 | + chmod +x ./cc-test-reporter |
| 93 | +
|
| 94 | + run-phpunit-tests: |
| 95 | + description: | |
| 96 | + Run PHPUnit tests. |
| 97 | + parameters: |
| 98 | + app-dir: |
| 99 | + default: ~/project |
| 100 | + description: Path to the directory containing your composer.json file. Not needed if composer.json lives in the root. |
| 101 | + type: string |
| 102 | + install-flags: |
| 103 | + default: "" |
| 104 | + description: Arguments to `composer update`. |
| 105 | + type: string |
| 106 | + test-command: |
| 107 | + default: test |
| 108 | + description: The name of the script within your composer.json which will run your tests. |
| 109 | + type: string |
| 110 | + report-to-codeclimate: |
| 111 | + type: boolean |
| 112 | + default: false |
| 113 | + description: Report coverage info to Codeclimate. |
| 114 | + steps: |
| 115 | + - checkout |
| 116 | + - update-packages: |
| 117 | + app-dir: <<parameters.app-dir>> |
| 118 | + cache-key: composer.json |
| 119 | + install-flags: <<parameters.install-flags>> |
| 120 | + - when: |
| 121 | + condition: <<parameters.report-to-codeclimate>> |
| 122 | + steps: |
| 123 | + - install-xdebug |
| 124 | + - install-cc-test-reporter |
| 125 | + - run: | |
| 126 | + ./cc-test-reporter before-build |
| 127 | + XDEBUG_MODE=coverage composer <<parameters.test-command>> -- --coverage-clover clover.xml |
| 128 | + ./cc-test-reporter after-build --coverage-input-type clover --exit-code $? |
| 129 | + - when: |
| 130 | + condition: |
| 131 | + not: <<parameters.report-to-codeclimate>> |
| 132 | + steps: |
| 133 | + - run: | |
| 134 | + XDEBUG_MODE=off composer <<parameters.test-command>> |
| 135 | +
|
2 | 136 | jobs:
|
3 |
| - build: |
4 |
| - environment: |
5 |
| - CC_TEST_REPORTER_ID: d20339bfed51b1e242630efbe3f2745337794f7a856f610aad4d21897c5e0309 |
6 |
| - docker: |
7 |
| - - image: circleci/php:7-cli-node-browsers-legacy |
8 |
| - working_directory: ~/repo |
9 |
| - steps: |
10 |
| - - checkout |
11 |
| - - run: |
12 |
| - name: Setup dependencies |
13 |
| - command: | |
14 |
| - sudo composer self-update |
15 |
| - composer install -n --prefer-dist |
16 |
| - - run: |
17 |
| - name: Setup Code Climate test-reporter |
18 |
| - command: | |
19 |
| - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter |
20 |
| - chmod +x ./cc-test-reporter |
21 |
| - - run: |
22 |
| - name: Run tests |
23 |
| - command: | |
24 |
| - ./cc-test-reporter before-build |
25 |
| - vendor/bin/phpunit --testsuite all --coverage-clover clover.xml |
26 |
| - ./cc-test-reporter after-build --coverage-input-type clover --exit-code $? |
| 137 | + matrix-conditions: |
| 138 | + environment: |
| 139 | + CC_TEST_REPORTER_ID: d20339bfed51b1e242630efbe3f2745337794f7a856f610aad4d21897c5e0309 |
| 140 | + description: Run tests for matrix |
| 141 | + executor: |
| 142 | + name: php/default |
| 143 | + tag: << parameters.version >> |
| 144 | + parameters: |
| 145 | + version: |
| 146 | + default: "7.4" |
| 147 | + description: The `cimg/php` Docker image version tag. |
| 148 | + type: string |
| 149 | + install-flags: |
| 150 | + default: "" |
| 151 | + description: Arguments to `composer update`. |
| 152 | + type: string |
| 153 | + steps: |
| 154 | + - when: |
| 155 | + condition: |
| 156 | + and: |
| 157 | + - equal: [ "8.1", <<parameters.version>> ] |
| 158 | + - equal: [ "", <<parameters.install-flags>> ] |
| 159 | + steps: |
| 160 | + - run-phpunit-tests: |
| 161 | + report-to-codeclimate: true |
| 162 | + install-flags: << parameters.install-flags >> |
| 163 | + - when: |
| 164 | + condition: |
| 165 | + not: |
| 166 | + and: |
| 167 | + - equal: [ "8.1", <<parameters.version>> ] |
| 168 | + - equal: [ "", <<parameters.install-flags>> ] |
| 169 | + steps: |
| 170 | + - run-phpunit-tests: |
| 171 | + install-flags: << parameters.install-flags >> |
| 172 | + |
| 173 | +workflows: |
| 174 | + all-tests: |
| 175 | + jobs: |
| 176 | + - matrix-conditions: |
| 177 | + matrix: |
| 178 | + parameters: |
| 179 | + version: ["7.4", "8.0", "8.1"] |
| 180 | + install-flags: ["", "--prefer-lowest"] |
0 commit comments