20250203
This commit is contained in:
		
							
								
								
									
										30
									
								
								tests/classes/ClassMapperTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								tests/classes/ClassMapperTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\classes; | ||||
|  | ||||
| use goodboyalex\php_components_pack\classes\ClassMapper; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| class ClassMapperTest extends TestCase | ||||
| { | ||||
|     public function testMapClass () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $a = new \goodboyalex\php_components_pack\tests\data\A(); | ||||
|         $a->a = 'a'; | ||||
|         $a->b = 2; | ||||
|         $a->c = true; | ||||
|  | ||||
|         $b = new B(); | ||||
|         ClassMapper::MapClass($a, $b); | ||||
|  | ||||
|         $this->assertEquals('a', $b->a); | ||||
|         $this->assertEquals(2, $b->b); | ||||
|     } | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../../sources/classes/classMapper.php'; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										10
									
								
								tests/data/A.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								tests/data/A.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\data; | ||||
|  | ||||
| class A | ||||
| { | ||||
|     public string $a; | ||||
|     public int $b; | ||||
|     public bool $c; | ||||
| } | ||||
							
								
								
									
										10
									
								
								tests/data/B.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								tests/data/B.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\classes; | ||||
|  | ||||
| class B | ||||
| { | ||||
|     public string $a; | ||||
|     public int $b; | ||||
|     public string $d; | ||||
| } | ||||
							
								
								
									
										67
									
								
								tests/extensions/ArrayExtensionTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								tests/extensions/ArrayExtensionTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,67 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\extensions; | ||||
|  | ||||
| use goodboyalex\php_components_pack\extensions\ArrayExtension; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| class ArrayExtensionTest extends TestCase | ||||
| { | ||||
|  | ||||
|     public function testRemoveEmpties () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $array = [ | ||||
|             'a' => 'a', | ||||
|             'b' => 'b', | ||||
|             'c' => '', | ||||
|             'd' => null, | ||||
|             'e' => 0, | ||||
|             'f' => false | ||||
|         ]; | ||||
|  | ||||
|         $this->assertEquals([ | ||||
|             'a' => 'a', | ||||
|             'b' => 'b', | ||||
|             'e' => 0, | ||||
|             'f' => false | ||||
|         ], ArrayExtension::RemoveEmpties($array)); | ||||
|     } | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../../sources/extensions/ArrayExtension.php'; | ||||
|     } | ||||
|  | ||||
|     public function testIsStringKey () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $this->assertTrue(ArrayExtension::IsStringKey('a')); | ||||
|         $this->assertFalse(ArrayExtension::IsStringKey(1)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testGetAssociativePart () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $array = [ | ||||
|             'a' => 'a', | ||||
|             'b' => 'b', | ||||
|             'c' => 'c', | ||||
|             'd' => 'd', | ||||
|             'e', | ||||
|             'f' | ||||
|         ]; | ||||
|  | ||||
|         $this->assertEquals([ | ||||
|             'a' => 'a', | ||||
|             'b' => 'b', | ||||
|             'c' => 'c', | ||||
|             'd' => 'd' | ||||
|         ], ArrayExtension::GetAssociativePart($array)); | ||||
|  | ||||
|     } | ||||
| } | ||||
							
								
								
									
										51
									
								
								tests/extensions/GUIDExtensionTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								tests/extensions/GUIDExtensionTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\extensions; | ||||
|  | ||||
| use goodboyalex\php_components_pack\extensions\GUIDExtension; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| class GUIDExtensionTest extends TestCase | ||||
| { | ||||
|     public function testGenerate () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|          | ||||
|         $guid = GUIDExtension::Generate(); | ||||
|         $this->assertTrue(strlen($guid) === 36); | ||||
|     } | ||||
|  | ||||
|     public function testIsNotValidOrEmpty () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $guid = GUIDExtension::Generate(); | ||||
|         $this->assertFalse(GUIDExtension::IsNotValidOrEmpty($guid)); | ||||
|  | ||||
|         $guid = '12345678-91101-1121-3141-516171819202'; | ||||
|         $this->assertTrue(GUIDExtension::IsNotValidOrEmpty($guid)); | ||||
|  | ||||
|         $guid = GUIDExtension::GUIDEmpty; | ||||
|         $this->assertTrue(GUIDExtension::IsNotValidOrEmpty($guid)); | ||||
|     } | ||||
|  | ||||
|     public function testValidate () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $guid = GUIDExtension::Generate(); | ||||
|         $this->assertFalse(GUIDExtension::IsNotValidOrEmpty($guid)); | ||||
|  | ||||
|         $guid = '12345678-91101-1121-3141-516171819202'; | ||||
|         $this->assertTrue(GUIDExtension::IsNotValidOrEmpty($guid)); | ||||
|  | ||||
|         $guid = GUIDExtension::GUIDEmpty; | ||||
|         $this->assertTrue(GUIDExtension::IsNotValidOrEmpty($guid)); | ||||
|     } | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../../sources/extensions/StringExtension.php'; | ||||
|         require_once __DIR__ . '/../../sources/extensions/GUIDExtension.php'; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										66
									
								
								tests/extensions/StringExtensionTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								tests/extensions/StringExtensionTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\extensions; | ||||
|  | ||||
| use goodboyalex\php_components_pack\extensions\StringExtension; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| class StringExtensionTest extends TestCase | ||||
| { | ||||
|  | ||||
|     public function testIsNullOrWhitespace () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $this->assertTrue(StringExtension::isNullOrWhitespace('')); | ||||
|         $this->assertTrue(StringExtension::isNullOrWhitespace(' ')); | ||||
|         $this->assertTrue(StringExtension::isNullOrWhitespace(null)); | ||||
|         $this->assertFalse(StringExtension::isNullOrWhitespace('TEST')); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../../sources/extensions/StringExtension.php'; | ||||
|     } | ||||
|  | ||||
|     public function testConvertToLatin () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $this->assertEquals('test', StringExtension::ConvertToLatin('тест')); | ||||
|         $this->assertEquals('test', StringExtension::ConvertToLatin('test')); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testIsNullOrEmpty () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $this->assertTrue(StringExtension::isNullOrEmpty('')); | ||||
|         $this->assertTrue(StringExtension::isNullOrEmpty(null)); | ||||
|         $this->assertFalse(StringExtension::isNullOrEmpty('TEST')); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testCompare () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $this->assertEquals(0, StringExtension::Compare('test', 'test')); | ||||
|         $this->assertEquals(-1, StringExtension::Compare('test', 'test1')); | ||||
|         $this->assertEquals(1, StringExtension::Compare('test2', 'test')); | ||||
|     } | ||||
|  | ||||
|     public function testGetShortText () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $this->assertEquals('test', StringExtension::GetShortText('test', 4)); | ||||
|         $this->assertEquals('test', StringExtension::GetShortText('test', 10)); | ||||
|         $this->assertEquals('test', StringExtension::GetShortText('test of this', 4)); | ||||
|         $this->assertEquals('t', StringExtension::GetShortText('test', 1)); | ||||
|         $this->assertEquals('', StringExtension::GetShortText('test', 0)); | ||||
|  | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user