<?php
namespace ccxt;

// ----------------------------------------------------------------------------

// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

// -----------------------------------------------------------------------------
include_once PATH_TO_CCXT . '/test/exchange/base/test_market.php';

function test_fetch_markets($exchange, $skipped_properties) {
    $method = 'fetchMarkets';
    $markets = $exchange->fetch_markets();
    assert(is_array($markets), $exchange->id . ' ' . $method . ' must return an object. ' . $exchange->json($markets));
    $market_values = is_array($markets) ? array_values($markets) : array();
    assert_non_emtpy_array($exchange, $skipped_properties, $method, $market_values);
    for ($i = 0; $i < count($market_values); $i++) {
        test_market($exchange, $skipped_properties, $method, $market_values[$i]);
    }
    detect_market_conflicts($exchange, $markets);
    return true;
}


function detect_market_conflicts($exchange, $market_values) {
    // detect if there are markets with different ids for the same symbol
    $ids = array();
    for ($i = 0; $i < count($market_values); $i++) {
        $market = $market_values[$i];
        $symbol = $market['symbol'];
        if (!(is_array($ids) && array_key_exists($symbol, $ids))) {
            $ids[$symbol] = $market['id'];
        } else {
            $is_different = $ids[$symbol] !== $market['id'];
            assert(!$is_different, $exchange->id . ' fetchMarkets() has different ids for the same symbol: ' . $symbol . ' ' . $ids[$symbol] . ' ' . $market['id']);
        }
    }
    return true;
}
