| Server IP : 54.94.228.101 / Your IP : 172.28.1.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/vendor/anahkiasen/underscore-php/tests/ |
Upload File : |
<?php
namespace Underscore;
use Underscore\Dummies\DummyClass;
use Underscore\Dummies\DummyDefault;
use Underscore\Types\Arrays;
use Underscore\Types\Strings;
class UnderscoreTest extends UnderscoreTestCase
{
// Tests --------------------------------------------------------- /
public function testCanWrapObject()
{
$under1 = new Underscore($this->array);
$under2 = Underscore::from($this->array);
$this->assertInstanceOf('Underscore\Underscore', $under1);
$this->assertInstanceOf('Underscore\Types\Arrays', $under2);
}
public function testCanRedirectToCorrectClass()
{
$under = Underscore::contains([1, 2, 3], 3);
$this->assertEquals(2, $under);
}
public function testCanSwitchTypesMidCourse()
{
$stringToArray = Strings::from('FOO.BAR')->lower()->explode('.')->last()->title();
$this->assertEquals('Bar', $stringToArray->obtain());
}
public function testCanWrapWithShortcutFunction()
{
// Skip if base function not present
if (!function_exists('underscore')) {
return $this->assertTrue(true);
}
$under = underscore($this->array);
$this->assertInstanceOf('Underscore\Underscore', $under);
}
public function testCanHaveAliasesForMethods()
{
$under = Arrays::select($this->arrayNumbers, function ($value) {
return $value === 1;
});
$this->assertEquals([1], $under);
}
public function testUserCanExtendWithCustomFunctions()
{
Arrays::extend('fooify', function ($array) {
return 'bar';
});
$this->assertEquals('bar', Arrays::fooify(['foo']));
Strings::extend('unfooer', function ($string) {
return Strings::replace($string, 'foo', 'bar');
});
$this->assertEquals('bar', Strings::unfooer('foo'));
}
public function testBreakersCantAlterTheOriginalValue()
{
$object = Arrays::from([1, 2, 3]);
$sum = $object->sum();
$this->assertEquals(6, $sum);
$this->assertEquals([1, 2, 3], $object->obtain());
}
public function testClassesCanExtendCoreTypes()
{
$class = new DummyClass();
$class->set('foo', 'bar');
$this->assertEquals('foobar', DummyDefault::create()->obtain());
$this->assertEquals('{"foo":"bar"}', $class->toJSON());
}
public function testClassesCanUpdateSubject()
{
$class = new DummyClass();
$class = $class->getUsers()->toJSON();
$class2 = DummyClass::create()->getUsers()->toJSON();
$this->assertEquals('[{"foo":"bar"},{"bar":"foo"}]', $class);
$this->assertEquals($class, $class2);
}
public function testClassesCanOverwriteUnderscore()
{
$class = new DummyClass();
$class = $class->map(3)->paddingLeft(3)->toJSON();
$this->assertEquals('"009"', $class);
}
public function testMacrosCantConflictBetweenTypes()
{
Strings::extend('foobar', function () {
return 'string';
});
Arrays::extend('foobar', function () {
return 'arrays';
});
$this->assertEquals('string', Strings::foobar());
$this->assertEquals('arrays', Arrays::foobar());
}
public function testCanCheckIfSubjectIsEmpty()
{
$array = Arrays::create();
$this->assertTrue($array->isEmpty());
}
public function testCanParseToStringOnToString()
{
$array = Arrays::from($this->array);
$this->assertEquals('{"foo":"bar","bis":"ter"}', $array->__toString());
}
public function testUnderscoreFindsRightClassToCall()
{
$numbers = [3, 4, 5];
$product = Underscore::reduce($numbers, function ($w, $v) {
return $w * $v;
}, 1);
$this->assertEquals(60, $product);
}
}