Skip to content

Commit 0c4d571

Browse files
author
f-lapinski
committed
Fix: add missing tests on string functions
1 parent 9ae3864 commit 0c4d571

File tree

6 files changed

+93
-3
lines changed

6 files changed

+93
-3
lines changed

src/core/etl/tests/Flow/ETL/Tests/Unit/Function/IndexOfTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,27 @@ public function test_returns_method_returns_string_int() : void
5151

5252
self::assertTrue($returnType->isEqual(type_int()));
5353
}
54+
55+
public function test_string_null_index_of_returns_false() : void
56+
{
57+
self::assertFalse(
58+
ref('str')->indexOf('x')->eval(
59+
row(
60+
str_entry('str', null),
61+
)
62+
)
63+
);
64+
}
65+
66+
public function test_needle_null_index_of_returns_false() : void
67+
{
68+
self::assertFalse(
69+
ref('str')->indexOf(ref('needle'))->eval(
70+
row(
71+
str_entry('str', 'x'),
72+
str_entry('needle', null)
73+
)
74+
)
75+
);
76+
}
5477
}

src/core/etl/tests/Flow/ETL/Tests/Unit/Function/IsUtf8Test.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,15 @@ public function test_returns_method_returns_string_boolean() : void
3636

3737
self::assertTrue($returnType->isEqual(type_boolean()));
3838
}
39+
40+
public function test_is_utf8_returns_null() : void
41+
{
42+
self::assertNull(
43+
ref('str')->isUtf8()->eval(
44+
row(
45+
str_entry('str', null),
46+
)
47+
)
48+
);
49+
}
3950
}

src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringAfterTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Flow\ETL\Tests\Unit\Function;
66

7+
use Flow\ETL\Function\StringAfter;
78
use function Flow\ETL\DSL\row;
89
use function Flow\ETL\DSL\{ref, str_entry, type_string};
910
use Flow\ETL\Function\StringTitle;
@@ -14,8 +15,8 @@ final class StringAfterTest extends FlowTestCase
1415
{
1516
public function test_returns_method_returns_string_type() : void
1617
{
17-
$stringTitleFunction = new StringTitle('str');
18-
$returnType = $stringTitleFunction->returns();
18+
$stringAfterFunction = new StringAfter('test', 'e');
19+
$returnType = $stringAfterFunction->returns();
1920

2021
self::assertInstanceOf(Type::class, $returnType);
2122

@@ -57,4 +58,15 @@ public function test_string_after_including_needle() : void
5758
)
5859
);
5960
}
61+
62+
public function test_string_after_returns_null() : void
63+
{
64+
self::assertFalse(
65+
ref('str')->stringAfter('x')->eval(
66+
row(
67+
str_entry('str', null),
68+
)
69+
)
70+
);
71+
}
6072
}

src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringFoldTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,23 @@
44

55
namespace Flow\ETL\Tests\Unit\Function;
66

7+
use Flow\ETL\Function\StringFold;
8+
use Flow\ETL\PHP\Type\Type;
79
use function Flow\ETL\DSL\row;
8-
use function Flow\ETL\DSL\{ref, str_entry};
10+
use function Flow\ETL\DSL\{ref, str_entry, type_string};
911
use Flow\ETL\Tests\FlowTestCase;
1012

1113
final class StringFoldTest extends FlowTestCase
1214
{
15+
public function test_returns_method_returns_string_type() : void
16+
{
17+
$stringFoldedFunction = new StringFold('str');
18+
$returnType = $stringFoldedFunction->returns();
19+
20+
self::assertInstanceOf(Type::class, $returnType);
21+
22+
self::assertTrue($returnType->isEqual(type_string()));
23+
}
1324
public function test_string_folded() : void
1425
{
1526
self::assertSame(
@@ -19,4 +30,15 @@ public function test_string_folded() : void
1930
)
2031
);
2132
}
33+
34+
public function test_string_folded_returns_null() : void
35+
{
36+
self::assertNull(
37+
ref('str')->stringFold()->eval(
38+
row(
39+
str_entry('str', null),
40+
)
41+
)
42+
);
43+
}
2244
}

src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringStyleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,15 @@ public function test_string_style_upper() : void
8585
)
8686
);
8787
}
88+
89+
public function test_string_style_returns_null() : void
90+
{
91+
self::assertNull(
92+
ref('str')->stringStyle(StringStyles::LOWER)->eval(
93+
row(
94+
str_entry('str', null),
95+
)
96+
)
97+
);
98+
}
8899
}

src/core/etl/tests/Flow/ETL/Tests/Unit/Function/StringTitleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,15 @@ public function test_string_title_allwords() : void
4141
)
4242
);
4343
}
44+
45+
public function test_string_title_returns_null() : void
46+
{
47+
self::assertNull(
48+
ref('str')->stringTitle()->eval(
49+
row(
50+
str_entry('str', null),
51+
)
52+
)
53+
);
54+
}
4455
}

0 commit comments

Comments
 (0)