HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/magento.bikenow.co/vendor/vertex/sdk/tests/Unit/MapperFactoryTest.php
<?php declare(strict_types=1);

/**
 * @copyright  Vertex. All rights reserved.  https://www.vertexinc.com/
 * @author     Mediotype Development         <diveinto@mediotype.com>
 */

namespace Vertex\Test\Unit;

use PHPUnit\Framework\TestCase;
use Vertex\Data\Address;
use Vertex\Data\AddressInterface;
use Vertex\Data\Configuration;
use Vertex\Data\ConfigurationInterface;
use Vertex\Data\Login;
use Vertex\Mapper\MapperFactory;

/**
 * Tests for {@see MapperFactory}
 */
class MapperFactoryTest extends TestCase
{
    /** @var MapperFactory */
    private $mapperFactory;

    /**
     * @inheritdoc
     */
    protected function setUp(): void
    {
        parent::setUp();

        $this->mapperFactory = new MapperFactory(
            [
                AddressInterface::class => [
                    '60' => Address::class,
                    '70' => Login::class,
                ],
                ConfigurationInterface::class => [
                    '60' => Configuration::class
                ]
            ]
        );
    }

    /**
     * Provide data for tests
     *
     * Returns an array of arrays, where the value is the three parameters used by the below tests:
     * - Interface to query against MapperFactory
     * - Object type we expect to be returned
     * - API Level
     *
     * @return array
     */
    public function getDataForTest()
    {
        return [
            [AddressInterface::class, Address::class, '60'],
            [AddressInterface::class, Login::class, '70'],
            [ConfigurationInterface::class, Configuration::class, '60']
        ];
    }

    /**
     * Test method createForClass
     *
     * Ensure that the expected object type is returned
     *
     * @dataProvider getDataForTest
     * @param string $interface
     * @param string $result
     * @param string $apiLevel
     * @return void
     */
    public function testCreateForClass($interface, $result, $apiLevel)
    {
        $object = $this->mapperFactory->createForClass($interface, $apiLevel);
        $this->assertInstanceOf($result, $object);
    }

    /**
     * Test method getForClass
     *
     * Ensure that when called twice, the second object is the same instance as the first object
     *
     * @dataProvider getDataForTest
     * @param string $interface
     * @param string $result
     * @param string $apiLevel
     * @return void
     */
    public function testGetForClass($interface, $result, $apiLevel)
    {
        $object = $this->mapperFactory->getForClass($interface, $apiLevel);
        $this->assertInstanceOf($result, $object);
        $object2 = $this->mapperFactory->getForClass($interface, $apiLevel);
        $this->assertEquals($object, $object2);
    }
}