babaev-an 97f73a73e2 20250525
Добавлен новый класс Tuple, реализующий работу кортежей почти как в C#.
2025-05-25 12:45:43 +03:00

37 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace goodboyalex\php_components_pack\tests\classes;
use Exception;
use goodboyalex\php_components_pack\classes\Tuple;
use PHPUnit\Framework\TestCase;
class TupleTest extends TestCase
{
public function testTuple ()
{
$this->PrepareForTest();
$tuple = new Tuple(1, 'string', ['array1', 'array2', 'array3']);
// Проверка на то, что возвращает значение кортежа при запросе значения по индексу
$this->assertEquals(1, $tuple->Get(0));
$this->assertEquals('string', $tuple->Get(1));
$this->assertEquals(['array1', 'array2', 'array3'], $tuple->Get(2));
// Проверка на то, что возвращает переменные
[$firstElement, $secondElement, $thirdElement] = $tuple;
$this->assertEquals(1, $firstElement);
$this->assertEquals('string', $secondElement);
$this->assertEquals(['array1', 'array2', 'array3'], $thirdElement);
// Проверка на то, что выбрасывает исключение при попытке задать данные в кортеж после его создания
$this->expectException(Exception::class);
$tuple[] = 'New data';
}
private function PrepareForTest (): void
{
require_once __DIR__ . '/../../sources/classes/Tuple.php';
}
}