EntityDataObjectBuilder.php 2.48 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace tests\unit\Util;

use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;

class EntityDataObjectBuilder
{
    /**
     * Array of data fields for the object. Has fields contained by default.
     *
     * @var array
     */
    private $data = [
        "name" => "Hopper",
        "gpa" => "3.5678",
        "phone" => "5555555",
        "isprimary" => "true"
    ];

    /**
     * Name of the data object.
     *
     * @var string
     */
    private $name = "testDataObject";

    /**
     * Name of the data object type (e.g. customer, category etc.)
     *
     * @var string
     */
    private $type = "testType";

    /**
     * A flat array containing linked entity name => linked entity type.
     *
     * @var array
     */
    private $linkedEntities = [];

    /**
     * An array contain references to data to be resolved by the api.
     *
     * @var array
     */
    private $vars = [];

    /**
     * A function which will build an Entity Data Object with the params specified by the object.
     *
     * @return EntityDataObject
     */
    public function build()
    {
        return new EntityDataObject(
            $this->name,
            $this->type,
            $this->data,
            $this->linkedEntities,
            null,
            $this->vars
        );
    }

    /**
     * Sets the name of the EntityDataObject.
     *
     * @param string $name
     * @return EntityDataObjectBuilder
     */
    public function withName($name)
    {
        $this->name = $name;
        return $this;
    }

    /**
     * Sets the type of the EntityDataObject.
     *
     * @param string $type
     * @return EntityDataObjectBuilder
     */
    public function withType($type)
    {
        $this->type = $type;
        return $this;
    }

    /**
     * Sets the data fields on the object to the data field array specified in the argument.
     *
     * @param array $fields
     * @return EntityDataObjectBuilder
     */
    public function withDataFields($fields)
    {
        $this->data = $fields;
        return $this;
    }

    /**
     * Sets the linked entities specified by the user as a param for Entity Data Object creation.
     *
     * @param array $linkedEntities
     * @return EntityDataObjectBuilder
     */
    public function withLinkedEntities($linkedEntities)
    {
        $this->linkedEntities = $linkedEntities;
        return $this;
    }
}