Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding a fake test #57

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}
Loading