php_components_pack/tests/extensions/BoolExtensionsTest.php
babaev-an 64c1f386eb 20250217
[Д] [BoolExtensions]: Добавлен новый статический класс, расширяющий возможности типа bool.
2025-02-17 17:34:14 +03:00

68 lines
1.9 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\extensions;
use Exception;
use goodboyalex\php_components_pack\extensions\BoolExtensions;
use PHPUnit\Framework\TestCase;
class BoolExtensionsTest extends TestCase
{
public function testAnyTrue ()
{
$this->PrepareForTest();
$hasTrue = [
true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false,
true, false, true, false, true, false, true, false, true, false, true, false
];
$noTrue = [
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false, false
];
$this->assertTrue(BoolExtensions::AnyTrue($hasTrue));
$this->assertFalse(BoolExtensions::AnyTrue($noTrue));
}
private function PrepareForTest (): void
{
require_once __DIR__ . '/../../sources/extensions/BoolExtensions.php';
}
public function testTrueCount ()
{
$this->PrepareForTest();
$array = [
true, false, true, false, true, false, true, false, true, false, true, false,
true, false, true, false, true, false, true, false, true, false, true, false, true, false, true,
false
];
$this->assertEquals(14,
BoolExtensions::TrueCount($array));
$this->expectException(Exception::class);
$array[] = "ПРЕДАТЕЛЬ!";
BoolExtensions::TrueCount($array);
}
public function testExportToString ()
{
$this->PrepareForTest();
$b = true;
$this->assertEquals('О, да!', BoolExtensions::ExportToString($b, 'О, да!', 'О, нет!'));
$b = false;
$this->assertEquals('О, нет!', BoolExtensions::ExportToString($b, 'О, да!', 'О, нет!'));
}
}