20250214
+ [TwoDimSize]: Класс, описывающий двумерный размер. + [HashGetType]: Перечисление типов получения хэша. + [FileHash]: Класс для работы с хэшем файла или строки.
This commit is contained in:
		
							
								
								
									
										42
									
								
								tests/classes/FileHashTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								tests/classes/FileHashTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\classes; | ||||
|  | ||||
| use goodboyalex\php_components_pack\classes\FileHash; | ||||
| use goodboyalex\php_components_pack\enums\HashGetType; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| class FileHashTest extends TestCase | ||||
| { | ||||
|     public function test__construct () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $fileHash = new FileHash("Тестовое слово"); | ||||
|         $this->assertEquals("000e22f7ba01ae35f781bc3069038110c46593306cafef6b489f7c83b34629b7", $fileHash->Hash); | ||||
|  | ||||
|         $fileHash = new FileHash(__DIR__ . '/../data/A.php', HashGetType::ByFile); | ||||
|         $this->assertEquals("fc8dad93af5de5dd7c7d64e04faadfa22557e577a1538737fe462a5f78699fa2", $fileHash->Hash); | ||||
|  | ||||
|         $fileHash = new FileHash(__DIR__ . '/../data/B.php', HashGetType::ByFile); | ||||
|         $this->assertEquals("f419262e46e9461517af46d0c1e4faf25f38990bb50351b691d84f1ad51f2299", $fileHash->Hash); | ||||
|     } | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../../sources/traits/EnumExtensionsTrait.php'; | ||||
|         require_once __DIR__ . '/../../sources/enums/HashGetType.php'; | ||||
|         require_once __DIR__ . '/../../sources/extensions/StringExtension.php'; | ||||
|         require_once __DIR__ . '/../../sources/classes/FileHash.php'; | ||||
|     } | ||||
|  | ||||
|     public function testIsEqual () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $fileHash = new FileHash("Тестовое слово"); | ||||
|  | ||||
|         $this->assertTrue($fileHash->IsEqual(new FileHash("Тестовое слово"))); | ||||
|         $this->assertFalse($fileHash->IsEqual(new FileHash("Тестовое слово2"))); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										66
									
								
								tests/classes/TwoDimSizeTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								tests/classes/TwoDimSizeTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\classes; | ||||
|  | ||||
| use Exception; | ||||
| use goodboyalex\php_components_pack\classes\TwoDimSize; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| class TwoDimSizeTest extends TestCase | ||||
| { | ||||
|     public function testParse () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         try { | ||||
|             $size = TwoDimSize::Parse("10x20", "x"); | ||||
|         } | ||||
|         catch (Exception $e) { | ||||
|             $this->fail($e->getMessage()); | ||||
|         } | ||||
|  | ||||
|         $this->assertEquals(10, $size->Width); | ||||
|         $this->assertEquals(20, $size->Height); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../../sources/interfaces/ISerializable.php'; | ||||
|         require_once __DIR__ . '/../../sources/classes/TwoDimSize.php'; | ||||
|     } | ||||
|  | ||||
|     public function test__toString () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $size = new TwoDimSize(10, 20); | ||||
|  | ||||
|         $this->assertEquals("10:20", $size->__toString()); | ||||
|     } | ||||
|  | ||||
|     public function testSerialize () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $size = new TwoDimSize(10, 20); | ||||
|  | ||||
|         $this->assertEquals("10x20x1", $size->Serialize()); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testUnSerialize () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $serialized = "10x20x1"; | ||||
|  | ||||
|         $size = new TwoDimSize(); | ||||
|  | ||||
|         $size->UnSerialize($serialized); | ||||
|  | ||||
|         $this->assertEquals(10, $size->Width); | ||||
|         $this->assertEquals(20, $size->Height); | ||||
|         $this->assertTrue($size->NoNegativeValues); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user