<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

class AbgleichAPITest extends \PHPUnit\Framework\TestCase
{
  /**
   * @var AbgleichAPI
   */
  protected $object;

  protected function setUp(): void
  {
    $this->object = new \AbgleichAPI();
  }

  protected function tearDown(): void
  {
  }

  /**
   * @test
   */
  public function testPing()
  {
    if (\SessionOperations::isDmzBetrieb()) {
      $msg = $this->object->sendPingMessage();
      $version = \Version::getCurrentVersion()->version;
      $matches = array();
      preg_match('&^(([0-9]+\\.){3})0?([0-9]+)$&', $version, $matches);
      $version = $matches[1] . $matches[3];
      $this->assertEquals($version, $msg);
    } else {
      $this->expectException(\AbgleichApiException::class);
      $this->object->sendPingMessage();
    }
  }
}
