<?php declare(strict_types=1);

use PHPUnit\Framework\TestCase;
use App\Model\Operator;
use App\Model\Storage;
use App\Model\Role;
use App\Model\Exception\StorageNotConnect;

/* require_once  '../vendor/autoload.php'; */

final class OperatorTest extends TestCase
{
    public function testCanBeReadOperatorFromStorage(): void
    {
    	$config['host'] = "192.168.15.70" ;
	$config['rdn'] = "cn=admin,dc=mc03,dc=local";
	$config['base'] = "dc=mc03,dc=local";
	$config['pass'] = "admin";

	$storage = new Storage($config);
	
	$operator1 = Operator::GetByName("Бондарь Елена Ивановна", $storage);
	$operator2 = Operator::GetByName("Шапель Алексей Михайлович", $storage);
	
        $this->assertSame($operator1->role, Role::Operator);
	$this->assertSame($operator1->login, "bondar");

	$this->assertSame($operator2->role, Role::Admin);
	$this->assertSame($operator2->login, "shapel");

    }

    public function testBadConnectToStorage(): void
    {
	$this->expectException(StorageNotConnect::class);
 	$config['host'] = "192.168.15.70" ;
	$config['rdn'] = "cn=admin,dc=mc03,dc=local";
	$config['base'] = "dc=mc03,dc=local";
	$config['pass'] = "adminasd";

	$storage = new Storage($config);
	
	$operator1 = Operator::GetByName("Бондарь Елена Ивановна", $storage);
	$operator2 = Operator::GetByName("Шапель Алексей Михайлович ", $storage);
	
	$this->assertSame($operator1->role, "operator");
	$this->assertSame($operator1->login, "bondar");

	$this->assertSame($operator2->role, "admin");
	$this->assertSame($operator2->login, "shapel");

    }

}
