Skip to content

Commit

Permalink
feat: Test coverage (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored May 2, 2023
1 parent d348d97 commit d9901af
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 24 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI
on:
push:
branches:
- master
tags:
- v[0-9]+.[0-9]+.[0-9]+*
pull_request:
branches:
- master
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up php 8.0
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
- name: 'Create env file'
run: |
touch ${{ github.workspace }}/tests/.env
echo RAZORPAY_API_KEY=${{ secrets.RAZORPAY_API_KEY }} >> ${{ github.workspace }}/tests/.env
echo RAZORPAY_API_SECRET=${{ secrets.RAZORPAY_API_SECRET }} >> ${{ github.workspace }}/tests/.env
cat ${{ github.workspace }}/tests/.env
- name: Install dependencies
run: composer self-update && composer install && composer require vlucas/phpdotenv && composer dump-autoload
- name: Run tests and collect coverage
run: vendor/bin/phpunit ./tests/CoverageTest.php --coverage-clover coverage.xml .
env:
RAZORPAY_API_KEY: ${{ secrets.RAZORPAY_API_KEY }}
RAZORPAY_API_SECRET: ${{ secrets.RAZORPAY_API_SECRET }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
66 changes: 66 additions & 0 deletions tests/ApiTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Razorpay\Tests;

use Razorpay\Api\Request;

class ApiTest extends TestCase
{

private $title = "codecov_test";

private $url = 'https://api.razorpay.com/v1/';

public function setUp(): void
{
parent::setUp();
}

/**
* Get app details
*/
public function testGetAppDetails()
{
$this->api->setAppDetails($this->title);

$data = $this->api->getAppsDetails();

$this->assertTrue(is_array($data));

$this->assertTrue($this->title==$data[0]['title']);
}

/**
* Get app details
*/
public function testSetBaseUrl()
{
$this->api->setBaseUrl($this->url);

$data = $this->api->getBaseUrl();

$this->assertTrue($this->url==$data);

}

public function testGetkey()
{
$data = $this->api->getKey();

$this->assertTrue(strlen($data) > 0);
}

public function testGetSecret()
{
$data = $this->api->getSecret();
$this->assertTrue(strlen($data) > 0);
}

public function testFullUrl()
{
$pattern = '/^(https?:\/\/)?([a-z0-9-]+\.)+[a-z]{2,}(\/.*)?$/i';
$url = $this->api->getFullUrl($this->api->getBaseUrl()."orders");
$this->assertTrue(preg_match($pattern, $url, $matches)==true);
}

}
30 changes: 30 additions & 0 deletions tests/CardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Razorpay\Tests;

use Razorpay\Api\Request;

class CardTest extends TestCase
{
/**
* Specify unique card id
*/

private $cardId = "card_LcQgzpfvWP0UKF";

public function setUp(): void
{
parent::setUp();
}

/**
* Fetch Card details
*/
public function testFetchCard()
{
$data = $this->api->card->fetch($this->cardId);

$this->assertTrue(in_array($this->cardId, $data->toArray()));
}

}
Loading

0 comments on commit d9901af

Please sign in to comment.