From 6629d8097e2ce6111084362d346157666734ffa8 Mon Sep 17 00:00:00 2001 From: vlad kobilansky Date: Mon, 24 Jun 2024 09:58:15 -0400 Subject: [PATCH 1/4] adding a fake test --- tests/Unit/ChargeTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Unit/ChargeTest.php b/tests/Unit/ChargeTest.php index ecfb30e..7cc9c7d 100644 --- a/tests/Unit/ChargeTest.php +++ b/tests/Unit/ChargeTest.php @@ -42,4 +42,11 @@ public function testReturnDataSet() { $result = $charge->returnDataSet(); $this->assertEquals('data set', $result); } + + public function testUncoveredUnitTestFuction() { + + $charge = Charge::factory()->make(); + $result = $charge->returnDataSet(); + $this->assertEquals('data set', $result); + } } From a637a916fa4683fae4f1cabdcde454ac5357c4a9 Mon Sep 17 00:00:00 2001 From: vlad kobilansky Date: Mon, 24 Jun 2024 10:20:21 -0400 Subject: [PATCH 2/4] adjusting a function --- app/Models/Charge.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Models/Charge.php b/app/Models/Charge.php index a8692ff..6df75b9 100644 --- a/app/Models/Charge.php +++ b/app/Models/Charge.php @@ -58,7 +58,9 @@ public function getDataForReport() } public function uncoveredUnitTestFunction() { - return 'data'; + if (true) { + return 'data'; + } } public function unitTestModel() { From 51c0952b2920caa98b22af438de49dd2c46fea2a Mon Sep 17 00:00:00 2001 From: vlad kobilansky Date: Mon, 24 Jun 2024 10:33:49 -0400 Subject: [PATCH 3/4] adding tests and things --- .github/workflows/pr-only.yaml | 24 ++++++++++++------------ app/Models/ImportantOne.php | 8 +++++--- tests/Unit/ChargeTest.php | 4 ++-- tests/Unit/ImportantOneTest.php | 26 ++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 tests/Unit/ImportantOneTest.php diff --git a/.github/workflows/pr-only.yaml b/.github/workflows/pr-only.yaml index d83d6cf..63b0f12 100644 --- a/.github/workflows/pr-only.yaml +++ b/.github/workflows/pr-only.yaml @@ -76,23 +76,23 @@ jobs: run: sudo chmod +x codecov # RUN tests an upload reports ### (Codecov integration - STEP 3) - # - name: Run Service Testsuite with Coverage - # run: vendor/bin/phpunit --testsuite="Services Tests" --coverage-clover=coverage-service.xml + - name: Run Service Testsuite with Coverage + run: vendor/bin/phpunit --testsuite="Services Tests" --coverage-clover=coverage-service.xml - # - name: Upload Service coverage report - # run: ./codecov upload-process --disable-search -t ${{ secrets.CODECOV_TOKEN }} -n 'service'-${{ github.run_id }} -F service -f coverage-service.xml + - name: Upload Service coverage report + run: ./codecov upload-process --disable-search -t ${{ secrets.CODECOV_TOKEN }} -n 'service'-${{ github.run_id }} -F service -f coverage-service.xml - # - name: Run Controller Testsuite with Coverage - # run: vendor/bin/phpunit --testsuite="Controllers Tests" --coverage-clover=coverage-controller.xml + - name: Run Controller Testsuite with Coverage + run: vendor/bin/phpunit --testsuite="Controllers Tests" --coverage-clover=coverage-controller.xml - # - name: Upload Controller coverage report - # run: ./codecov upload-process --disable-search -t ${{ secrets.CODECOV_TOKEN }} -n 'controller'-${{ github.run_id }} -F controller -f coverage-controller.xml + - name: Upload Controller coverage report + run: ./codecov upload-process --disable-search -t ${{ secrets.CODECOV_TOKEN }} -n 'controller'-${{ github.run_id }} -F controller -f coverage-controller.xml - # - name: Run Unit Testsuite with Coverage - # run: vendor/bin/phpunit --testsuite="Unit Tests" --coverage-clover=coverage-unit.xml + - name: Run Unit Testsuite with Coverage + run: vendor/bin/phpunit --testsuite="Unit Tests" --coverage-clover=coverage-unit.xml - # - name: Upload unit coverage report - # run: ./codecov upload-process --disable-search -t ${{ secrets.CODECOV_TOKEN }} -n 'unit'-${{ github.run_id }} -F unit -f coverage-unit.xml + - name: Upload unit coverage report + run: ./codecov upload-process --disable-search -t ${{ secrets.CODECOV_TOKEN }} -n 'unit'-${{ github.run_id }} -F unit -f coverage-unit.xml - name: Javascript tests using Jest run: npm run test diff --git a/app/Models/ImportantOne.php b/app/Models/ImportantOne.php index 7b94123..726342b 100644 --- a/app/Models/ImportantOne.php +++ b/app/Models/ImportantOne.php @@ -3,16 +3,18 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Factories\HasFactory; class ImportantOne extends Model { + use HasFactory; public function brandNewFunctionHasNoTest() { - if ( $_COOKIE['codecov'] === '' ) { - return 'we have no cookie'; + if ( is_object($this) ) { + return 'we have data'; } else { - return 'we have cookies'; + return 'we have no data'; } } diff --git a/tests/Unit/ChargeTest.php b/tests/Unit/ChargeTest.php index 7cc9c7d..13b2a5e 100644 --- a/tests/Unit/ChargeTest.php +++ b/tests/Unit/ChargeTest.php @@ -46,7 +46,7 @@ public function testReturnDataSet() { public function testUncoveredUnitTestFuction() { $charge = Charge::factory()->make(); - $result = $charge->returnDataSet(); - $this->assertEquals('data set', $result); + $result = $charge->uncoveredUnitTestFunction(); + $this->assertEquals('data', $result); } } diff --git a/tests/Unit/ImportantOneTest.php b/tests/Unit/ImportantOneTest.php new file mode 100644 index 0000000..6ef0d89 --- /dev/null +++ b/tests/Unit/ImportantOneTest.php @@ -0,0 +1,26 @@ +make(); + $result = $charge->brandNewFunctionHasNoTest(); + $this->assertEquals('we have data', $result); + } + +} From ac5d64e90577a06e110e7bb431fa889fbebc2348 Mon Sep 17 00:00:00 2001 From: vlad kobilansky Date: Mon, 24 Jun 2024 10:42:51 -0400 Subject: [PATCH 4/4] adding factory --- database/factories/ImportantOneFactory.php | 35 ++++++++++++++++++++++ tests/Unit/ImportantOneTest.php | 4 +-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 database/factories/ImportantOneFactory.php diff --git a/database/factories/ImportantOneFactory.php b/database/factories/ImportantOneFactory.php new file mode 100644 index 0000000..5a2e73c --- /dev/null +++ b/database/factories/ImportantOneFactory.php @@ -0,0 +1,35 @@ + 99, + 'status' => 'active', + 'created' => now(), + 'created_at' => now(), + 'object' => 'important_row', + 'transaction_id' => Str::random(10), + ]; + } +} diff --git a/tests/Unit/ImportantOneTest.php b/tests/Unit/ImportantOneTest.php index 6ef0d89..e5f9adf 100644 --- a/tests/Unit/ImportantOneTest.php +++ b/tests/Unit/ImportantOneTest.php @@ -18,8 +18,8 @@ class ImportantOneTest extends TestCase public function testBrandNewFunctionHasNoTest() { - $charge = Charge::factory()->make(); - $result = $charge->brandNewFunctionHasNoTest(); + $importantOne = ImportantOne::factory()->make(); + $result = $importantOne->brandNewFunctionHasNoTest(); $this->assertEquals('we have data', $result); }