2021-03-03 13:59:55 -08:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 https://rewiv.com sikofitt@gmail.com
|
|
|
|
*
|
|
|
|
* This file is a part of Olive BBS
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the
|
|
|
|
* terms of the Mozilla Public License, v. 2.0.
|
|
|
|
*
|
|
|
|
* If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* ___ ___ ___
|
|
|
|
* ( ).-. ( ) ( )
|
|
|
|
* .--. | |( __)___ ___ .--. | |.-. | |.-. .--.
|
|
|
|
* / \| |(''"( )( / \| / \| / \ / _ \
|
|
|
|
* | .-. | | | | | | | | .-. | .-. | .-. |. .' `. ;
|
|
|
|
* | | | | | | | | | | | | | | | | | | | || ' | |
|
|
|
|
* | | | | | | | | | | | |/ | | | | | | |_\_`.(___)
|
|
|
|
* | | | | | | | | | | | ' _.| | | | | | ( ). '.
|
|
|
|
* | ' | | | | | ' ' ; | .'.-| ' | | ' | || | `\ |
|
|
|
|
* ' `-' | | | | \ `' /' `-' ' `-' ;' `-' ; ; '._,' '
|
|
|
|
* `.__.(___(___) '_.' `.__.' `.__. `.__. '.___.'
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Olivebbs\Tests\Map;
|
|
|
|
|
2022-05-11 16:28:23 -07:00
|
|
|
use Olivebbs\Map\Enum\KeyType;
|
|
|
|
use Olivebbs\Map\Enum\ValueType;
|
2021-03-03 13:59:55 -08:00
|
|
|
use Olivebbs\Map\Exception\ImmutableMapException;
|
|
|
|
use Olivebbs\Map\Exception\InvalidArgumentException;
|
|
|
|
use Olivebbs\Map\ImmutableMap;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class ImmutableMapTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testOffsetUnset(): void
|
|
|
|
{
|
2022-05-11 16:28:23 -07:00
|
|
|
$immutableMap = ImmutableMap::create(KeyType::INTEGER, ValueType::CHAR, range('A', 'Z'));
|
2021-03-03 13:59:55 -08:00
|
|
|
$this->expectException(ImmutableMapException::class);
|
|
|
|
unset($immutableMap[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOffsetSet(): void
|
|
|
|
{
|
2022-05-11 16:28:23 -07:00
|
|
|
$immutableMap = ImmutableMap::create(KeyType::INTEGER, ValueType::CHAR, range('A', 'Z'));
|
2021-03-03 13:59:55 -08:00
|
|
|
$this->expectException(ImmutableMapException::class);
|
|
|
|
$immutableMap[0] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test__construct(): void
|
|
|
|
{
|
|
|
|
$values = [
|
|
|
|
'A' => 1,
|
|
|
|
'C' => 2,
|
|
|
|
'3' => 4,
|
|
|
|
];
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
$this->expectExceptionMessage('Invalid types for map [string => int], they should be [int => string]');
|
2022-05-11 16:28:23 -07:00
|
|
|
$immutableMap = ImmutableMap::create(KeyType::INT, ValueType::STRING, $values);
|
2021-03-03 13:59:55 -08:00
|
|
|
}
|
|
|
|
}
|