Skip to content

Testing ​

Against staging ​

Develop against staging (ANIKEEN_ID_MODE=staging) with an OAuth client registered there. Payments on staging run in Stripe's test mode: pay with Stripe's test cards, e.g. 4242 4242 4242 4242 with any future expiry date and any CVC. No money is charged.

Point ANIKEEN_ID_BASE_URL at your own Anikeen ID instance if you run one locally.

Unit tests ​

Swap the HTTP client for a Guzzle MockHandler, so no request leaves your test:

php
use Anikeen\Id\AnikeenId;

$mock = new \GuzzleHttp\Handler\MockHandler([
    new \GuzzleHttp\Psr7\Response(201, ['Content-Type' => 'application/json'], json_encode([
        'data' => ['id' => '01JORDER', 'status' => 'draft'],
    ])),
]);

$this->app->instance(AnikeenId::class, (new AnikeenId())->setHttpClient(new \GuzzleHttp\Client([
    'handler' => \GuzzleHttp\HandlerStack::create($mock),
    'base_uri' => 'https://id.test/api/',
])));

Your API ​

For routes behind the anikeen guard, sign a user in without a token:

php
AnikeenId::actingAs($user, ['user']);

Webhooks ​

Sign test payloads with your test secret the way Anikeen ID does – t=<timestamp>,v1=<hex HMAC-SHA256 of "t.body"> – and post them to your route:

php
config(['services.anikeen.webhook_secret' => 'whsec_test']);

$payload = json_encode(['id' => '01JEVT', 'type' => 'order.completed', 'created' => time(),
    'data' => ['object' => ['id' => '01JORDER', 'status' => 'completed']]]);
$t = time();
$signature = hash_hmac('sha256', "{$t}.{$payload}", 'whsec_test');

$this->call('POST', '/webhooks/anikeen', [], [], [], [
    'HTTP_ANIKEEN_SIGNATURE' => "t={$t},v1={$signature}",
    'CONTENT_TYPE' => 'application/json',
], $payload)->assertNoContent();

Anikeen ID developer documentation