Skip to content

Commit 71482d4

Browse files
committed
write new tests
1 parent 455d98d commit 71482d4

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

tests/StrUtilityTest.php

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class StrUtilityTest extends TestCase
1717
{
1818
public $sampleText = 'somE TexT 444 for? tE34st! @#56$%^ <>';
19+
public $basePath = __DIR__ . '/../';
1920

2021
public function testToCamelCaseCanReturnStringValue()
2122
{
@@ -122,7 +123,7 @@ public function testDotNotationCanReturnStringValue()
122123
public function testDotNotationCanReturnStringLikeDotNotation()
123124
{
124125
$string = strHelpersTest::dotNotation($this->sampleText);
125-
$this->assertEquals('some.text.444.for.te34st.56', $string);
126+
$this->assertEquals('somE.TexT.444.for.tE34st.56', $string);
126127
}
127128

128129
public function testEntitiesWrapperCanReturnStringValue()
@@ -201,9 +202,10 @@ public function testAlternateCanReturnStringValueIfBothParamAreNull()
201202
$this->assertEquals('not defined', $string);
202203
}
203204

204-
public function testTranslateCanReturnStringData()
205+
public function testTranslateCanReturnStringValue()
205206
{
206-
$string = strHelpersTest::translate('app.title');
207+
$translatePath = strHelpersTest::translatePath(realpath($this->basePath), 'en');
208+
$string = strHelpersTest::translate($translatePath . 'app.title');
207209
$this->assertIsString($string);
208210
}
209211

@@ -216,18 +218,28 @@ public function testTranslateCanThrowExceptionIfLangFileDoesNotExists()
216218
public function testTranslateCanThrowExceptionIfLangFileDoesNotInArrayType()
217219
{
218220
$this->expectException(LanguageFileIsNotArrayException::class);
219-
$string = strHelpersTest::translate('app.title');
221+
$translatePath = strHelpersTest::translatePath(realpath($this->basePath), 'en');
222+
strHelpersTest::translate($translatePath . 'auth.title');
220223
}
221224

225+
// public function testTranslateCanReturnReplaceParamIfGivenKeyDoesNotExists()
226+
// {
227+
// $translatePath = strHelpersTest::translatePath(realpath($this->basePath), 'en');
228+
// $string = strHelpersTest::translate($translatePath . 'app.site', 'replace text');
229+
// $this->assertEquals('replace text', $string);
230+
// }
231+
222232
public function testFilePathCanReturnStringValue()
223233
{
224-
$filePath = strHelpersTest::filePath('lang.en.app');
234+
$basePath = realpath($this->basePath);
235+
$filePath = strHelpersTest::filePath($basePath . '.lang.en.app');
225236
$this->assertIsString($filePath);
226237
}
227238

228239
public function testFilePathReturnedFilePathIfExists()
229240
{
230-
$filePath = strHelpersTest::filePath('lang.en.app');
241+
$basePath = realpath($this->basePath);
242+
$filePath = strHelpersTest::filePath($basePath . '.lang.en.app');
231243
$this->assertFileExists($filePath);
232244
$this->assertFileEquals('lang/en/app.php', $filePath);
233245
$this->assertFileIsReadable($filePath);
@@ -236,7 +248,7 @@ public function testFilePathReturnedFilePathIfExists()
236248
public function testPathThrowAnExceptionsIfFileDoesNotExists()
237249
{
238250
$this->expectException(FileDoesNotExistsException::class);
239-
$filePath = strHelpersTest::filePath('lang.en.config.auth');
251+
strHelpersTest::filePath('lang.en.config.auth');
240252
}
241253

242254
public function testWrapperCanReturnStringValue()
@@ -783,4 +795,46 @@ public function testDecrementByCanDecrementGivenString()
783795
$string = strHelpersTest::decrementBy('bar1', '*');
784796
$this->assertEquals('bar*0', $string);
785797
}
798+
799+
public function testRmLastWordCanReturnStringValue()
800+
{
801+
$string = strHelpersTest::rmLastWord('foo bar baz');
802+
$this->assertIsString($string);
803+
}
804+
805+
public function testRmLastWordCanRemoveLastWordOfGivenString()
806+
{
807+
$string = strHelpersTest::rmLastWord('foo bar baz 123');
808+
$this->assertEquals('foo bar baz', $string);
809+
}
810+
811+
public function testRmFirstWordCanReturnStringValue()
812+
{
813+
$string = strHelpersTest::rmFirstWord('foo bar baz');
814+
$this->assertIsString($string);
815+
}
816+
817+
public function testRmFirstWordCanRemoveFirstWordOfGivenString()
818+
{
819+
$string = strHelpersTest::rmFirstWord('12 123 foo bar baz');
820+
$this->assertEquals('123 foo bar baz', $string);
821+
}
822+
823+
public function testIsSlugCanReturnBooleanValue()
824+
{
825+
$slug = strHelpersTest::is_slug('foo-bar-baz');
826+
$this->assertIsBool($slug);
827+
}
828+
829+
public function testIsSlugReturnFalseIfGivenStringIsNotASlug()
830+
{
831+
$slug = strHelpersTest::is_slug('foo bar baz');
832+
$this->assertNotTrue($slug);
833+
}
834+
835+
public function testIsSlugReturnTrueIfGivenStringIsASlug()
836+
{
837+
$slug = strHelpersTest::is_slug('132Foo-12bar-3432az');
838+
$this->assertTrue($slug);
839+
}
786840
}

0 commit comments

Comments
 (0)