-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringHelperTest.php
More file actions
124 lines (110 loc) · 3.5 KB
/
StringHelperTest.php
File metadata and controls
124 lines (110 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
declare(strict_types=1);
namespace Forge\tests;
use App\Modules\ForgeTesting\Attributes\Group;
use App\Modules\ForgeTesting\Attributes\Test;
use App\Modules\ForgeTesting\TestCase;
use Forge\Traits\StringHelper;
#[Group('helpers')]
final class StringHelperTest extends TestCase
{
private static function runner(): string
{
return get_class(new class {
use StringHelper;
});
}
#[Test('String converted to camelCase')]
public function string_to_camel_case(): void
{
$expected = 'thisIsATest';
$runner = self::runner();
$actual = $runner::toCamelCase('this is a test');
$this->assertEquals($expected, $actual);
}
#[Test('String converted to PascalCase')]
public function string_to_pascal_case(): void
{
$expected = 'ThisIsATest';
$runner = self::runner();
$actual = $runner::toPascalCase('this is a test');
$this->assertEquals($expected, $actual);
}
#[Test('String converted to_snake_case')]
public function string_to_snake_case(): void
{
$expected = 'this_is_a_test';
$runner = self::runner();
$actual = $runner::toSnakeCase('thisIsATest');
$this->assertEquals($expected, $actual);
}
#[Test('String converted to-friendly-url')]
public function string_to_friendly_url(): void
{
$expected = 'this-is-a-test';
$runner = self::runner();
$actual = $runner::slugify('this is a test');
$this->assertEquals($expected, $actual);
}
#[Test('Truncate string to spesified length')]
public function truncate_string(): void
{
$string = 'this is just some random test';
$expected = 'this...';
$runner = self::runner();
$actual = $runner::truncate($string, 4);
$this->assertEquals($expected, $actual);
}
#[Test('Truncate should fail')]
public function truncate_string_should_fail(): void
{
$string = 'this is just some random test';
$expected = 'this...';
$runner = self::runner();
$actual = $runner::truncate($string, 10);
$this->shouldFail(function () use ($expected, $actual) {
$this->assertEquals($expected, $actual);
});
}
#[Test('String to Title Case')]
public function string_to_title_case(): void
{
$string = 'this is a test';
$expected = 'This Is A Test';
$runner = self::runner();
$actual = $runner::toTitleCase($string);
$this->assertEquals($expected, $actual);
}
#[Test('is camelCase')]
public function string_is_camel_case(): void
{
$string = 'isCamelCase';
$runner = self::runner();
$expected = $runner::isCamelCase($string);
$this->assertTrue($expected);
}
#[Test('is PascalCase')]
public function string_is_pascal_case(): void
{
$string = 'IsPascalCase';
$runner = self::runner();
$expected = $runner::isPascalCase($string);
$this->assertTrue($expected);
}
#[Test('is snake_case')]
public function string_is_snake_case(): void
{
$string = 'is_snake_case';
$runner = self::runner();
$expected = $runner::isSnakeCase($string);
$this->assertTrue($expected);
}
#[Test('is kebab-case')]
public function string_is_kebab_case(): void
{
$string = 'is-kebab-case';
$runner = self::runner();
$expected = $runner::isKebabCase($string);
$this->assertTrue($expected);
}
}