forceedge01 / sql-api-wrapper

A decorator around the sql extension API, gives powerful tools to create fixture data for tests quickly.
3 stars 1 forks source link

Bridge mechanism broken #22

Closed forceedge01 closed 5 years ago

forceedge01 commented 6 years ago

The bridge receives the class with full namespace of the one trying to call which is not valid. It should receive the class that links to the bridge i.e an entity.

Sample implementation of bridge:

<?php

namespace Cdt\InsuranceBundle\Features\Bootstrap;

use Genesis\SQLExtensionWrapper\BridgeInterface;
use ReflectionClass;

/**
 * EntityBridge class.
 */
class EntityBridge implements BridgeInterface
{
    private static $entities = [];

    /**
     * @param string $dataModelClass
     *
     * @return string
     */
    public static function getBaseTable($bridgedClass)
    {
        if (! isset(self::$entities[$bridgedClass]['reflection'])) {
            self::$entities[$bridgedClass]['reflection'] = new ReflectionClass($bridgedClass);
        }

        return self::$entities[$bridgedClass]['reflection']->getShortName();
    }

    /**
     * @param string $dataModelClass
     *
     * @return array
     */
    public static function getDataMapping($bridgedClass)
    {
        if (! isset(self::$entities[$bridgedClass]['dataMapping'])) {
            $reflection = self::$entities[$bridgedClass]['reflection'];
            $dataMapping = [];
            foreach ($reflection->getProperties() as $property) {
                $dataMapping[$property->name] = strtolower($property->name);
            }

            self::$entities[$bridgedClass]['dataMapping'] = $dataMapping;
        }

        return self::$entities[$bridgedClass]['dataMapping'];
    }
}

Changes goes with PR https://github.com/forceedge01/sql-api-wrapper/pull/19/files. Needs lots of unit and behavioural testing.