38 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| namespace nulib;
 | |
| 
 | |
| use nulib\tests\TestCase;
 | |
| 
 | |
| class clTest extends TestCase {
 | |
|   function checkKeys(?array $array, ?array $ref, bool $sameKeys, array $expectedKeys, array $expectedRemains, array $expectedMissings): void {
 | |
|     self::assertSame($sameKeys, cl::same_keys($array, $ref, $keys, $remains, $missings), "sameKeys");
 | |
|     self::assertSame($expectedKeys, $keys, "keys");
 | |
|     self::assertSame($expectedRemains, $remains, "remains");
 | |
|     self::assertSame($expectedMissings, $missings, "missings");
 | |
|   }
 | |
|   function test_same_keys() {
 | |
|     $array = ["a" => 42, "b" => "tesxt"]; $arrayKeys = array_keys($array);
 | |
|     $xarray = ["parasite0", "a" => 42, "parasite1", "b" => "tesxt"]; $xarrayKeys = array_keys($array);
 | |
|     $ref = ["a" => "int", "b" => "text"]; $refKeys = array_keys($ref);
 | |
|     $missingArray = ["c" => true]; $missingKeys = array_keys($missingArray);
 | |
|     $missingRef = ["c" => "bool"]; $missingKeys = array_keys($missingRef);
 | |
| 
 | |
|     $this->checkKeys(null, null, true, [], [], []);
 | |
|     $this->checkKeys(null, [], true, [], [], []);
 | |
|     $this->checkKeys([], null, true, [], [], []);
 | |
|     $this->checkKeys([], [], true, [], [], []);
 | |
| 
 | |
|     $this->checkKeys(null, $ref, false, [], [], $refKeys);
 | |
|     $this->checkKeys([], $ref, false, [], [], $refKeys);
 | |
| 
 | |
|     $this->checkKeys($array, null, true, [], $arrayKeys, []);
 | |
|     $this->checkKeys($array, [], true, [], $arrayKeys, []);
 | |
| 
 | |
|     $this->checkKeys($array, $ref, true, $arrayKeys, [], []);
 | |
|     $this->checkKeys(cl::merge($array, $missingArray), $ref, true, $arrayKeys, $missingKeys, []);
 | |
|     $this->checkKeys($array, cl::merge($ref, $missingRef), false, $arrayKeys, [], $missingKeys);
 | |
| 
 | |
|     $this->checkKeys($xarray, $ref, false, $arrayKeys, [0, 1], []);
 | |
|   }
 | |
| }
 |