Skip to content

Commit

Permalink
Merge branch 'release-15.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
shpran committed Sep 24, 2021
2 parents 6e6a515 + 537ef12 commit cf6a240
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
21 changes: 20 additions & 1 deletion core/resource/DependsOnPropertyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,27 @@
use core_kernel_classes_Property;

/**
* @method core_kernel_classes_Property current()
* @method core_kernel_classes_Property|null current()
*/
class DependsOnPropertyCollection extends ArrayIterator
{
public function isEqual(DependsOnPropertyCollection $dependsOnPropertyCollection): bool
{
return $this->areArraysEqual($this->getPropertyUris(), $dependsOnPropertyCollection->getPropertyUris());
}

public function getPropertyUris(): array
{
return array_map(
static function (core_kernel_classes_Property $property) {
return $property->getUri();
},
$this->getArrayCopy()
);
}

private function areArraysEqual(array $array1, array $array2): bool
{
return empty(array_diff($array1, $array2)) && empty(array_diff($array2, $array1));
}
}
83 changes: 83 additions & 0 deletions test/unit/core/resource/DependsOnPropertyCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2021 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\generis\test\unit\model\resource;

use oat\generis\test\TestCase;
use core_kernel_classes_Property;
use oat\generis\model\resource\DependsOnPropertyCollection;

class DependsOnPropertyCollectionTest extends TestCase
{
/** @var DependsOnPropertyCollection */
private $sut;

protected function setUp(): void
{
$this->sut = new DependsOnPropertyCollection();
}

public function testIsEqual(): void
{
$dependsOnPropertyCollection = new DependsOnPropertyCollection();
$this->assertTrue($this->sut->isEqual($dependsOnPropertyCollection));

$firstProperty = $this->createMock(core_kernel_classes_Property::class);
$firstProperty
->method('getUri')
->willReturn('firstProperty');
$dependsOnPropertyCollection->append($firstProperty);
$this->assertFalse($this->sut->isEqual($dependsOnPropertyCollection));

$secondProperty = $this->createMock(core_kernel_classes_Property::class);
$secondProperty
->method('getUri')
->willReturn('secondProperty');
$this->sut->append($secondProperty);
$this->assertFalse($this->sut->isEqual($dependsOnPropertyCollection));

$dependsOnPropertyCollection->append($secondProperty);
$this->assertFalse($this->sut->isEqual($dependsOnPropertyCollection));

$this->sut->append($firstProperty);
$this->assertTrue($this->sut->isEqual($dependsOnPropertyCollection));
}

public function testGetPropertyUris(): void
{
$this->assertEmpty($this->sut->getPropertyUris());

$firstProperty = $this->createMock(core_kernel_classes_Property::class);
$firstProperty
->method('getUri')
->willReturn('firstProperty');
$this->sut->append($firstProperty);
$this->assertEquals(['firstProperty'], $this->sut->getPropertyUris());

$secondProperty = $this->createMock(core_kernel_classes_Property::class);
$secondProperty
->method('getUri')
->willReturn('secondProperty');
$this->sut->append($secondProperty);
$this->assertEquals(['firstProperty', 'secondProperty'], $this->sut->getPropertyUris());
}
}

0 comments on commit cf6a240

Please sign in to comment.