Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Mar 31, 2024
1 parent 50f0886 commit 8462e7e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 61 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"php-http/guzzle7-adapter": "^1.0"
},
"require-dev": {
"nunomaduro/collision": "^7.5 || ^8.0",
"larastan/larastan": "^2.0",
"orchestra/canvas": "^8.0 || ^9.0",
"orchestra/testbench": "^8.0 || ^9.0"
"nunomaduro/collision": "^7.5 || ^8.0",
"orchestra/testbench": "^8.22 || ^9.0",
"phpunit/phpunit": "^10.5"
},
"config": {
"sort-packages": true,
Expand Down
4 changes: 4 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
providers:
- Billplz\Laravel\BillplzServiceProvider

migrations: false
8 changes: 4 additions & 4 deletions tests/Feature/BillplzServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class BillplzServiceProviderTest extends TestCase
{
/** @test */
#[Test]
public function it_has_proper_signature()
{
$billplz = new BillplzServiceProvider(null);
Expand All @@ -17,7 +17,7 @@ public function it_has_proper_signature()
$this->assertSame(['billplz', 'Billplz\Client'], $billplz->provides());
}

/** @test */
#[Test]
public function it_provides_the_service()
{
config(['services.billplz.key' => 'abc']);
Expand All @@ -27,7 +27,7 @@ public function it_provides_the_service()
$this->assertSame('abc', Billplz::getApiKey());
}

/** @test */
#[Test]
public function it_can_configure_api_version()
{
config([
Expand All @@ -38,7 +38,7 @@ public function it_can_configure_api_version()
$this->assertSame('v4', Billplz::getApiVersion());
}

/** @test */
#[Test]
public function it_can_use_sandbox_environment()
{
config([
Expand Down
22 changes: 10 additions & 12 deletions tests/Feature/PaymentCompletion/RedirectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@
use Billplz\Laravel\Testing\RedirectionTests;
use Billplz\Laravel\Tests\TestCase;
use Illuminate\Support\Arr;
use PHPUnit\Framework\Attributes\Test;

class RedirectionTest extends TestCase
{
use RedirectionTests;

/**
* Setup the test environment.
*/
protected function setUp(): void
/** {@inheritDoc} */
#[\Override]
protected function defineRoutes($router): void
{
parent::setUp();

$this->app['router']->get('completed', function (Redirection $request) {
$router->get('completed', function (Redirection $request) {
return Arr::only($request->validated(), ['id', 'paid', 'transaction_id', 'transaction_status']);
});
}

/** @test */
#[Test]
public function it_can_accept_redirection_callback()
{
$this->makeSuccessfulRedirection('completed')
Expand All @@ -33,7 +31,7 @@ public function it_can_accept_redirection_callback()
]);
}

/** @test */
#[Test]
public function it_can_accept_redirection_callback_with_extra_payment_info()
{
$this->makeSuccessfulRedirection('completed', [
Expand All @@ -48,7 +46,7 @@ public function it_can_accept_redirection_callback_with_extra_payment_info()
]);
}

/** @test */
#[Test]
public function it_can_accept_redirection_callback_without_signature()
{
$this->makeSuccessfulRedirectionWithoutSignature('completed')
Expand All @@ -57,13 +55,13 @@ public function it_can_accept_redirection_callback_without_signature()
]);
}

/** @test */
#[Test]
public function it_cant_accept_redirection_callback_with_invalid_signature()
{
$this->makeUnsuccessfulRedirectionWithInvalidSignature('completed');
}

/** @test */
#[Test]
public function it_cant_accept_redirection_callback_given_bad_data()
{
$this->makeUnsuccessfulRedirection('completed');
Expand Down
24 changes: 11 additions & 13 deletions tests/Feature/PaymentCompletion/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@
use Billplz\Laravel\Testing\WebhookTests;
use Billplz\Laravel\Tests\TestCase;
use Illuminate\Support\Arr;
use PHPUnit\Framework\Attributes\Test;

class WebhookTest extends TestCase
{
use WebhookTests;

/**
* Setup the test environment.
*/
protected function setUp(): void
/** {@inheritDoc} */
#[\Override]
protected function defineRoutes($router): void
{
parent::setUp();

$this->app['router']->post('webhook', function (Webhook $request) {
$router->post('webhook', function (Webhook $request) {
return Arr::only($request->validated(), ['id', 'collection_id', 'paid', 'transaction_id', 'transaction_status']);
});
}

/** @test */
#[Test]
public function it_can_accept_webhook_callback()
{
$this->makeSuccessfulWebhook('webhook')
Expand All @@ -34,7 +32,7 @@ public function it_can_accept_webhook_callback()
]);
}

/** @test */
#[Test]
public function it_can_accept_webhook_callback_with_extra_payment_info()
{
$this->makeSuccessfulWebhook('webhook', [
Expand All @@ -49,7 +47,7 @@ public function it_can_accept_webhook_callback_with_extra_payment_info()
]);
}

/** @test */
#[Test]
public function it_can_accept_webhook_callback_when_phone_number_is_null()
{
$this->makeSuccessfulWebhook('webhook', ['mobile' => ''])
Expand All @@ -60,7 +58,7 @@ public function it_can_accept_webhook_callback_when_phone_number_is_null()
]);
}

/** @test */
#[Test]
public function it_can_accept_webhook_callback_without_signature()
{
$this->makeSuccessfulWebhookWithoutSignature('webhook')
Expand All @@ -71,13 +69,13 @@ public function it_can_accept_webhook_callback_without_signature()
]);
}

/** @test */
#[Test]
public function it_cant_accept_webhook_callback_with_invalid_signature()
{
$this->makeUnsuccessfulWebhookWithInvalidSignature('webhook');
}

/** @test */
#[Test]
public function it_cant_accept_webhook_callback_given_invalid_data()
{
$this->makeUnsuccessfulWebhook('webhook');
Expand Down
35 changes: 9 additions & 26 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Billplz\Laravel\Tests;

use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase as Testbench;

abstract class TestCase extends Testbench
{
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app): void
use WithWorkbench;

/** {@inheritDoc} */
#[\Override]
protected function defineEnvironment($app): void
{
$app['config']->set('services.billplz', [
'key' => '73eb57f0-7d4e-42b9-a544-aeac6e4b0f81',
Expand All @@ -21,29 +21,12 @@ protected function getEnvironmentSetUp($app): void
]);
}

/**
* Get package aliases.
*
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageAliases($app)
/** {@inheritDoc} */
#[\Override]
protected function getPackageAliases($app): array
{
return [
'Billplz' => \Billplz\Laravel\Billplz::class,
];
}

/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
* @return array
*/
protected function getPackageProviders($app)
{
return [
\Billplz\Laravel\BillplzServiceProvider::class,
];
}
}
7 changes: 4 additions & 3 deletions tests/Unit/Exceptions/ValidationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Billplz\Laravel\Exceptions\ValidationException;
use Mockery as m;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class ValidationExceptionTest extends TestCase
Expand All @@ -16,7 +17,7 @@ protected function tearDown(): void
m::close();
}

/** @test */
#[Test]
public function it_has_proper_signature()
{
$validator = m::mock('Illuminate\Contracts\Validation\Validator');
Expand All @@ -37,7 +38,7 @@ public function it_has_proper_signature()
$this->assertSame(['device_id' => 'The device_id is required.'], $e->errors());
}

/** @test */
#[Test]
public function it_can_override_error_bag()
{
$validator = m::mock('Illuminate\Contracts\Validation\Validator');
Expand All @@ -50,7 +51,7 @@ public function it_can_override_error_bag()
$this->assertSame('custom', $e->errorBag);
}

/** @test */
#[Test]
public function it_can_override_status_code()
{
$validator = m::mock('Illuminate\Contracts\Validation\Validator');
Expand Down

0 comments on commit 8462e7e

Please sign in to comment.