<commit_before><?php

use WireMock\Client\ListStubMappingsResult;
use WireMock\Serde\SerializerFactory;
use WireMock\Stubbing\StubMapping;

/**
 * @param StubMapping $localStubMapping
 */
function assertThatTheOnlyMappingPresentIs(StubMapping $localStubMapping)
{
    $mappingsFromServer = getMappings();
    assertThat($mappingsFromServer, is(arrayWithSize(1)));

    assertThat($mappingsFromServer[0], equalTo($localStubMapping));
}

function assertThatThereAreNoMappings()
{
    $mappings = getMappings();
    assertThat($mappings, is(emptyArray()));
}

function getMappings()
{
    $defaultSerializer = SerializerFactory::default();
    $adminJson = file_get_contents('http://localhost:8080/__admin/mappings');
    /** @var ListStubMappingsResult $listResult */
    $listResult = $defaultSerializer->deserialize($adminJson, ListStubMappingsResult::class);
    return $listResult->getMappings();<commit_msg>Log local & server stub mappings when integration assertions fail<commit_after><?php

use WireMock\Client\ListStubMappingsResult;
use WireMock\Serde\SerializerFactory;
use WireMock\Stubbing\StubMapping;

/**
 * @param StubMapping $localStubMapping
 */
function assertThatTheOnlyMappingPresentIs(StubMapping $localStubMapping)
{
    $mappingsFromServer = getMappings();
    assertThat($mappingsFromServer, is(arrayWithSize(1)));

    /** @noinspection PhpNonStrictObjectEqualityInspection */
    if ($mappingsFromServer[0] != $localStubMapping) {
        var_dump('Server', $mappingsFromServer[0], 'Local', $localStubMapping);
    }
    assertThat($mappingsFromServer[0], equalTo($localStubMapping));
}

function assertThatThereAreNoMappings()
{
    $mappings = getMappings();
    assertThat($mappings, is(emptyArray()));
}

function getMappings()
{
    $defaultSerializer = SerializerFactory::default();
    $adminJson = file_get_contents('http://localhost:8080/__admin/mappings');
    /** @var ListStubMappingsResult $listResult */
    $listResult = $defaultSerializer->deserialize($adminJson, ListStubMappingsResult::class);
    return $listResult->getMappings();
{'fraction_non_alphanumeric': 0.12771084337349398, 'fraction_numerical': 0.006746987951807229, 'mean_word_length': 6.467625899280575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3224123', 'n_tokens_mistral': 598, 'n_tokens_neox': 621, 'n_words': 94}