20250525
Добавлен новый класс Tuple, реализующий работу кортежей почти как в C#.
This commit is contained in:
37
tests/classes/TupleTest.php
Normal file
37
tests/classes/TupleTest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user