Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
Trying to get unit tests going? Since this is not an actual laravel project, and is a package instead I'm not sure how to test. Going to have to do some research.
  • Loading branch information
levizoesch committed Oct 22, 2023
1 parent f2922d7 commit d32f224
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 23 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/tellersdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ jobs:
- name: Set Environment Variables
run: sed -i "s/TELLER_TEST_TOKEN=.*/TELLER_TEST_TOKEN=${{ secrets.TELLER_TEST_TOKEN }}/" .env

# - name: Run Tests
# run: ./vendor/bin/phpunit -c phpunit.xml --coverage-clover=coverage.xml ;
- name: PHPUnit Tests
uses: php-actions/phpunit@v3
env:
XDEBUG_MODE: coverage
with:
bootstrap: vendor/autoload.php
configuration: phpunit.xml
php_extensions: xdebug
args: tests --coverage-clover ./coverage.xml
- name: Run Tests
run: ./vendor/bin/phpunit -c phpunit.xml --coverage-clover=coverage.xml ;
# - name: PHPUnit Tests
# uses: php-actions/phpunit@v3
# env:
# XDEBUG_MODE: coverage
# with:
# bootstrap: vendor/autoload.php
# configuration: phpunit.xml
# php_extensions: xdebug
# args: tests --coverage-clover ./coverage.xml

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
Expand Down
10 changes: 10 additions & 0 deletions src/Exceptions/MissingAccessTokenException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace LeviZoesch\TellerSDK\Exceptions;

use Exception;

class MissingAccessTokenException extends Exception
{

}
7 changes: 7 additions & 0 deletions src/TellerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LeviZoesch\TellerSDK;

use LeviZoesch\TellerSDK\Enums\EnvironmentTypes;
use LeviZoesch\TellerSDK\Exceptions\MissingAccessTokenException;
use LeviZoesch\TellerSDK\Exceptions\MissingTellerConfigurationException;

class TellerClient
Expand All @@ -11,8 +12,14 @@ class TellerClient

private string $access_token;

/**
* @throws MissingAccessTokenException
*/
public function __construct($accessToken)
{
if ($accessToken === null){
throw new MissingAccessTokenException();
}
$this->access_token = $accessToken;
}

Expand Down
5 changes: 3 additions & 2 deletions tests/TestCase.php → tests/BaseTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
namespace LeviZoesch\TellerSDK\Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

use Orchestra\Testbench\Concerns\CreatesApplication;
use Illuminate\Foundation\Testing\TestCase;

abstract class TestCase extends BaseTestCase
abstract class BaseTest extends TestCase
{
use CreatesApplication;
}
18 changes: 11 additions & 7 deletions tests/TellerClientTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
<?php

namespace LeviZoesch\TellerSDK\Tests;
use LeviZoesch\TellerSDK\Exceptions\MissingAccessTokenException;
use LeviZoesch\TellerSDK\Exceptions\MissingTellerConfigurationException;
use LeviZoesch\TellerSDK\TellerClient;

class TellerClientTest extends TestCase
class TellerClientTest extends BaseTest
{

public function testListAccounts()
{
$teller = new TellerClient(config('teller.TEST_TOKEN'));
$result = $teller->listAccounts();
$this->assertJson($result);
}
// /**
// * @throws MissingAccessTokenException
// */
// public function testListAccounts()
// {
// $teller = new TellerClient(config('teller.TEST_TOKEN'));
// $result = $teller->listAccounts();
// $this->assertJson($result);
// }

public function testTellerTestTokenIsNotDefined()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TellerEnvironmentTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use LeviZoesch\TellerSDK\Enums\EnvironmentTypes;

class TellerEnvironmentTypesTest extends TestCase
class TellerEnvironmentTypesTest extends BaseTest
{

public function testEnvironmentTypeSandbox() {
Expand Down
4 changes: 2 additions & 2 deletions tests/TellerSDKServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use LeviZoesch\TellerSDK\TellerSDKServiceProvider;
use LeviZoesch\TellerSDK\Tests\TestCase;
use LeviZoesch\TellerSDK\Tests\BaseTest;

class TellerSDKServiceProviderTest extends TestCase
class TellerSDKServiceProviderTest extends BaseTest
{
protected function getPackageProviders($app): array
{
Expand Down

0 comments on commit d32f224

Please sign in to comment.