From c875410378e33d6f0081b9116d9ff56e879e81cf Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 7 Jan 2021 01:57:11 +0800 Subject: [PATCH] Migrate to GitHub Actions and improve assertions --- .github/workflows/php.yml | 35 ++++++++++++++++++++++++++ .travis.yml | 33 ------------------------ composer.json | 4 +-- tests/Loader/ArrayValuesLoaderTest.php | 2 +- tests/Loader/EnvLoaderTest.php | 9 +++---- tests/Loader/FileLoaderTest.php | 2 +- 6 files changed, 42 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/php.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..0de79a2 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,35 @@ +name: Build +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ['7.1', '7.2', '7.3', '7.4', '8.0'] + name: PHP ${{ matrix.php }} + steps: + - uses: actions/checkout@v1 + - name: Install PHP + uses: shivammathur/setup-php@master + with: + php-version: ${{ matrix.php }} + - name: Report PHP version + run: php -v + - name: Validate composer.json and composer.lock + run: composer validate + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Cache dependencies + uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ matrix.php }}-composer- + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + - name: Run style check + run: vendor/bin/phpcs src tests + - name: Run test suite + run: vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1e863e3..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: php - -## Versions to test -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - -## Use lowest stable versions for oldest version test -matrix: - include: - - php: 7.1 - env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"' - -## Cache composer -cache: - directories: - - $HOME/.composer/cache - -## Run composer update -before_script: - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist - -## Run tests (codesniffer and PhpUnit) -script: - - vendor/bin/phpcs --standard=psr12 src/ - - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover - -## Report code coverage to scrutinizer -after_script: - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover coverage.clover \ No newline at end of file diff --git a/composer.json b/composer.json index 232e014..340edce 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "php" : "^7.1", + "php" : ">=7.1", "ext-json": "*", "symfony/yaml" : "^3.4|^4.0|^5.0", @@ -22,7 +22,7 @@ }, "require-dev": { - "phpunit/phpunit" : "^7.5|^8.0", + "phpunit/phpunit" : "^7.5|^8.0|^9.0", "vlucas/phpdotenv" : "^4.1", "symfony/config" : "^3.4|^4.2|^5.0", "squizlabs/php_codesniffer": "^3.5" diff --git a/tests/Loader/ArrayValuesLoaderTest.php b/tests/Loader/ArrayValuesLoaderTest.php index 22bbb38..0c34064 100644 --- a/tests/Loader/ArrayValuesLoaderTest.php +++ b/tests/Loader/ArrayValuesLoaderTest.php @@ -27,6 +27,6 @@ public function testLoad(): void { $config = (new ArrayValuesLoader(static::$values))->load(); $this->assertEquals('Pineapple', $config->get('c.p')); - $this->assertEquals(4, count($config)); + $this->assertCount(4, $config); } } diff --git a/tests/Loader/EnvLoaderTest.php b/tests/Loader/EnvLoaderTest.php index 4f38c1a..a2989f2 100644 --- a/tests/Loader/EnvLoaderTest.php +++ b/tests/Loader/EnvLoaderTest.php @@ -47,9 +47,6 @@ function ($val) use ($rMethod) { $this->assertEquals($expected, (new EnvLoader())->load()->getArrayCopy()); } - /** - * - */ public function testLoadSetsAllValuesToLowerCaseIfSpecified() { $this->assertEquals( @@ -148,9 +145,9 @@ public function testPrepareValuesSetsScalarsCorrectly() $values = EnvLoader::loadUsingPrefix('FOOBAR_'); $this->assertSame(2, $values->get('INTEGER')); $this->assertSame(2.3, $values->get('FLOAT')); - $this->assertSame(true, $values->get('TRUE')); - $this->assertSame(false, $values->get('FALSE')); - $this->assertSame(null, $values->get('NULL')); + $this->assertTrue($values->get('TRUE')); + $this->assertFalse($values->get('FALSE')); + $this->assertNull($values->get('NULL')); $this->assertSame('somestuff', $values->get('STR')); } diff --git a/tests/Loader/FileLoaderTest.php b/tests/Loader/FileLoaderTest.php index e4c00f4..a6ee33f 100644 --- a/tests/Loader/FileLoaderTest.php +++ b/tests/Loader/FileLoaderTest.php @@ -35,7 +35,7 @@ public function testLoadReturnsEmptyConfigValuesIfFileNotExistsAndNotRequired(): { @unlink($this->getTestFilePath()); // remove the file $values = $this->getLoader(false)->load(); - $this->assertEquals(0, count($values)); + $this->assertCount(0, $values); } public function testLoadThowsExceptionIfFileIsNotReadableAndIsRequired(): void