Contract tests

  1. Using it
  2. What it asserts
  3. Mocking HTTP in tests

Contract tests are a first-class feature: the core ships RegistryDriverContractTestCase so any third-party driver can be held to the same bar as the bundled ones. This is what makes the toolkit extensible in practice, not just in theory.

Using it

Extend the case and implement two hooks. Wire your driver to a mocked PSR-18 client so the contract runs offline.

use Gawrys\Counterparty\Testing\RegistryDriverContractTestCase;
use Gawrys\Counterparty\Registry\{RegistryDriver, LookupRequest};
use Gawrys\Counterparty\Enum\RegistryCapability;
use Gawrys\Counterparty\Counterparty;

final class GermanRegistryDriverTest extends RegistryDriverContractTestCase
{
    protected function createDriver(): RegistryDriver
    {
        $http = /* JsonHttpClient over a mock PSR-18 client returning canned JSON */;

        return new GermanRegistryDriver($http);
    }

    protected function supportedRequest(): LookupRequest
    {
        return new LookupRequest(
            new Counterparty('Muster GmbH', 'DE', nip: '0000000000'),
            RegistryCapability::LegalEntityData,
        );
    }
}

What it asserts

  • The driver declares at least one capability, and capabilities are unique.
  • It serves at least one country, and every country is a valid upper-case ISO-3166-1 alpha-2 code.
  • supports() is true for every declared (country, capability) pair.
  • supports() is false for an unserved country (ZZ) and for an undeclared capability.
  • supportedRequest() is actually supported by the driver.
  • lookup() returns a well-formed LookupResult: a not-found result carries no data and no proof identifier.

Mocking HTTP in tests

The bundled tests use php-http/mock-client + nyholm/psr7. A small helper that queues JSON responses keeps tests readable - see the reference adapters’ tests in counterparty-core for a copy-paste MockHttp fixture.


Counterparty Verification - a due-diligence aid, not a compliance product. MIT licensed.

This site uses Just the Docs, a documentation theme for Jekyll.