Skip to content

Commit

Permalink
[#13954] - More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Apr 7, 2019
1 parent caddf96 commit a9a2d5d
Show file tree
Hide file tree
Showing 31 changed files with 2,006 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/unit.suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ modules:
host: '%DATA_MEMCACHED_HOST%'
port: '%DATA_MEMCACHED_PORT%'
weight: '%DATA_MEMCACHED_WEIGHT%'
Phalcon\Test\Module\Cache\Backend\File:
frontend: Phalcon\Cache\Frontend\Data
cache_dir: '%PATH_CACHE%'
# Phalcon\Test\Module\Cache\Backend\File:
# frontend: Phalcon\Cache\Frontend\Data
# cache_dir: '%PATH_CACHE%'
enabled:
- Apc
- Asserts
- Filesystem
- Redis
- Helper\Unit
- Helper\PhalconCacheFile
# - Helper\PhalconCacheFile
- Helper\PhalconLibmemcached
91 changes: 91 additions & 0 deletions tests/unit/Helper/Arr/ChunkCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Helper\Arr;

use Phalcon\Helper\Arr;
use UnitTester;

/**
* Class ChunkCest
*/
class ChunkCest
{
/**
* Tests Phalcon\Helper\Arr :: chunk()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-04-06
*/
public function helperArrChunk(UnitTester $I)
{
$I->wantToTest('Helper\Arr - chunk()');

$source = [
'k1' => 1,
'k2' => 2,
'k3' => 3,
'k4' => 4,
'k5' => 5,
'k6' => 6,
];

$expected = [
[1, 2],
[3, 4],
[5, 6],
];
$actual = Arr::chunk($source, 2);
$I->assertEquals($expected, $actual);
}

/**
* Tests Phalcon\Helper\Arr :: chunk() - preserve
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-04-06
*/
public function helperArrChunkPreserve(UnitTester $I)
{
$I->wantToTest('Helper\Arr - chunk() - preserve');

$source = [
'k1' => 1,
'k2' => 2,
'k3' => 3,
'k4' => 4,
'k5' => 5,
'k6' => 6,
];

$expected = [
[
'k1' => 1,
'k2' => 2,
],
[
'k3' => 3,
'k4' => 4,
],
[
'k5' => 5,
'k6' => 6,
],
];
$actual = Arr::chunk($source, 2, true);
$I->assertEquals($expected, $actual);
}
}
43 changes: 43 additions & 0 deletions tests/unit/Helper/Arr/FirstCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Helper\Arr;

use Phalcon\Helper\Arr;
use UnitTester;

/**
* Class FirstCest
*/
class FirstCest
{
/**
* Tests Phalcon\Helper\Arr :: first()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-04-06
*/
public function helperArrFirst(UnitTester $I)
{
$I->wantToTest('Helper\Arr - first()');
$collection = [
'Phalcon',
'Framework',
];

$expected = 'Phalcon';
$actual = Arr::first($collection);
$I->assertEquals($expected, $actual);
}
}
58 changes: 58 additions & 0 deletions tests/unit/Helper/Arr/FlattenCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Helper\Arr;

use Phalcon\Helper\Arr;
use UnitTester;

/**
* Class FlattenCest
*/
class FlattenCest
{
/**
* Tests Phalcon\Helper\Arr :: flatten()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-04-06
*/
public function helperArrFlatten(UnitTester $I)
{
$I->wantToTest('Helper\Arr - flatten()');

$source = [1, [2], [[3], 4], 5];
$expected = [1, 2, [3], 4, 5];
$actual = Arr::flatten($source);
$I->assertEquals($expected, $actual);
}

/**
* Tests Phalcon\Helper\Arr :: flatten() - deep
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-04-06
*/
public function helperArrFlattenDeep(UnitTester $I)
{
$I->wantToTest('Helper\Arr - flatten() - deep');

$source = [1, [2], [[3], 4], 5];
$expected = [1, 2, 3, 4, 5];
$actual = Arr::flatten($source, true);
$I->assertEquals($expected, $actual);
}
}
49 changes: 49 additions & 0 deletions tests/unit/Helper/Arr/IsUniqueCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Helper\Arr;

use Phalcon\Helper\Arr;
use UnitTester;

/**
* Class IsUniqueCest
*/
class IsUniqueCest
{
/**
* Tests Phalcon\Helper\Arr :: isUnique()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-04-06
*/
public function helperArrIsUnique(UnitTester $I)
{
$I->wantToTest('Helper\Arr - isUnique()');
$collection = [
'Phalcon',
'Framework',
];
$actual = Arr::isUnique($collection);
$I->assertTrue($actual);

$collection = [
'Phalcon',
'Framework',
'Phalcon',
];
$actual = Arr::isUnique($collection);
$I->assertFalse($actual);
}
}
43 changes: 43 additions & 0 deletions tests/unit/Helper/Arr/LastCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Helper\Arr;

use Phalcon\Helper\Arr;
use UnitTester;

/**
* Class LastCest
*/
class LastCest
{
/**
* Tests Phalcon\Helper\Arr :: last()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-04-06
*/
public function helperArrLast(UnitTester $I)
{
$I->wantToTest('Helper\Arr - last()');
$collection = [
'Phalcon',
'Framework',
];

$expected = 'Framework';
$actual = Arr::last($collection);
$I->assertEquals($expected, $actual);
}
}
56 changes: 56 additions & 0 deletions tests/unit/Helper/Arr/OrderCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
declare(strict_types=1);

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Test\Unit\Helper\Arr;

use Phalcon\Helper\Arr;
use UnitTester;

/**
* Class OrderCest
*/
class OrderCest
{
/**
* Tests Phalcon\Helper\Arr :: order()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-04-06
*/
public function helperArrOrder(UnitTester $I)
{
$I->wantToTest('Helper\Arr - order()');
$collection = [
['id' => 2, 'name' => 'Joy'],
['id' => 3, 'name' => 'Khaja'],
['id' => 1, 'name' => 'Raja'],
];

$expected = [
['id' => 1, 'name' => 'Raja'],
['id' => 2, 'name' => 'Joy'],
['id' => 3, 'name' => 'Khaja'],
];
$actual = Arr::order($collection, 'id');
$I->assertEquals($expected, $actual);

$expected = [
['id' => 3, 'name' => 'Khaja'],
['id' => 2, 'name' => 'Joy'],
['id' => 1, 'name' => 'Raja'],
];
$actual = Arr::order($collection, 'id', 'desc');
$I->assertEquals($expected, $actual);
}
}
Loading

0 comments on commit a9a2d5d

Please sign in to comment.