From e191b1cda50175b252f68f0f573420b870e02ca6 Mon Sep 17 00:00:00 2001 From: Tom Hu <88201630+thomasrockhu-codecov@users.noreply.github.com> Date: Mon, 31 Oct 2022 16:36:08 -0400 Subject: [PATCH 1/9] Create LICENSE.md --- LICENSE.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE.md diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c341b2a --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Codecov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 3712333d35c6f6f37c8a473ef8d9a5b091484de2 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 13 Mar 2023 19:16:27 -0400 Subject: [PATCH 2/9] fix: update REAMDE --- README.md | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 0892ba8..b91974c 100644 --- a/README.md +++ b/README.md @@ -1,46 +1,18 @@ # [Codecov](https://codecov.io) PHP Example +[![codecov](https://codecov.io/github/codecov/example-php/branch/main/graph/badge.svg?token=A7Mb0qlkNW)](https://app.codecov.io/github/codecov/example-php) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-php.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-php?ref=badge_shield) +This example repository shows how Codecov can be integrated with a simple php project. It uses **GitHub Actions** as the CI/CD provider and **phpunit** as the coverage provider. -## Guide - -### Travis Setup - -Add to your `.travis.yml` file. -```yml -language: php - -script: - - vendor/bin/phpunit --coverage-clover coverage.xml - -after_success: - - bash <(curl -s https://codecov.io/bash) -``` - -### Produce Coverage Reports -Collect coverage reports `vendor/bin/phpunit --coverage-clover coverage.xml`, [see here](https://github.com/codecov/example-php/blob/master/.travis.yml#L15) - -### FAQ -- Q: Can I use phpunit.xml.dist?
A: Start tracking coverage metrics by adding a coverage logger: - ```xml - - ... - - - - -``` -- Q: I don't see one or more files, why?
A: Codecov will only show files that have lines covered (hit or miss). If your file has no statments it will not show up in Codecov until you add some. Go get em' tiger! - -## Caveats -### Private Repo -Repository tokens are required for (a) all private repos, (b) public repos not using Travis-CI, CircleCI or AppVeyor. Find your repository token at Codecov and provide via appending `-t ` to you where you upload reports. +For more information, please see the links below. ## Links +- [Quick Start](https://docs.codecov.com/docs/quick-start) +- [GitHub Tutorial](https://docs.codecov.com/docs/github-tutorial) - [Community Boards](https://community.codecov.io) - [Support](https://codecov.io/support) - [Documentation](https://docs.codecov.io) ## License -[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-php.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-php?ref=badge_large) \ No newline at end of file +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fcodecov%2Fexample-php.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fcodecov%2Fexample-php?ref=badge_large) From 75eee4007c68391c966158921be1b8b253a80e34 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Thu, 14 Sep 2023 14:18:23 -0700 Subject: [PATCH 3/9] chore(ci): upgrade to codecov v4 --- .github/workflows/ci.yml | 6 ++++-- .travis.yml | 16 ---------------- 2 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee4b54..8fed75f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up php 8.1 uses: shivammathur/setup-php@v2 with: @@ -15,4 +15,6 @@ jobs: - name: Run tests and collect coverage run: vendor/bin/phpunit --coverage-clover coverage.xml . - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 023b52d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: php - -php: - - 7.2 - - 7.3 - - 7.4 - -before_script: - - travis_retry composer self-update - - travis_retry composer install --no-interaction --prefer-source --dev - -script: - - vendor/bin/phpunit --coverage-clover coverage.xml - -after_success: - - bash <(curl -s https://codecov.io/bash) From 5352b4ced3779411dd601fa2aa27ff353a35c7bb Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Fri, 15 Sep 2023 20:18:02 -0700 Subject: [PATCH 4/9] fix: switch to v4-beta --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fed75f..a53b3de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,6 @@ jobs: - name: Run tests and collect coverage run: vendor/bin/phpunit --coverage-clover coverage.xml . - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v4-beta env: CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} From 3fb204a33d5bd7c05930d3dac66298cb387344d6 Mon Sep 17 00:00:00 2001 From: peter279k Date: Fri, 22 Sep 2023 19:09:52 +0800 Subject: [PATCH 5/9] Improve assertion approaches --- tests/calculatorTest.php | 42 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/calculatorTest.php b/tests/calculatorTest.php index 3c41ed4..f4859f8 100644 --- a/tests/calculatorTest.php +++ b/tests/calculatorTest.php @@ -10,11 +10,11 @@ class calculatorTest extends PHPUnit\Framework\TestCase */ public function testAdd() { - $this->assertEquals(BasicCalculator::add(1, 2), 3.0); - $this->assertEquals(BasicCalculator::add(1.0, 2.0), 3.0); - $this->assertEquals(BasicCalculator::add(0, 2.0), 2.0); - $this->assertEquals(BasicCalculator::add(2.0, 0), 2.0); - $this->assertEquals(BasicCalculator::add(-4, 2.0), -2.0); + $this->assertEquals(3.0, BasicCalculator::add(1, 2)); + $this->assertEquals(3.0, BasicCalculator::add(1.0, 2.0)); + $this->assertEquals(2.0, BasicCalculator::add(0, 2.0)); + $this->assertEquals(2.0, BasicCalculator::add(2.0, 0)); + $this->assertEquals(-2.0, BasicCalculator::add(-4, 2.0)); } /** @@ -22,12 +22,12 @@ public function testAdd() */ public function testSubtract() { - $this->assertEquals(BasicCalculator::subtract(1, 2), -1.0); - $this->assertEquals(BasicCalculator::subtract(2, 1), 1.0); - $this->assertEquals(BasicCalculator::subtract(1.0, 2.0), -1.0); - $this->assertEquals(BasicCalculator::subtract(0, 2.0), -2.0); - $this->assertEquals(BasicCalculator::subtract(2.0, 0), 2.0); - $this->assertEquals(BasicCalculator::subtract(-4, 2.0), -6.0); + $this->assertEquals(-1.0, BasicCalculator::subtract(1, 2)); + $this->assertEquals(1.0, BasicCalculator::subtract(2, 1)); + $this->assertEquals(-1.0, BasicCalculator::subtract(1.0, 2.0)); + $this->assertEquals(-2.0, BasicCalculator::subtract(0, 2.0)); + $this->assertEquals(2.0, BasicCalculator::subtract(2.0, 0)); + $this->assertEquals(-6.0, BasicCalculator::subtract(-4, 2.0)); } /** @@ -35,11 +35,11 @@ public function testSubtract() */ public function testMultiply() { - $this->assertEquals(BasicCalculator::multiply(1, 2), 2.0); - $this->assertEquals(BasicCalculator::multiply(1.0, 2.0), 2.0); - $this->assertEquals(BasicCalculator::multiply(0, 2.0), 0.0); - $this->assertEquals(BasicCalculator::multiply(2.0, 0), 0.0); - $this->assertEquals(BasicCalculator::multiply(-4, 2.0), -8.0); + $this->assertEquals(2.0, BasicCalculator::multiply(1, 2)); + $this->assertEquals(2.0, BasicCalculator::multiply(1.0, 2.0)); + $this->assertEquals(0.0, BasicCalculator::multiply(0, 2.0)); + $this->assertEquals(0.0, BasicCalculator::multiply(2.0, 0)); + $this->assertEquals(-8.0, BasicCalculator::multiply(-4, 2.0)); } /** @@ -47,10 +47,10 @@ public function testMultiply() */ public function testDivide() { - $this->assertEquals(BasicCalculator::divide(1, 2), 0.5); - $this->assertEquals(BasicCalculator::divide(1.0, 2.0), 0.5); - $this->assertEquals(BasicCalculator::divide(0, 2.0), 0.0); - $this->assertEquals(BasicCalculator::divide(-4, 2.0), -2.0); - // $this->assertEquals(BasicCalculator::divide(2.0, 0), 'Cannot divide by 0'); + $this->assertEquals(0.5, BasicCalculator::divide(1, 2)); + $this->assertEquals(0.5, BasicCalculator::divide(1.0, 2.0)); + $this->assertEquals(0.0, BasicCalculator::divide(0, 2.0)); + $this->assertEquals(-2.0, BasicCalculator::divide(-4, 2.0)); + $this->assertEquals('Cannot divide by 0', BasicCalculator::divide(2.0, 0)); } } From 68e94c15f7e2bec14a153d52a1ec41ba6147c1dd Mon Sep 17 00:00:00 2001 From: Tom Hu <88201630+thomasrockhu-codecov@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:57:19 -0500 Subject: [PATCH 6/9] Update tests/calculatorTest.php --- tests/calculatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/calculatorTest.php b/tests/calculatorTest.php index f4859f8..9713e02 100644 --- a/tests/calculatorTest.php +++ b/tests/calculatorTest.php @@ -51,6 +51,6 @@ public function testDivide() $this->assertEquals(0.5, BasicCalculator::divide(1.0, 2.0)); $this->assertEquals(0.0, BasicCalculator::divide(0, 2.0)); $this->assertEquals(-2.0, BasicCalculator::divide(-4, 2.0)); - $this->assertEquals('Cannot divide by 0', BasicCalculator::divide(2.0, 0)); + // $this->assertEquals('Cannot divide by 0', BasicCalculator::divide(2.0, 0)); } } From be3114932649d71fdfb15e81160469d72c5be466 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Wed, 17 Jan 2024 12:38:30 -0800 Subject: [PATCH 7/9] chore(ci): add fossa workflow --- .github/workflows/enforce-license-compliance.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/enforce-license-compliance.yml diff --git a/.github/workflows/enforce-license-compliance.yml b/.github/workflows/enforce-license-compliance.yml new file mode 100644 index 0000000..86be741 --- /dev/null +++ b/.github/workflows/enforce-license-compliance.yml @@ -0,0 +1,14 @@ +name: Enforce License Compliance + +on: + pull_request: + branches: [main, master] + +jobs: + enforce-license-compliance: + runs-on: ubuntu-latest + steps: + - name: 'Enforce License Compliance' + uses: getsentry/action-enforce-license-compliance@57ba820387a1a9315a46115ee276b2968da51f3d # main + with: + fossa_api_key: ${{ secrets.FOSSA_API_KEY }} From c3ab38de8c94b4502074b6604c384a20e44605a3 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Mon, 1 Apr 2024 17:57:36 -0700 Subject: [PATCH 8/9] chore(ci): upgrade to v4 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a53b3de..8fed75f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,6 @@ jobs: - name: Run tests and collect coverage run: vendor/bin/phpunit --coverage-clover coverage.xml . - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4-beta + uses: codecov/codecov-action@v4 env: CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} From 62ff5a654692d816a9f220ce8177d40f028a2127 Mon Sep 17 00:00:00 2001 From: Tom Hu Date: Thu, 5 Dec 2024 19:32:39 -0300 Subject: [PATCH 9/9] chore(ci): upgrade to v5 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fed75f..650248d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,6 @@ jobs: - name: Run tests and collect coverage run: vendor/bin/phpunit --coverage-clover coverage.xml . - name: Upload coverage to Codecov - uses: codecov/codecov-action@v4 + uses: codecov/codecov-action@v5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }}