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

Add code coverage github action #69

Closed
30 changes: 30 additions & 0 deletions .github/workflows/aqua.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Aqua
on:
pull_request:
branches:
- main

jobs:
aqua:
name: Aqua scanner
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Aqua scanner
uses: docker://aquasec/aqua-scanner
with:
args: trivy fs --sast --reachability --scanners config,vuln,secret .
# To customize which severities add the following flag: --severity UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
# To enable SAST scanning, add: --sast
# To enable reachability scanning, add: --reachability
# To enable npm/dotnet non-lock file scanning, add: --package-json / --dotnet-proj
env:
AQUA_KEY: ${{ secrets.AQUA_KEY }}
AQUA_SECRET: ${{ secrets.AQUA_SECRET }}
GITHUB_TOKEN: ${{ github.token }}
AQUA_URL: https://api.eu-1.supply-chain.cloud.aquasec.com
CSPM_URL: https://eu-1.api.cloudsploit.com
TRIVY_RUN_AS_PLUGIN: "aqua"
# For http/https proxy configuration add env vars: HTTP_PROXY/HTTPS_PROXY, CA-CRET (path to CA certificate)
68 changes: 68 additions & 0 deletions .github/workflows/code-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: PHPUnit Coverage Report

on:
pull_request:
branches: [master, develop]
paths:
- '.github/reporting.yml'
- '**.php'

permissions:
contents: write

jobs:
ci:
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ./

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 5.6
tools: composer:v1

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: PHPUnit
run: |
./vendor/bin/phpunit -c phpunit.ci.xml --coverage-clover=coverage.xml
env:
XDEBUG_MODE: coverage

- name: Generate Coverage report
run: |
php CoverageGenerate.php >> Coverage.md
env:
XDEBUG_MODE: coverage

- name: PHPStan Analysis
run: |
./vendor/bin/phpstan analyse --configuration=phpstan.neon --memory-limit=1024M --error-format=md --no-progress >> 'Static Analysis.md'

- name: Wiki checkout
uses: actions/checkout@v4
with:
repository: ${{github.repository}}.wiki
path: 'wiki'

- name: Push
run: |
mv Coverage.md wiki
mv 'Static Analysis.md' wiki
cd wiki
ls -la
git config user.name actions-runner
git config user.email [email protected]
git add .
git commit -m "Add Coverage and Analysis files"
git push
3 changes: 2 additions & 1 deletion src/Endpoints/Insurance.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public function subscription($subscriptionArray, $paymentId = null, $customerSes
->setRequestBody($subscriptionData);

$this->addCustomerSessionToRequest($request, $customerSessionId, $cartId);

$response = $request->post();

if ($response->isError()) {

throw new RequestException($response->errorMessage, null, $response);
}

Expand Down Expand Up @@ -163,6 +163,7 @@ protected function buildSubscriptionData($subscriptionArray, $paymentId = null)
'insurance_contract_id' => $subscription->getContractId(),
'cms_reference' => $subscription->getCmsReference(),
'product_price' => $subscription->getProductPrice(),
'cms_callback_url' => $subscription->getCallbackUrl(),
'subscriber' => [
'email' => $subscription->getSubscriber()->getEmail(),
'phone_number' => $subscription->getSubscriber()->getPhoneNumber(),
Expand Down
36 changes: 34 additions & 2 deletions src/Entities/Insurance/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,55 @@ class Subscription
*/
private $subscriber;

/**
* @var $callbackUrl;
*/
private $callbackUrl;

CONST STATE_STARTED = 'started';
CONST STATE_FAILED = 'failed';
CONST STATE_CANCELLED = 'canceled';
CONST STATE_PENDING = 'pending';

/**
* @param string $contractId
* @param string $cmsReference
* @param int $productPrice
* @param Subscriber $subscriber
* @param string $callbackUrl
*/
public function __construct(
$contractId,
$cmsReference,
$productPrice,
$subscriber
$subscriber,
$callbackUrl
)
{
$this->contractId = $contractId;
$this->cmsReference = $cmsReference;
$this->productPrice = $productPrice;
$this->subscriber = $subscriber;
$this->callbackUrl = $callbackUrl;
}

public function getAll()
{
return [
$this->contractId,
$this->cmsReference,
$this->productPrice,
$this->subscriber,
$this->callbackUrl,
];
}

/**
* @return string
*/
public function getCallbackUrl()
{
return $this->callbackUrl;
}

/**
Expand Down Expand Up @@ -71,4 +103,4 @@ public function getSubscriber()
{
return $this->subscriber;
}
}
}
12 changes: 8 additions & 4 deletions tests/Unit/Legacy/Endpoints/InsuranceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ public function subscriptionDataProvider()
'adr1',
'adr1',
null
)
),
'cancelUrl'
),
new Subscription(
'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI',
Expand All @@ -344,7 +345,8 @@ public function subscriptionDataProvider()
'adr2',
'adr2',
'1988-08-22'
)
),
'cancelUrl'
)
],
null
Expand All @@ -366,7 +368,8 @@ public function subscriptionDataProvider()
'adr1',
'adr1',
null
)
),
'cancelUrl'
),
new Subscription(
'insurance_contract_3vt2jyvWWQc9wZCmWd1KtI',
Expand All @@ -383,7 +386,8 @@ public function subscriptionDataProvider()
'adr2',
'adr2',
'1988-08-22'
)
),
'cancelUrl'
)
],
'payment_id' => 'payment_11xlpX9QQYhd3xZVzNMrtdKw4myV7QET7X'
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Legacy/Entities/Insurance/SubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Alma\API\Entities\Insurance\Subscription;
use PHPUnit\Framework\TestCase;

class SubscriptionTest extends TestCase
class SubscriptionTest extends TestCase
{
/**
* @var Subscription
Expand Down Expand Up @@ -38,7 +38,8 @@ public function createNewSubscription()
$data['insurance_contract_id'],
$data['cms_reference'],
$data['product_price'],
$this->getSubscriber()
$this->getSubscriber(),
'cancelUrl'
);
}

Expand Down
Loading