# quadmenu/3.3.7/vendor/franmastromarino/wp-orm/tests/Collection/CollectionMapperTest.php

QuadMenu – Mega Menu, version 3.3.7. 60 lines.

- Page: https://pluginprobe.com/plugins/quadmenu/3.3.7/code/vendor/franmastromarino/wp-orm/tests/Collection/CollectionMapperTest.php
- Raw: https://pluginprobe.com/plugins/quadmenu/3.3.7/raw/vendor/franmastromarino/wp-orm/tests/Collection/CollectionMapperTest.php
- Modified: 2025-11-15T21:00:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/quadmenu/3.3.7/code/vendor/franmastromarino/wp-orm/tests/Collection/CollectionMapperTest.php#L10-L20`.

```php
<?php

namespace QuadLayers\WP_Orm\Tests\Collection\Mapper;

use PHPUnit\Framework\TestCase;
use QuadLayers\WP_Orm\Entity\CollectionEntity;
use QuadLayers\WP_Orm\Entity\EntityInterface;
use QuadLayers\WP_Orm\Factory\CollectionFactory;
use QuadLayers\WP_Orm\Mapper\CollectionMapper;
use QuadLayers\WP_Orm\Tests\Collection\CollectionEntityTest;

class CollectionMapperTest extends TestCase
{
    private array $testValue;
    private EntityInterface $entity;
    private CollectionFactory $factory;
    private CollectionMapper $mapper;

    protected function setUp(): void
    {

        $entity = new CollectionEntityTest();

        $this->testValue = $entity->getDefaults();

        $this->factory = new CollectionFactory('\QuadLayers\WP_Orm\Tests\Collection\CollectionEntityTest');
        $this->mapper = new CollectionMapper($this->factory);
        $this->entity = $this->mapper->toEntity($this->testValue);
    }

    public function testToEntity()
    {

        $entity = $this->mapper->toEntity($this->testValue);

        $this->assertInstanceOf(CollectionEntity::class, $entity);
        $this->assertEquals($this->testValue['key1'], $entity->getKey1());
        $this->assertEquals($this->testValue['key2'], $entity->getKey2());
    }

    public function testToArray()
    {

        // Then we convert the entity back to an array
        $array = $this->mapper->toArray($this->entity);

        // Check if the original array and the result are the same
        $this->assertEquals(['id' => 0], $array);
    }

    public function testEntityHasDefaultAttributes()
    {

        $entity = $this->mapper->toEntity([]);

        $this->assertEquals($this->testValue['key1'], $entity->getKey1());
        $this->assertEquals($this->testValue['key2'], $entity->getKey2());
    }
}

```
