Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Yii Arrays Change Log
=======================
# Yii Arrays Change Log

## 1.0.0 under development

1.0.0 under development
-----------------------
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ composer require yiisoft/arrays
Array helper methods are static so usage is like the following:

```php
$username = ArrayHelper::getValue($_POST, 'username');
$username = \Yiisoft\Arrays\ArrayHelper::getValue($_POST, 'username');
```

Overall the helper has the following method groups.
Expand Down Expand Up @@ -96,7 +96,7 @@ Overall the helper has the following method groups.
Array sorter has one static method which usage is like the following:

```php
ArraySorter::multisort($data, ['age', 'name'], [SORT_ASC, SORT_DESC]);
\Yiisoft\Arrays\ArraySorter::multisort($data, ['age', 'name'], [SORT_ASC, SORT_DESC]);
```

## ArrayAccessTrait usage
Expand All @@ -112,6 +112,8 @@ The data will be exposed by ArrayAccessTrait to support accessing the class obje
Example of use:

```php
use \Yiisoft\Arrays\ArrayAccessTrait;

class OfficeClassification implements \IteratorAggregate, \ArrayAccess, \Countable
{
use ArrayAccessTrait;
Expand Down Expand Up @@ -141,6 +143,9 @@ while ($iterator->valid()) {
Example of use:

```php
use \Yiisoft\Arrays\ArrayableTrait;
use \Yiisoft\Arrays\ArrayableInterface;

class Car implements ArrayableInterface
{
use ArrayableTrait;
Expand Down
3 changes: 1 addition & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Upgrading Instructions
======================
# Upgrading Instructions

Changes summary:
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" verbose="true" bootstrap="tests/bootstrap.php" failOnRisky="true" failOnWarning="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" verbose="true" bootstrap="vendor/autoload.php" failOnRisky="true" failOnWarning="true">
<coverage>
<include>
<directory>./</directory>
Expand Down
14 changes: 6 additions & 8 deletions tests/ArrayAccessTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,39 @@

namespace Yiisoft\Arrays\Tests;

use ArrayIterator;
use PHPUnit\Framework\TestCase;
use Yiisoft\Arrays\Tests\Objects\ArrayAccessObject;

final class ArrayAccessTraitTest extends TestCase
{
public function testIterator()
public function testIterator(): void
{
$object = new ArrayAccessObject();
$iterator = $object->getIterator();
$this->assertInstanceOf(ArrayIterator::class, $iterator);
$this->assertSame($object->data, $iterator->getArrayCopy());
}

public function testCount()
public function testCount(): void
{
$object = new ArrayAccessObject();
$this->assertSame(3, $object->count());
}

public function testOffsetExists()
public function testOffsetExists(): void
{
$object = new ArrayAccessObject();
$this->assertTrue($object->offsetExists('a'));
$this->assertFalse($object->offsetExists('x'));
}

public function testOffsetGet()
public function testOffsetGet(): void
{
$object = new ArrayAccessObject();
$this->assertSame(1, $object->offsetGet('a'));
$this->assertNull($object->offsetGet('x'));
}

public function testOffsetSet()
public function testOffsetSet(): void
{
$object = new ArrayAccessObject();
$object->offsetSet('a', 4);
Expand All @@ -53,7 +51,7 @@ public function testOffsetSet()
], $object->data);
}

public function testOffsetUnset()
public function testOffsetUnset(): void
{
$object = new ArrayAccessObject();
$object->offsetUnset('b');
Expand Down
2 changes: 1 addition & 1 deletion tests/ArrayHelper/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function dataFilter(): array
],
['A.B'],
],
'nestedlArray' => [
'nestedArray' => [
[
'A' => [
'D' => [
Expand Down
7 changes: 4 additions & 3 deletions tests/ArrayHelper/GetValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Arrays\Tests\ArrayHelper;

use ArrayObject;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use stdClass;
use Yiisoft\Arrays\ArrayHelper;
Expand Down Expand Up @@ -265,7 +266,7 @@ public function testNonExistingMagicObjectProperty(): void
{
$magic = new Magic([]);

$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);

ArrayHelper::getValue($magic, 'name');
}
Expand All @@ -282,11 +283,11 @@ public function testNonExistingNestedMagicObjectProperty(): void
$order = new stdClass();
$order->magic = new Magic([]);

$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
ArrayHelper::getValueByPath($order, 'magic.name');
}

public function testGetValueFromInvalidArray()
public function testGetValueFromInvalidArray(): void
{
$this->expectExceptionMessage(
'getValue() can not get value from integer. Only array and object are supported.'
Expand Down
13 changes: 7 additions & 6 deletions tests/ArrayHelper/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Yiisoft\Arrays\Tests\ArrayHelper;

use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Yiisoft\Arrays\ArrayHelper;

Expand Down Expand Up @@ -171,9 +172,9 @@ static function ($element) {
$this->assertEquals($expected, $result);
}

public function testInvalidIndex()
public function testInvalidIndex(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$array = [
['id' => '123', 'data' => 'abc'],
['id' => '345', 'data' => 'def'],
Expand All @@ -182,9 +183,9 @@ public function testInvalidIndex()
ArrayHelper::index($array, 'id');
}

public function testInvalidIndexWithoutKey()
public function testInvalidIndexWithoutKey(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$array = [
['id' => '123', 'data' => 'abc'],
['id' => '345', 'data' => 'def'],
Expand All @@ -195,13 +196,13 @@ public function testInvalidIndexWithoutKey()

public function testInvalidIndexGroupBy(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
ArrayHelper::index(['id' => '1'], null, ['id']);
}

public function testInvalidIndexGroupByWithKey(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
ArrayHelper::index(['id' => '1'], 'id', ['id']);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/ArrayHelper/ToArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Yiisoft\Arrays\Tests\Objects\Post1;
use Yiisoft\Arrays\Tests\Objects\Post2;
use Yiisoft\Arrays\Tests\Objects\Post3;
use function get_class;
use function strlen;

final class ToArrayTest extends TestCase
{
Expand Down
10 changes: 9 additions & 1 deletion tests/Objects/Magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Yiisoft\Arrays\Tests\Objects;

use InvalidArgumentException;
use function array_key_exists;

final class Magic
{
private array $attributes;
Expand All @@ -16,7 +19,7 @@ public function __construct(array $attributes)
public function __get(string $attribute)
{
if (!array_key_exists($attribute, $this->attributes)) {
throw new \InvalidArgumentException("There is no \"$attribute\"");
throw new InvalidArgumentException("There is no \"$attribute\"");
}

return $this->attributes[$attribute];
Expand All @@ -26,4 +29,9 @@ public function __set(string $attribute, $value)
{
$this->attributes[$attribute] = $value;
}

public function __isset(string $attribute): bool
{
return array_key_exists($attribute, $this->attributes);
}
}
15 changes: 0 additions & 15 deletions tests/bootstrap.php

This file was deleted.