3 Commits

Author SHA1 Message Date
Meritoo
1a649d35e1 Merge branch 'develop' 2018-06-18 09:37:27 +02:00
Meritoo
0a3955026b Revert "StyleCI > update configuration"
This reverts commit f9fa5f5
2018-06-15 23:00:53 +02:00
Meritoo
f9fa5f5915 StyleCI > update configuration 2018-06-15 23:00:29 +02:00
4 changed files with 13 additions and 116 deletions

View File

@@ -1,11 +1,7 @@
# Meritoo Common Library
Common and useful classes, methods, exceptions etc.
# 0.0.20
1. Collection > add() method > treat empty string as not provided index (same as null)
# 0.0.19
## 0.0.19
1. Add this changelog
2. Reorganize documentation & update [Readme](README.md)

View File

@@ -2,7 +2,7 @@
"name": "meritoo/common-library",
"description": "Useful classes, methods, extensions etc.",
"license": "MIT",
"version": "0.0.20",
"version": "0.0.19",
"authors": [
{
"name": "Meritoo.pl",

View File

@@ -109,7 +109,7 @@ class Collection implements Countable, ArrayAccess, IteratorAggregate
*/
public function add($element, $index = null)
{
if (null === $index || '' === $index) {
if (null === $index) {
$this->elements[] = $element;
} else {
$this->elements[$index] = $element;

View File

@@ -9,7 +9,6 @@
namespace Meritoo\Common\Test\Collection;
use ArrayIterator;
use Generator;
use Meritoo\Common\Collection\Collection;
use Meritoo\Common\Test\Base\BaseTestCase;
use Meritoo\Common\Type\OopVisibilityType;
@@ -130,39 +129,22 @@ class CollectionTest extends BaseTestCase
static::assertInstanceOf(ArrayIterator::class, $this->simpleCollection->getIterator());
}
/**
* @param mixed $element The element to add
* @param int $expectedCount Expected count of elements in collection
* @param int $expectedIndex Expected index of added element in collection
* @param Collection $collection The collection
*
* @dataProvider provideElementToAdd
*/
public function testAddWithoutIndex($element, $expectedCount, $expectedIndex, Collection $collection)
public function testAdd()
{
$collection->add($element);
$this->emptyCollection->add('test1');
static::assertTrue($collection->has($element));
static::assertEquals($expectedCount, $collection->count());
static::assertEquals($element, $collection[$expectedIndex]);
static::assertTrue($this->emptyCollection->has('test1'));
static::assertEquals(1, $this->emptyCollection->count());
static::assertEquals('test1', $this->emptyCollection[0]);
}
/**
* @param mixed $element The element to add
* @param mixed $index Index of element to add
* @param int $expectedCount Expected count of elements in collection
* @param int $expectedIndex Expected index of added element in collection
* @param Collection $collection The collection
*
* @dataProvider provideElementToAddWithIndex
*/
public function testAddWithIndex($element, $index, $expectedCount, $expectedIndex, Collection $collection)
public function testAddWithIndex()
{
$collection->add($element, $index);
$this->emptyCollection->add('test2', 1234);
static::assertTrue($collection->has($element));
static::assertEquals($expectedCount, $collection->count());
static::assertEquals($element, $collection[$expectedIndex]);
static::assertTrue($this->emptyCollection->has('test2'));
static::assertEquals(1, $this->emptyCollection->count());
static::assertEquals('test2', $this->emptyCollection[1234]);
}
public function testAddMultipleUsingEmptyArray()
@@ -327,87 +309,6 @@ class CollectionTest extends BaseTestCase
static::assertMethodVisibilityAndArguments(Collection::class, 'exists', OopVisibilityType::IS_PRIVATE, 1, 1);
}
/**
* Provides element to add to collection
*
* @return Generator
*/
public function provideElementToAdd()
{
$collection = new Collection();
yield[
'test1',
1,
0,
$collection,
];
yield[
'test2',
2,
1,
$collection,
];
yield[
'test3',
3,
2,
$collection,
];
}
/**
* Provides element with index to add to collection
*
* @return Generator
*/
public function provideElementToAddWithIndex()
{
$collection = new Collection();
yield[
'test1',
'aa',
1,
'aa',
$collection,
];
yield[
'test2',
'oo',
2,
'oo',
$collection,
];
yield[
'test3',
null,
3,
0,
$collection,
];
yield[
'test4',
'',
4,
1,
$collection,
];
yield[
'test5',
'vv',
5,
'vv',
$collection,
];
}
/**
* {@inheritdoc}
*/