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

Fix test suite #108 #426

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions .github/workflows/test_suite.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Code Test Suite

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
tests:
runs-on: ubuntu-latest

# Test on multiple PHP versions
strategy:
matrix:
php-version: ["8.2"]

services:
mariadb:
image: mariadb:10.11
env:
MYSQL_DATABASE: micro_power_manager
MYSQL_ROOT_PASSWORD: wF9zLp2qRxaS2e
ports:
- 3306:3306

steps:
# Checkout code
- uses: actions/checkout@v3

# Setup PHP with extensions
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, dom, fileinfo, mysql
coverage: xdebug

# Setup GitHub environment
- name: Copy .env
run: php -r "file_exists('./dev/.env.micropowermanager-backend') || copy('./dev/.env.micropowermanager-backend', '.env');"

# Install composer dependencies
- name: Install Composer Dependencies
run: |
composer install --no-interaction --prefer-dist
composer dump-autoload
working-directory: ./src/backend

# Generate application key
# - name: Generate key
# run: php artisan key:generate
# working-directory: ./src/backend

# Run database migrations for testing
# - name: Run Migrations
# run: |
# php artisan migrate --env=.env
# php artisan migrate-tenant --env=.env

# Run PHPUnit tests with coverage
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: php artisan test
continue-on-error: true
working-directory: ./src/backend
2 changes: 1 addition & 1 deletion src/backend/app/Models/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function assetType(): BelongsTo {
}

public function agentAssignedAppliance(): HasMany {
return $this->hasMany(AgentAssignedAppliances::class, 'appliance_type_id', 'id');
return $this->hasMany(AgentAssignedAppliances::class, 'appliance_id', 'id');
}

public function rates(): HasMany {
Expand Down
3 changes: 2 additions & 1 deletion src/backend/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"Inensus\\GomeLongMeter\\": "packages/inensus/gome-long-meter/src",
"Inensus\\WavecomPaymentProvider\\": "packages/inensus/wavecom-payment-provider/src",
"Inensus\\DalyBms\\": "packages/inensus/daly-bms/src",
"Inensus\\AngazaSHS\\": "packages/inensus/angaza-shs/src"
"Inensus\\AngazaSHS\\": "packages/inensus/angaza-shs/src",
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
Expand Down
2 changes: 1 addition & 1 deletion src/backend/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true">
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
Expand Down
11 changes: 6 additions & 5 deletions src/backend/tests/Unit/AgentSellApplianceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use App\Models\AgentAssignedAppliances;
use App\Models\AgentCommission;
use App\Models\AgentSoldAppliance;
use App\Models\AssetType;
use App\Models\Asset;
use App\Models\Cluster;
use App\Models\MiniGrid;
use App\Models\PaymentHistory;
use Database\Factories\PersonFactory;
use Database\Factories\Person\PersonFactory;
use Database\Factories\UserFactory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
Expand Down Expand Up @@ -81,7 +81,7 @@ public function initData() {
'agent_commission_id' => 1,
'device_id' => 1,
'name' => 'alper',
'email' => 'a@b.com',
'email' => 'a@a.com',
'fire_base_token' => 'sadadadasd3',
'password' => '123123',
]);
Expand All @@ -93,15 +93,16 @@ public function initData() {
'risk_balance' => -3,
]);

AssetType::query()->create([
Asset::query()->create([
'name' => 'test',
'price' => 100,
'asset_type_id' => 1,
]);

AgentAssignedAppliances::query()->create([
'agent_id' => 1,
'user_id' => 1,
'appliance_type_id' => 1,
'appliance_id' => 1,
'cost' => 100,
]);
}
Expand Down
Loading