Skip to content

Commit

Permalink
Merge pull request #57 from vlad-ko/feature/enable-tests
Browse files Browse the repository at this point in the history
adding a fake test
  • Loading branch information
vlad-ko committed Aug 22, 2024
2 parents 0061c7d + ac5d64e commit 3312600
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 16 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/pr-only.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion app/Models/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function getDataForReport()
}

public function uncoveredUnitTestFunction() {
return 'data';
if (true) {
return 'data';
}
}

public function unitTestModel() {
Expand Down
8 changes: 5 additions & 3 deletions app/Models/ImportantOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

Expand Down
35 changes: 35 additions & 0 deletions database/factories/ImportantOneFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Database\Factories;

use App\Models\ImportantOne;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use Faker\Generator as Faker;

class ImportantOneFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = ImportantOne::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'value' => 99,
'status' => 'active',
'created' => now(),
'created_at' => now(),
'object' => 'important_row',
'transaction_id' => Str::random(10),
];
}
}
7 changes: 7 additions & 0 deletions tests/Unit/ChargeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@ public function testReturnDataSet() {
$result = $charge->returnDataSet();
$this->assertEquals('data set', $result);
}

public function testUncoveredUnitTestFuction() {

$charge = Charge::factory()->make();
$result = $charge->uncoveredUnitTestFunction();
$this->assertEquals('data', $result);
}
}
26 changes: 26 additions & 0 deletions tests/Unit/ImportantOneTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Models\ImportantOne;

class ImportantOneTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/

public function testBrandNewFunctionHasNoTest() {

$importantOne = ImportantOne::factory()->make();
$result = $importantOne->brandNewFunctionHasNoTest();
$this->assertEquals('we have data', $result);
}

}

0 comments on commit 3312600

Please sign in to comment.