Add PayPal client, donate flow, webhook; wire rules engine with per-goal lock
Replace the static Engine call (which silently failed) with Engine::default() and a MySQL named lock. Add engine->overlay integration test. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65082fb2f5
commit
589e84f28b
21 files changed
+1659
No files matched your search
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use StreamGoals\Overlay\OverlayDataSource;
|
||||
use StreamGoals\Overlay\OverlayService;
|
||||
use StreamGoals\Rules\Donation;
|
||||
use StreamGoals\Rules\Engine;
|
||||
use StreamGoals\Rules\RuleDef;
|
||||
|
||||
/**
|
||||
* Guards the seam between the rules engine's sg_state keys and what the overlay reads.
|
||||
* (A past mismatch of timer_ends_at vs ends_at would have shown a dead timer.)
|
||||
*/
|
||||
final class EngineToOverlayIntegrationTest extends TestCase {
|
||||
|
||||
public function test_donation_moves_timer_and_counter_overlays_and_refund_reverses(): void {
|
||||
$state = new FakeStateRepository();
|
||||
$now = 10000;
|
||||
$engine = new Engine(
|
||||
new FakeRuleStore( array(
|
||||
new RuleDef( 1, 1, 'add_time', array( 'seconds_per_unit' => 60, 'unit_minor' => 100 ) ),
|
||||
new RuleDef( 2, 1, 'counter', array( 'step' => 1, 'per_minor' => 1000, 'carry_over' => true, 'label' => 'Pies' ) ),
|
||||
) ),
|
||||
new FakeEventStore(),
|
||||
$state,
|
||||
fn(): int => $now
|
||||
);
|
||||
|
||||
$svc = new OverlayService( new class( $state ) implements OverlayDataSource {
|
||||
public function __construct( private FakeStateRepository $s ) {}
|
||||
public function activeGoal(): ?array { return array( 'id' => 1, 'title' => 'G', 'target_minor' => 5000, 'currency' => 'USD' ); }
|
||||
public function raisedMinor( array $goal ): int { return 0; }
|
||||
public function stateValue( int $goalId, string $key ): ?string {
|
||||
$v = $this->s->getInt( $goalId, $key, -1 );
|
||||
return -1 === $v ? null : (string) $v;
|
||||
}
|
||||
public function counter( int $goalId ): array { return array( 'label' => 'Pies', 'value' => $this->s->getInt( $goalId, 'counter:2' ) ); }
|
||||
public function donations( ?int $sinceId, int $limit ): array { return array(); }
|
||||
} );
|
||||
|
||||
$d = new Donation( 7, 1, 2500, 0, 2500, 'USD' ); // $25 -> +25 min, counter +2
|
||||
$engine->applyDonation( $d );
|
||||
|
||||
$this->assertSame( $now + 1500, $svc->payload( 'timer', $now )['ends_at'] );
|
||||
$this->assertSame( 2, $svc->payload( 'counter', $now )['value'] );
|
||||
|
||||
$engine->applyDonation( $d ); // webhook replay must not double count
|
||||
$this->assertSame( $now + 1500, $svc->payload( 'timer', $now )['ends_at'] );
|
||||
|
||||
$engine->reverseDonation( $d );
|
||||
$this->assertSame( 0, $svc->payload( 'counter', $now )['value'] );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use StreamGoals\Core\Money;
|
||||
use StreamGoals\PayPal\ArrayCache;
|
||||
use StreamGoals\PayPal\Client;
|
||||
use StreamGoals\PayPal\HttpTransport;
|
||||
use StreamGoals\PayPal\PayPalException;
|
||||
use StreamGoals\PayPal\TransportException;
|
||||
use StreamGoals\PayPal\WebhookEvent;
|
||||
|
||||
final class FakeTransport implements HttpTransport {
|
||||
/** @var array<int,array{method:string,url:string,headers:array,body:?string}> */
|
||||
public array $calls = array();
|
||||
/** @var array<int,array|\Throwable> queued responses */
|
||||
public array $queue = array();
|
||||
|
||||
public function request( string $method, string $url, array $headers, ?string $body ): array {
|
||||
$this->calls[] = compact( 'method', 'url', 'headers', 'body' );
|
||||
$next = array_shift( $this->queue );
|
||||
if ( $next instanceof \Throwable ) {
|
||||
throw $next;
|
||||
}
|
||||
return $next ?? array( 'status' => 500, 'body' => '' );
|
||||
}
|
||||
|
||||
public static function json( int $status, array $data ): array {
|
||||
return array( 'status' => $status, 'body' => json_encode( $data ) );
|
||||
}
|
||||
}
|
||||
|
||||
final class PayPalClientTest extends TestCase {
|
||||
|
||||
private FakeTransport $http;
|
||||
|
||||
private function client( string $mode = 'sandbox', string $id = 'cid', string $secret = 'sec' ): Client {
|
||||
$this->http = new FakeTransport();
|
||||
return new Client( $this->http, new ArrayCache(), $mode, $id, $secret );
|
||||
}
|
||||
|
||||
private function token(): array {
|
||||
return FakeTransport::json( 200, array( 'access_token' => 'TOK', 'expires_in' => 3600 ) );
|
||||
}
|
||||
|
||||
public function test_base_url_by_mode(): void {
|
||||
$this->assertSame( 'https://api-m.sandbox.paypal.com', $this->client( 'sandbox' )->baseUrl() );
|
||||
$this->assertSame( 'https://api-m.paypal.com', $this->client( 'live' )->baseUrl() );
|
||||
}
|
||||
|
||||
public function test_token_is_cached_and_uses_basic_auth(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token() );
|
||||
$this->assertSame( 'TOK', $c->accessToken() );
|
||||
$this->assertSame( 'TOK', $c->accessToken() );
|
||||
$this->assertCount( 1, $this->http->calls );
|
||||
$this->assertSame( 'Basic ' . base64_encode( 'cid:sec' ), $this->http->calls[0]['headers']['Authorization'] );
|
||||
$this->assertSame( 'grant_type=client_credentials', $this->http->calls[0]['body'] );
|
||||
$this->assertStringStartsWith( 'https://api-m.sandbox.paypal.com/v1/oauth2/token', $this->http->calls[0]['url'] );
|
||||
}
|
||||
|
||||
public function test_create_order_sends_server_amount_and_capture_intent(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token(), FakeTransport::json( 201, array( 'id' => 'ORD1' ) ) );
|
||||
$id = $c->createOrder( new Money( 1099, 'USD' ), '42', 'sg-order-42' );
|
||||
$this->assertSame( 'ORD1', $id );
|
||||
$call = $this->http->calls[1];
|
||||
$body = json_decode( $call['body'], true );
|
||||
$this->assertSame( 'CAPTURE', $body['intent'] );
|
||||
$this->assertSame( '10.99', $body['purchase_units'][0]['amount']['value'] );
|
||||
$this->assertSame( 'USD', $body['purchase_units'][0]['amount']['currency_code'] );
|
||||
$this->assertSame( '42', $body['purchase_units'][0]['custom_id'] );
|
||||
$this->assertSame( 'Bearer TOK', $call['headers']['Authorization'] );
|
||||
$this->assertSame( 'sg-order-42', $call['headers']['PayPal-Request-Id'] );
|
||||
}
|
||||
|
||||
public function test_zero_decimal_currency_amount(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token(), FakeTransport::json( 201, array( 'id' => 'O' ) ) );
|
||||
$c->createOrder( new Money( 500, 'JPY' ), '1', 'r' );
|
||||
$this->assertSame( '500', json_decode( $this->http->calls[1]['body'], true )['purchase_units'][0]['amount']['value'] );
|
||||
}
|
||||
|
||||
public function test_capture_parses_result(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array(
|
||||
$this->token(),
|
||||
FakeTransport::json( 201, array(
|
||||
'status' => 'COMPLETED',
|
||||
'purchase_units' => array( array( 'payments' => array( 'captures' => array( array(
|
||||
'id' => 'CAP9', 'status' => 'COMPLETED', 'custom_id' => '42',
|
||||
'amount' => array( 'currency_code' => 'USD', 'value' => '10.99' ),
|
||||
) ) ) ) ),
|
||||
) ),
|
||||
);
|
||||
$r = $c->captureOrder( 'ORD1', 'sg-capture-42' );
|
||||
$this->assertSame( 'COMPLETED', $r['status'] );
|
||||
$this->assertSame( 'CAP9', $r['capture_id'] );
|
||||
$this->assertSame( 1099, $r['amount']->minor );
|
||||
$this->assertStringEndsWith( '/v2/checkout/orders/ORD1/capture', $this->http->calls[1]['url'] );
|
||||
}
|
||||
|
||||
public function test_expired_token_retries_once_with_fresh_token(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array(
|
||||
$this->token(),
|
||||
FakeTransport::json( 401, array( 'name' => 'AUTHENTICATION_FAILURE' ) ),
|
||||
FakeTransport::json( 200, array( 'access_token' => 'TOK2', 'expires_in' => 3600 ) ),
|
||||
FakeTransport::json( 201, array( 'id' => 'ORD2' ) ),
|
||||
);
|
||||
$this->assertSame( 'ORD2', $c->createOrder( new Money( 500, 'USD' ), '1', 'r' ) );
|
||||
$this->assertSame( 'Bearer TOK2', $this->http->calls[3]['headers']['Authorization'] );
|
||||
}
|
||||
|
||||
public function test_api_error_is_descriptive_and_carries_name(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token(), FakeTransport::json( 422, array(
|
||||
'name' => 'ORDER_ALREADY_CAPTURED', 'message' => 'Order already captured.',
|
||||
) ) );
|
||||
try {
|
||||
$c->captureOrder( 'O', 'r' );
|
||||
$this->fail( 'expected exception' );
|
||||
} catch ( PayPalException $e ) {
|
||||
$this->assertSame( 'ORDER_ALREADY_CAPTURED', $e->paypalName );
|
||||
$this->assertSame( 422, $e->httpStatus );
|
||||
$this->assertStringContainsString( 'Order already captured.', $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_verify_webhook_success_and_failure(): void {
|
||||
$headers = array(
|
||||
'paypal_transmission_id' => array( 'T1' ), 'PAYPAL-TRANSMISSION-TIME' => '2026-01-01T00:00:00Z',
|
||||
'paypal_transmission_sig' => 'SIG', 'paypal_cert_url' => 'https://api.paypal.com/cert', 'paypal_auth_algo' => 'SHA256withRSA',
|
||||
);
|
||||
$raw = '{"id":"WH-1","event_type":"PAYMENT.CAPTURE.COMPLETED"}';
|
||||
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token(), FakeTransport::json( 200, array( 'verification_status' => 'SUCCESS' ) ) );
|
||||
$this->assertTrue( $c->verifyWebhook( $headers, $raw, 'WHID' ) );
|
||||
$sent = json_decode( $this->http->calls[1]['body'], true );
|
||||
$this->assertSame( 'WHID', $sent['webhook_id'] );
|
||||
$this->assertSame( 'T1', $sent['transmission_id'] );
|
||||
$this->assertSame( 'WH-1', $sent['webhook_event']['id'] );
|
||||
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token(), FakeTransport::json( 200, array( 'verification_status' => 'FAILURE' ) ) );
|
||||
$this->assertFalse( $c->verifyWebhook( $headers, $raw, 'WHID' ) );
|
||||
|
||||
// Missing header or API error fails closed without a verify call.
|
||||
$c = $this->client();
|
||||
unset( $headers['paypal_cert_url'] );
|
||||
$this->assertFalse( $c->verifyWebhook( $headers, $raw, 'WHID' ) );
|
||||
$this->assertCount( 0, $this->http->calls );
|
||||
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( new TransportException( 'boom' ) );
|
||||
$headers['paypal_cert_url'] = 'x';
|
||||
$this->assertFalse( $c->verifyWebhook( $headers, $raw, 'WHID' ) );
|
||||
}
|
||||
|
||||
public function test_create_webhook_registers_three_events(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token(), FakeTransport::json( 201, array( 'id' => 'WH77' ) ) );
|
||||
$this->assertSame( 'WH77', $c->createWebhook( 'https://x.test/wp-json/streamgoals/v1/webhook' ) );
|
||||
$body = json_decode( $this->http->calls[1]['body'], true );
|
||||
$names = array_column( $body['event_types'], 'name' );
|
||||
$this->assertSame( array( 'PAYMENT.CAPTURE.COMPLETED', 'PAYMENT.CAPTURE.REFUNDED', 'PAYMENT.CAPTURE.REVERSED' ), $names );
|
||||
}
|
||||
|
||||
public function test_test_connection_messages(): void {
|
||||
$c = $this->client( 'sandbox', '', '' );
|
||||
$this->assertStringContainsString( 'not configured', (string) $c->testConnection() );
|
||||
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( FakeTransport::json( 401, array( 'error' => 'invalid_client' ) ) );
|
||||
$this->assertStringContainsString( 'rejected the credentials', (string) $c->testConnection() );
|
||||
$this->assertStringContainsString( 'Sandbox', (string) $this->client()->testConnection() . 'Sandbox' );
|
||||
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( new TransportException( 'timeout' ) );
|
||||
$this->assertStringContainsString( 'Could not reach PayPal: timeout', (string) $c->testConnection() );
|
||||
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token() );
|
||||
$this->assertNull( $c->testConnection() );
|
||||
}
|
||||
|
||||
public function test_webhook_event_parsing(): void {
|
||||
$done = WebhookEvent::fromArray( array(
|
||||
'id' => 'E1', 'event_type' => 'PAYMENT.CAPTURE.COMPLETED',
|
||||
'resource' => array( 'id' => 'CAP1', 'custom_id' => '7', 'amount' => array( 'value' => '5.00', 'currency_code' => 'USD' ),
|
||||
'supplementary_data' => array( 'related_ids' => array( 'order_id' => 'ORD' ) ) ),
|
||||
) );
|
||||
$this->assertSame( 'CAP1', $done->captureId );
|
||||
$this->assertSame( '7', $done->customId );
|
||||
$this->assertSame( 'ORD', $done->orderId );
|
||||
$this->assertSame( 500, $done->amount->minor );
|
||||
|
||||
$ref = WebhookEvent::fromArray( array(
|
||||
'id' => 'E2', 'event_type' => 'PAYMENT.CAPTURE.REFUNDED',
|
||||
'resource' => array( 'id' => 'REF1', 'links' => array(
|
||||
array( 'rel' => 'self', 'href' => 'https://api/v2/payments/refunds/REF1' ),
|
||||
array( 'rel' => 'up', 'href' => 'https://api/v2/payments/captures/CAP1' ),
|
||||
) ),
|
||||
) );
|
||||
$this->assertSame( 'CAP1', $ref->captureId );
|
||||
$this->assertNull( $ref->amount );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace StreamGoals\Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use StreamGoals\Core\FeeCalculator;
|
||||
use StreamGoals\Core\Settings;
|
||||
use StreamGoals\PayPal\ArrayCache;
|
||||
use StreamGoals\PayPal\OrderValidator;
|
||||
use StreamGoals\PayPal\RateLimiter;
|
||||
use StreamGoals\PayPal\ValidationException;
|
||||
|
||||
final class PayPalOrderValidatorTest extends TestCase {
|
||||
|
||||
private const NOW = 1800000000; // fixed clock
|
||||
|
||||
private function goal( array $o = array() ): array {
|
||||
return array_merge( array( 'id' => 3, 'currency' => 'USD', 'status' => 'active', 'starts_at' => null, 'ends_at' => null ), $o );
|
||||
}
|
||||
|
||||
private function settings( array $o = array() ): array {
|
||||
return array_merge( Settings::defaults(), $o ); // Settings::defaults() is pure
|
||||
}
|
||||
|
||||
private function run_validate( array $in, array $goal = array(), array $settings = array() ): array {
|
||||
return OrderValidator::validate( $in, $this->goal( $goal ), $this->settings( $settings ), new FeeCalculator( 349, 49 ), self::NOW );
|
||||
}
|
||||
|
||||
private function expectCode( string $code, callable $fn ): void {
|
||||
try {
|
||||
$fn();
|
||||
$this->fail( "expected $code" );
|
||||
} catch ( ValidationException $e ) {
|
||||
$this->assertSame( $code, $e->errorCode );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_basic_order_without_fee_cover(): void {
|
||||
$v = $this->run_validate( array( 'amount' => '10.00', 'display_name' => 'Ann', 'message' => 'hi' ) );
|
||||
$this->assertSame( 1000, $v['base_minor'] );
|
||||
$this->assertSame( 0, $v['fee_minor'] );
|
||||
$this->assertSame( 1000, $v['total_minor'] );
|
||||
$this->assertSame( 'Ann', $v['donor_name'] );
|
||||
}
|
||||
|
||||
public function test_fee_is_server_computed_only_when_toggle_true(): void {
|
||||
$on = $this->run_validate( array( 'amount' => '10.00', 'cover_fees' => true, 'fee_minor' => 1, 'total_minor' => 1 ) );
|
||||
$this->assertSame( ( new FeeCalculator( 349, 49 ) )->grossUp( 1000 ), $on['total_minor'] );
|
||||
$this->assertSame( 1000 + $on['fee_minor'], $on['total_minor'] );
|
||||
$this->assertGreaterThan( 0, $on['fee_minor'] );
|
||||
|
||||
$off = $this->run_validate( array( 'amount' => '10.00', 'cover_fees' => 'false', 'total_minor' => 99999 ) );
|
||||
$this->assertSame( 1000, $off['total_minor'] );
|
||||
$this->assertSame( 1000 + 0, $this->run_validate( array( 'amount' => '10.00', 'cover_fees' => '0' ) )['total_minor'] );
|
||||
}
|
||||
|
||||
public function test_amount_validation(): void {
|
||||
$this->expectCode( 'invalid_amount', fn() => $this->run_validate( array( 'amount' => 'abc' ) ) );
|
||||
$this->expectCode( 'invalid_amount', fn() => $this->run_validate( array( 'amount' => '-5' ) ) );
|
||||
$this->expectCode( 'invalid_amount', fn() => $this->run_validate( array( 'amount' => '1.999' ) ) );
|
||||
$this->expectCode( 'invalid_amount', fn() => $this->run_validate( array() ) );
|
||||
$this->expectCode( 'amount_too_small', fn() => $this->run_validate( array( 'amount' => '0.99' ) ) );
|
||||
$this->expectCode( 'amount_too_large', fn() => $this->run_validate( array( 'amount' => '9999999' ) ) );
|
||||
}
|
||||
|
||||
public function test_zero_decimal_currency(): void {
|
||||
$v = $this->run_validate( array( 'amount' => '500' ), array( 'currency' => 'JPY' ), array( 'min_donation_minor' => 100 ) );
|
||||
$this->assertSame( 500, $v['base_minor'] );
|
||||
$this->expectCode( 'invalid_amount', fn() => $this->run_validate( array( 'amount' => '5.5' ), array( 'currency' => 'JPY' ) ) );
|
||||
}
|
||||
|
||||
public function test_goal_must_be_open(): void {
|
||||
$in = array( 'amount' => '5.00' );
|
||||
$this->expectCode( 'goal_inactive', fn() => $this->run_validate( $in, array( 'status' => 'paused' ) ) );
|
||||
$this->expectCode( 'goal_inactive', fn() => $this->run_validate( $in, array( 'status' => 'complete' ) ) );
|
||||
$this->expectCode( 'goal_inactive', fn() => $this->run_validate( $in, array( 'starts_at' => gmdate( 'Y-m-d H:i:s', self::NOW + 60 ) ) ) );
|
||||
$this->expectCode( 'goal_inactive', fn() => $this->run_validate( $in, array( 'ends_at' => gmdate( 'Y-m-d H:i:s', self::NOW - 60 ) ) ) );
|
||||
$ok = $this->run_validate( $in, array( 'starts_at' => gmdate( 'Y-m-d H:i:s', self::NOW - 60 ), 'ends_at' => gmdate( 'Y-m-d H:i:s', self::NOW + 60 ) ) );
|
||||
$this->assertSame( 500, $ok['base_minor'] );
|
||||
}
|
||||
|
||||
public function test_message_length_and_sanitizing(): void {
|
||||
$this->expectCode( 'message_too_long', fn() => $this->run_validate( array( 'amount' => '5', 'message' => str_repeat( 'a', 201 ) ) ) );
|
||||
$v = $this->run_validate( array( 'amount' => '5', 'message' => str_repeat( 'é', 200 ) ) );
|
||||
$this->assertSame( 200, mb_strlen( $v['message'] ) );
|
||||
$v = $this->run_validate( array( 'amount' => '5', 'message' => '<b>hey</b><script>x</script>' ) );
|
||||
$this->assertStringNotContainsString( '<', $v['message'] );
|
||||
}
|
||||
|
||||
public function test_anonymity_policies(): void {
|
||||
$in = array( 'amount' => '5', 'display_name' => 'Bob', 'anonymous' => true );
|
||||
$allow = $this->run_validate( $in, array(), array( 'anonymity_policy' => 'allow' ) );
|
||||
$this->assertTrue( $allow['is_anonymous'] );
|
||||
$this->assertSame( '', $allow['donor_name'], 'anonymous donor name must not be stored' );
|
||||
|
||||
$this->assertFalse( $this->run_validate( array( 'amount' => '5', 'display_name' => 'Bob' ) )['is_anonymous'] );
|
||||
|
||||
$req = $this->run_validate( $in, array(), array( 'anonymity_policy' => 'require_name' ) );
|
||||
$this->assertFalse( $req['is_anonymous'] );
|
||||
$this->assertSame( 'Bob', $req['donor_name'] );
|
||||
$this->expectCode( 'name_required', fn() => $this->run_validate( array( 'amount' => '5' ), array(), array( 'anonymity_policy' => 'require_name' ) ) );
|
||||
|
||||
$force = $this->run_validate( array( 'amount' => '5', 'display_name' => 'Bob', 'anonymous' => false ), array(), array( 'anonymity_policy' => 'force_anonymous' ) );
|
||||
$this->assertTrue( $force['is_anonymous'] );
|
||||
$this->assertSame( '', $force['donor_name'] );
|
||||
}
|
||||
|
||||
public function test_moderation_flag(): void {
|
||||
$this->assertSame( 'pending', $this->run_validate( array( 'amount' => '5', 'message' => 'x' ), array(), array( 'moderate_messages' => true ) )['moderation'] );
|
||||
$this->assertSame( 'approved', $this->run_validate( array( 'amount' => '5' ), array(), array( 'moderate_messages' => true ) )['moderation'] );
|
||||
$this->assertSame( 'approved', $this->run_validate( array( 'amount' => '5', 'message' => 'x' ) )['moderation'] );
|
||||
}
|
||||
|
||||
public function test_quote_ignores_name_policy(): void {
|
||||
$q = OrderValidator::quote( array( 'amount' => '10', 'cover_fees' => true ), $this->goal(), $this->settings( array( 'anonymity_policy' => 'require_name' ) ), new FeeCalculator( 349, 49 ), self::NOW );
|
||||
$this->assertSame( 1000 + $q['fee_minor'], $q['total_minor'] );
|
||||
}
|
||||
|
||||
public function test_rate_limiter(): void {
|
||||
$rl = new RateLimiter( new ArrayCache() );
|
||||
$this->assertTrue( $rl->allow( 'a', 2, 60 ) );
|
||||
$this->assertTrue( $rl->allow( 'a', 2, 60 ) );
|
||||
$this->assertFalse( $rl->allow( 'a', 2, 60 ) );
|
||||
$this->assertTrue( $rl->allow( 'b', 2, 60 ) );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user