Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions tests/Support/SupportHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ public function testStrIs()
$this->assertFalse(str_is('foo?bar', 'fobar'));
}

public function testStrRandom()
{
$result = str_random(20);
$this->assertTrue(is_string($result));
$this->assertEquals(20, mb_strlen($result));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use the mb function.

}


public function testStartsWith()
{
Expand Down Expand Up @@ -197,13 +204,30 @@ public function testStrContains()
}


public function testStrFinish()
{
$this->assertEquals('test/string/', str_finish('test/string', '/'));
$this->assertEquals('test/string/', str_finish('test/string/', '/'));
$this->assertEquals('test/string/', str_finish('test/string//', '/'));
}


public function testSnakeCase()
{
$this->assertEquals('foo_bar', snake_case('fooBar'));
$this->assertEquals('foo_bar', snake_case('fooBar')); // test cache
}


public function testStrLimit()
{
$string = 'The PHP framework for web artisans.';
$this->assertEquals('The PHP...', str_limit($string, 7));
$this->assertEquals('The PHP', str_limit($string, 7, ''));
$this->assertEquals('The PHP framework for web artisans.', str_limit($string, 100));
}


public function testCamelCase()
{
$this->assertEquals('fooBar', camel_case('FooBar'));
Expand All @@ -224,6 +248,13 @@ public function testStudlyCase()
}


public function testClassBasename()
{
$this->assertEquals('Baz', class_basename('Foo\Bar\Baz'));
$this->assertEquals('Baz', class_basename('Baz'));
}


public function testValue()
{
$this->assertEquals('foo', value('foo'));
Expand Down Expand Up @@ -277,6 +308,32 @@ public function testArraySort()
}


public function testArrayWhere()
{
$array = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6, 'g' => 7, 'h' => 8];
$this->assertEquals(['b' => 2, 'd' => 4, 'f' => 6, 'h' => 8], array_where(
$array,
function ($key, $value) {
return $value % 2 === 0;
}
));
}


public function testHead()
{
$array = ['a', 'b', 'c'];
$this->assertEquals('a', head($array));
}


public function testLast()
{
$array = ['a', 'b', 'c'];
$this->assertEquals('c', last($array));
}


public function testClassUsesRecursiveShouldReturnTraitsOnParentClasses()
{
$this->assertEquals([
Expand Down