1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Tests for all procedural based functions |
7
|
|
|
* |
8
|
|
|
* @since 0.1.0 |
9
|
|
|
* @author Glynn Quelch <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
require_once dirname(__FILE__, 2) . '/FunctionsLoader.php'; |
13
|
|
|
require_once dirname(__FILE__) . '/Providers/ObjectFactory.php'; |
14
|
|
|
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use PinkCrab\FunctionConstructors\Numbers as Num; |
17
|
|
|
use PinkCrab\FunctionConstructors\Strings as Str; |
18
|
|
|
use PinkCrab\FunctionConstructors\FunctionsLoader; |
19
|
|
|
use PinkCrab\FunctionConstructors\GeneralFunctions as Func; |
20
|
|
|
use PinkCrab\FunctionConstructors\Tests\Providers\ObjectFactory; |
21
|
|
|
|
22
|
|
|
class ProceduralFunctionsTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
public function testCanFlattenArray() |
25
|
|
|
{ |
26
|
|
|
$array = array( |
27
|
|
|
1, |
28
|
|
|
2, |
29
|
|
|
array( 3, 4 ), |
30
|
|
|
array( |
31
|
|
|
5, |
32
|
|
|
6, |
33
|
|
|
7, |
34
|
|
|
8, |
35
|
|
|
array( |
36
|
|
|
9, |
37
|
|
|
10, |
38
|
|
|
array( 11, 12, 13 ), |
39
|
|
|
), |
40
|
|
|
), |
41
|
|
|
); |
42
|
|
|
$this->assertArrayHasKey(2, arrayFlatten($array, 2)); |
43
|
|
|
$this->assertIsArray(arrayFlatten($array, 1)[8]); |
44
|
|
|
|
45
|
|
|
$this->assertArrayHasKey(9, arrayFlatten($array, 2)); |
46
|
|
|
$this->assertIsArray(arrayFlatten($array, 2)[10]); |
47
|
|
|
|
48
|
|
|
$this->assertArrayHasKey(12, arrayFlatten($array, 3)); |
49
|
|
|
$this->assertEquals(13, arrayFlatten($array, 3)[12]); |
50
|
|
|
|
51
|
|
|
// Check will fully flatten if no depth defined. |
52
|
|
|
$this->assertArrayHasKey(12, arrayFlatten($array)); |
53
|
|
|
$this->assertEquals(13, arrayFlatten($array)[12]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testCanUsestr_contains() |
57
|
|
|
{ |
58
|
|
|
$this->assertTrue(stringContains('--True', '--')); |
59
|
|
|
$this->assertFalse(stringContains('++False', '--')); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|