updating unit tests
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,3 +2,7 @@
|
|||||||
/lab/
|
/lab/
|
||||||
composer.lock
|
composer.lock
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
**/temp/
|
||||||
|
**/temp.*
|
||||||
|
**/*.temp.*
|
||||||
21
phpunit.xml
Normal file
21
phpunit.xml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.2/phpunit.xsd"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
forceCoversAnnotation="true"
|
||||||
|
beStrictAboutCoversAnnotation="true"
|
||||||
|
beStrictAboutOutputDuringTests="true"
|
||||||
|
beStrictAboutTodoAnnotatedTests="true"
|
||||||
|
verbose="true">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="default">
|
||||||
|
<directory suffix="Test.php">tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
|
||||||
|
<filter>
|
||||||
|
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||||
|
<directory suffix=".php">src</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
||||||
@ -61,8 +61,8 @@ or use Composer:
|
|||||||
|
|
||||||
composer require salarmehr/ary
|
composer require salarmehr/ary
|
||||||
|
|
||||||
* The class (`Ary()`) requires PHP 5.4 or above.
|
* The `Ary()` requires PHP 5.4 or above.
|
||||||
* The helper function (`ary()`) requires PHP 5.6 or above.
|
* The `ary()` helper function requires PHP 5.6 or above.
|
||||||
|
|
||||||
Licence
|
Licence
|
||||||
=======
|
=======
|
||||||
|
|||||||
@ -178,6 +178,7 @@ class Ary extends Collection
|
|||||||
* Get all items except for those with the specified keys.
|
* Get all items except for those with the specified keys.
|
||||||
*
|
*
|
||||||
* @param mixed $keys
|
* @param mixed $keys
|
||||||
|
* @param bool $returnArray
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
public function except($keys, $returnArray = false)
|
public function except($keys, $returnArray = false)
|
||||||
|
|||||||
@ -17,11 +17,11 @@ class Test extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
public function provider()
|
public function provider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array(''),
|
[['']],
|
||||||
array(['ali', 'reza', 'mohammad']),
|
[['ali', 'reza', 'mohammad']],
|
||||||
array([1, 2, 3, 4]),
|
[[1, 2, 3, 4]],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,16 +43,16 @@ class Test extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
public function various()
|
public function various()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('', ''),
|
['', ''],
|
||||||
array(null, null),
|
[null, null],
|
||||||
array(['ali', 'reza', 'mohammad'], ['ali', 'reza', 'mohammad']),
|
[['ali', 'reza', 'mohammad'], ['ali', 'reza', 'mohammad']],
|
||||||
array(['name' => 'ali', 'lastname' => 'reza', 'age' => 30], ['name' => 'ali', 'lastname' => 'reza', 'age' => 30]),
|
[['name' => 'ali', 'lastname' => 'reza', 'age' => 30], ['name' => 'ali', 'lastname' => 'reza', 'age' => 30]],
|
||||||
array((object)['name' => 'ali', 'lastname' => 'reza', 'age' => 30], (object)['name' => 'ali', 'lastname' => 'reza', 'age' => 30]),
|
[(object)['name' => 'ali', 'lastname' => 'reza', 'age' => 30], (object)['name' => 'ali', 'lastname' => 'reza', 'age' => 30]],
|
||||||
array(['ali', 'reza', 'mohammad'], ['ali', 'reza', 'mohammad']),
|
[['ali', 'reza', 'mohammad'], ['ali', 'reza', 'mohammad']],
|
||||||
array([1, 2, 3, 4], [1, 2, 3, 4]),
|
[[1, 2, 3, 4], [1, 2, 3, 4]],
|
||||||
array(['x'=>'y'], ['x'=>'y']),
|
[['x' => 'y'], ['x' => 'y']],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,20 +67,21 @@ class Test extends PHPUnit\Framework\TestCase
|
|||||||
|
|
||||||
public function testAryHelper()
|
public function testAryHelper()
|
||||||
{
|
{
|
||||||
$a=ary(['x'=>2,'y'=>22]);
|
$a = ary(['x' => 2, 'y' => 22]);
|
||||||
$this->assertEquals($a['x'],2);
|
$this->assertEquals($a['x'], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider Provider
|
* @dataProvider provider
|
||||||
*/
|
*/
|
||||||
public function testCount($objects)
|
public function testCount($objects)
|
||||||
{
|
{
|
||||||
$ary = new Ary($objects);
|
$ary = new Ary($objects);
|
||||||
$result = count($objects);
|
var_dump($objects);
|
||||||
|
$expected = count($objects);
|
||||||
$num = count($ary);
|
$num = count($ary);
|
||||||
$this->assertEquals($result, $num);
|
$this->assertEquals($expected, $num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +90,7 @@ class Test extends PHPUnit\Framework\TestCase
|
|||||||
public function testGetArrayableItems($original, $expected)
|
public function testGetArrayableItems($original, $expected)
|
||||||
{
|
{
|
||||||
$ary = new Ary($original);
|
$ary = new Ary($original);
|
||||||
$this->invokeMethod($ary, 'getArrayableItems', array($original));
|
$this->invokeMethod($ary, 'getArrayableItems', [$original]);
|
||||||
$this->assertEquals($expected, $original);
|
$this->assertEquals($expected, $original);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,8 +100,9 @@ class Test extends PHPUnit\Framework\TestCase
|
|||||||
* @param array $parameters Array of parameters to pass into method.
|
* @param array $parameters Array of parameters to pass into method.
|
||||||
*
|
*
|
||||||
* @return mixed Method return.
|
* @return mixed Method return.
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function invokeMethod(&$ary, $getArrayableItems, array $parameters = array())
|
public function invokeMethod(&$ary, $getArrayableItems, array $parameters = [])
|
||||||
{
|
{
|
||||||
$reflection = new \ReflectionClass(get_class($ary));
|
$reflection = new \ReflectionClass(get_class($ary));
|
||||||
$method = $reflection->getMethod($getArrayableItems);
|
$method = $reflection->getMethod($getArrayableItems);
|
||||||
@ -175,33 +177,27 @@ class Test extends PHPUnit\Framework\TestCase
|
|||||||
$this->assertEquals(['foo' => 'x'], $c->except(['bar'])->all());
|
$this->assertEquals(['foo' => 'x'], $c->except(['bar'])->all());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function testOffsetExists()
|
public function testOffsetExists()
|
||||||
{
|
{
|
||||||
|
|
||||||
$parameters = array(4,5,2,0,1,3);
|
$parameters = [4, 5, 2, 0, 1, 3];
|
||||||
$ary= new Ary($parameters);
|
$ary = new Ary($parameters);
|
||||||
|
|
||||||
for($i=0 ; $i<=count($ary) ; $i++){
|
for ($i = 0; $i <= count($ary); $i++) {
|
||||||
$key = [];
|
$key = [];
|
||||||
$key[$i] = $ary->{$i};
|
$key[$i] = $ary->{$i};
|
||||||
if($i < count($ary)){
|
if ($i < count($ary)) {
|
||||||
$resultTrue=$ary->offsetExists($key[$i]);
|
$resultTrue = $ary->offsetExists($key[$i]);
|
||||||
$this->assertTrue($resultTrue);
|
$this->assertTrue($resultTrue);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
$resultFalse = $ary->offsetExists($key[$i]);
|
$resultFalse = $ary->offsetExists($key[$i]);
|
||||||
$this->assertFalse($resultFalse);
|
$this->assertFalse($resultFalse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testToObject()
|
||||||
public function testToObject(){
|
{
|
||||||
|
|
||||||
$name1 = 'mehdi';
|
$name1 = 'mehdi';
|
||||||
$height1 = 181;
|
$height1 = 181;
|
||||||
@ -213,17 +209,14 @@ class Test extends PHPUnit\Framework\TestCase
|
|||||||
$persons[$name1] = $height1;
|
$persons[$name1] = $height1;
|
||||||
$persons[$name2] = $height2;
|
$persons[$name2] = $height2;
|
||||||
|
|
||||||
$ary= new Ary($persons);
|
$ary = new Ary($persons);
|
||||||
$objected = $ary->toObject();
|
$objected = $ary->toObject();
|
||||||
|
|
||||||
|
|
||||||
$this->assertInternalType("string" , $name1);
|
$this->assertInternalType("string", $name1);
|
||||||
$this->assertInternalType("array" , $persons);
|
$this->assertInternalType("array", $persons);
|
||||||
$this->assertInternalType("object" , $ary);
|
$this->assertInternalType("object", $ary);
|
||||||
$this->assertInternalType("object", $objected);
|
$this->assertInternalType("object", $objected);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user