Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Contributing to Yii2

- [Report an issue](https://github.com/yiisoft/yii2/blob/master/docs/internals/report-an-issue.md)
- [Translate documentation or messages](https://github.com/yiisoft/yii2/blob/master/docs/internals/translation-workflow.md)
- [Give us feedback or start a design discussion](http://www.yiiframework.com/forum/index.php/forum/42-general-discussions-for-yii-20/)
- [Give us feedback or start a design discussion](https://www.yiiframework.com/forum/index.php/forum/42-general-discussions-for-yii-20/)
- [Contribute to the core code or fix bugs](https://github.com/yiisoft/yii2/blob/master/docs/internals/git-workflow.md)
3 changes: 2 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# These are supported funding model platforms

github: [cebe]
open_collective: yiisoft
github: [yiisoft]
tidelift: "packagist/yiisoft/yii2-bootstrap5"
19 changes: 12 additions & 7 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<!--
Please use this issue tracker for bugs and feature requests only. In case you need support please use one of
Yii communities listed at https://github.com/yiisoft/yii2/wiki/communities
-->

### What steps will reproduce the problem?

### What's expected?
### What is the expected result?

### What do you get instead?


### Additional info

| Q | A
| ---------------------- | ---
| Yii version |
| Yii Collection version |
| PHP version |
| Operating system |
| Q | A
| ---------------- | ---
| Yii vesion |
| PHP version |
| Operating system |
9 changes: 4 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
| Q | A
| ------------- | ---
| Is bugfix? | yes/no
| New feature? | yes/no
| Breaks BC? | yes/no
| Tests pass? | yes/no
| Fixed issues | comma-separated list of tickets # fixed by the PR, if any
| Is bugfix? | ✔️/❌
| New feature? | ✔️/❌
| Breaks BC? | ✔️/❌
| Fixed issues | <!-- comma-separated list of tickets # fixed by the PR, if any -->
6 changes: 6 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Security Policy

Please use the [security issue form](https://www.yiiframework.com/security) to report to us any security issue you find in Yii.
DO NOT use the issue tracker or discuss it in the public forum as it will cause more damage than help.

Please note that as a non-commercial OpenSource project we are not able to pay bounties at the moment.
31 changes: 31 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'psalm.xml'

name: build

jobs:
phpunit:
uses: yiisoft/actions/.github/workflows/phpunit.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
39 changes: 0 additions & 39 deletions .travis.yml

This file was deleted.

9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
}
],
"require": {
"php": ">=5.6.0",
"php": ">=7.3",
"yiisoft/yii2": "~2.0.14"
},
"require-dev": {
"phpunit/phpunit": "<7"
"phpunit/phpunit": "^9.6"
},
"repositories": [
{
Expand All @@ -40,5 +40,10 @@
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true
}
}
}
37 changes: 25 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./tests/bootstrap.php"
colors="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>

<php>
<ini name="error_reporting" value="-1"/>
</php>

<testsuites>
<testsuite name="Yii2-Collection">
<directory>./tests</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
</phpunit>
6 changes: 3 additions & 3 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* @author Carsten Brandt <[email protected]>
* @since 1.0
*/
class Collection extends Component implements ArrayAccess, IteratorAgregate, Countable
class Collection extends Component implements ArrayAccess, IteratorAggregate, Countable
{
use ArrayAccessTrait;

Expand All @@ -74,7 +74,7 @@ public function __construct(array $data, array $config = [])
*
* @return array the reference to collection data.
*/
public function &getData()
public function getData()
{
return $this->data;
}
Expand Down Expand Up @@ -560,7 +560,7 @@ public function paginate(Pagination $pagination, $preserveKeys = false)
* @return void
* @throws InvalidCallException
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
throw new InvalidCallException('Read only collection');
}
Expand Down
67 changes: 18 additions & 49 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

namespace yiiunit\collection;

use yii\data\Pagination;
use yii\base\InvalidArgumentException;
use yii\base\InvalidCallException;
use yii\collection\Collection;
use yii\data\Pagination;
use yiiunit\collection\models\Customer;

class CollectionTest extends TestCase
Expand Down Expand Up @@ -44,42 +46,6 @@ public function testIterator()
$this->assertEquals(3, $it);
}

public function testIteratorCurrent()
{
$models = $this->getIteratorModels();
$collection = new Collection($models);
$this->assertSame($models[0], $collection->current());
}

public function testIteratorKey()
{
$models = $this->getIteratorModels();
$collection = new Collection($models);
$this->assertSame(0, $collection->key());
}

public function testIteratorNext()
{
$models = $this->getIteratorModels();
$collection = new Collection($models);
$collection->next();
$this->assertSame($models[1], $collection->current());
$collection->next();
$this->assertSame($models[2], $collection->current());
$collection->next();
$this->assertFalse($collection->current());
}

public function testIteratorValid()
{
$collection = new Collection([]);
$this->assertFalse($collection->valid());

$models = $this->getIteratorModels();
$collection = new Collection($models);
$this->assertTrue($collection->valid());
}

public function testArrayAccessRead()
{
$models = [
Expand Down Expand Up @@ -117,46 +83,48 @@ public function testArrayAccessRead()
$this->assertFalse(isset($collection['four']));
}

/**
* @expectedException \yii\base\InvalidCallException
*/
public function testArrayAccessWrite()
{
$models = [
'one' => new Customer(['id' => 1]),
'two' => new Customer(['id' => 2]),
'three' => new Customer(['id' => 3]),
];

$this->expectException(InvalidCallException::class);
$this->expectExceptionMessage('Read only collection');

$collection = new Collection($models);
$collection['three'] = 'test';
}

/**
* @expectedException \yii\base\InvalidCallException
*/
public function testArrayAccessWrite2()
{
$models = [
'one' => new Customer(['id' => 1]),
'two' => new Customer(['id' => 2]),
'three' => new Customer(['id' => 3]),
];

$this->expectException(InvalidCallException::class);
$this->expectExceptionMessage('Read only collection');

$collection = new Collection($models);
$collection[] = 'test';
}

/**
* @expectedException \yii\base\InvalidCallException
*/
public function testArrayAccessUnset()
{
$models = [
'one' => new Customer(['id' => 1]),
'two' => new Customer(['id' => 2]),
'three' => new Customer(['id' => 3]),
];

$collection = new Collection($models);
unset($collection['two']);

$this->expectNotToPerformAssertions();
}

public function testCountable()
Expand Down Expand Up @@ -363,13 +331,14 @@ public function testMerge()
$this->assertEquals([1, 2, 3, 'a', 'b', 'c'], $collection2->merge($data1)->getData());
}

/**
* @expectedException \yii\base\InvalidArgumentException
*/
public function testMergeWrongType()
{
$data1 = ['a', 'b', 'c'];
$collection1 = new Collection($data1);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Collection can only be merged with an array or other collections.');

$collection1->merge('string');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ModelCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ModelCollectionTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
$this->mockApplication();

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
/**
* {@inheritdoc}
*/
protected function setUp()
protected function setUp(): void
{
$this->mockApplication();

Expand All @@ -37,7 +37,7 @@ protected function setUp()
* Clean up after test.
* By default the application created with [[mockApplication]] will be destroyed.
*/
protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->destroyApplication();
Expand Down