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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"require-dev": {
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^10.0",
"phpunit/phpunit": "^12.5",
"respect/coding-standard": "^5.0",
"squizlabs/php_codesniffer": "^4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:
- tests/
ignoreErrors:
- message: '/Call to an undefined (static )?method Respect\\Data\\(AbstractMapper|Collections\\(Collection|Filtered|Mix|Typed))::\w+\(\)\./'
- message: '/Access to an undefined property Respect\\Data\\Collections\\Collection::\$\w+\./'
- message: '/Access to an undefined property Respect\\Data\\(AbstractMapper|Collections\\Collection)::\$\w+\./'
- message: '/Unsafe usage of new static\(\)\./'
-
message: '/Expression .+ on a separate line does not do anything\./'
Expand Down
13 changes: 10 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<phpunit bootstrap="vendor/autoload.php" colors="false" stopOnFailure="false" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnPhpunitDeprecations="true" failOnDeprecation="false">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Default">
<testsuite name="unit">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion src/AbstractMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function remove(object $object, Collection $fromCollection): bool

public function isTracked(object $entity): bool
{
return $this->tracked->contains($entity);
return $this->tracked->offsetExists($entity);
}

protected function fetchHydrated(Collection $collection, mixed $statement): SplObjectStorage|false
Expand Down
33 changes: 25 additions & 8 deletions tests/AbstractMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@

namespace Respect\Data;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Respect\Data\Collections\Collection;

class AbstractMapperTest extends \PHPUnit\Framework\TestCase
#[CoversClass(AbstractMapper::class)]
class AbstractMapperTest extends TestCase
{
protected $mapper;
protected AbstractMapper $mapper;

protected function setUp(): void
{
parent::setUp();
$this->mapper = $this->getMockForAbstractClass('Respect\Data\AbstractMapper');
$this->mapper = new class extends AbstractMapper {
protected function createStatement(Collection $fromCollection, mixed $withExtra = null): mixed
{
return null;
}

public function flush(): void
{
}
};
}

function test_registerCollection_should_add_collection_to_pool()
#[Test]
public function registerCollection_should_add_collection_to_pool(): void
{
$coll = Collection::foo();
$this->mapper->registerCollection('my_alias', $coll);
Expand All @@ -28,7 +41,8 @@ function test_registerCollection_should_add_collection_to_pool()
$this->assertEquals($coll, $this->mapper->my_alias);
}

function test_magic_setter_should_add_collection_to_pool()
#[Test]
public function magic_setter_should_add_collection_to_pool(): void
{
$coll = Collection::foo();
$this->mapper->my_alias = $coll;
Expand All @@ -40,14 +54,17 @@ function test_magic_setter_should_add_collection_to_pool()
$this->assertEquals($coll, $this->mapper->my_alias);
}

function test_magic_call_should_bypass_to_collection()
#[Test]
public function magic_call_should_bypass_to_collection(): void
{
$collection = $this->mapper->foo()->bar()->baz();
$expected = Collection::foo();
$expected->setMapper($this->mapper);
$this->assertEquals($expected->bar->baz, $collection);
}
function test_magic_getter_should_bypass_to_collection()

#[Test]
public function magic_getter_should_bypass_to_collection(): void
{
$collection = $this->mapper->foo->bar->baz;
$expected = Collection::foo();
Expand Down
34 changes: 23 additions & 11 deletions tests/CollectionIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,74 @@

namespace Respect\Data;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Respect\Data\Collections\Collection;

class CollectionIteratorTest extends \PHPUnit\Framework\TestCase
#[CoversClass(CollectionIterator::class)]
class CollectionIteratorTest extends TestCase
{
function test_static_builder_should_create_recursive_iterator()
#[Test]
public function static_builder_should_create_recursive_iterator(): void
{
$this->assertInstanceOf(
'RecursiveIteratorIterator',
CollectionIterator::recursive(Collection::foo())
);
}

function test_constructing_should_accept_collections_or_arrays()
#[Test]
public function constructing_should_accept_collections_or_arrays(): void
{
$iterator = new CollectionIterator(Collection::foo());
$iterator2 = new CollectionIterator(array(Collection::foo()));
$this->assertEquals($iterator, $iterator2);
}

function test_key_should_track_nameCounts()
#[Test]
public function key_should_track_nameCounts(): void
{
$i = new CollectionIterator(Collection::foo());
$this->assertEquals('foo', $i->key());
$this->assertEquals('foo2', $i->key());
$this->assertEquals('foo3', $i->key());
}

function test_hasChildren_consider_empties()
#[Test]
public function hasChildren_consider_empties(): void
{
$coll = Collection::foo();
$iterator = new CollectionIterator($coll);
$this->assertFalse($iterator->hasChildren());
}

function test_hasChildren_use_collection_children()
#[Test]
public function hasChildren_use_collection_children(): void
{
$coll = Collection::foo(Collection::bar());
$iterator = new CollectionIterator($coll);
$this->assertTrue($iterator->hasChildren());
}

function test_hasChildren_use_collection_next()
#[Test]
public function hasChildren_use_collection_next(): void
{
$coll = Collection::foo()->bar;
$iterator = new CollectionIterator($coll);
$this->assertTrue($iterator->hasChildren());
}

function test_getChildren_consider_empties()
#[Test]
public function getChildren_consider_empties(): void
{
$coll = Collection::foo();
$iterator = new CollectionIterator($coll);
$this->assertEquals(new CollectionIterator(), $iterator->getChildren());
}

function test_getChildren_use_collection_children()
#[Test]
public function getChildren_use_collection_children(): void
{
$coll = Collection::foo(Collection::bar(), Collection::baz());
list($foo_child, $bar_child) = $coll->getChildren();
Expand All @@ -68,11 +80,11 @@ function test_getChildren_use_collection_children()
$this->assertContains($bar_child, $items);
}

function test_getChildren_use_collection_next()
#[Test]
public function getChildren_use_collection_next(): void
{
$coll = Collection::foo()->bar;
$iterator = new CollectionIterator($coll);
$this->assertTrue($iterator->hasChildren());
}

}
Loading
Loading