EntityDataObjectBuilder.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace tests\unit\Util;
  7. use Magento\FunctionalTestingFramework\DataGenerator\Objects\EntityDataObject;
  8. class EntityDataObjectBuilder
  9. {
  10. /**
  11. * Array of data fields for the object. Has fields contained by default.
  12. *
  13. * @var array
  14. */
  15. private $data = [
  16. "name" => "Hopper",
  17. "gpa" => "3.5678",
  18. "phone" => "5555555",
  19. "isprimary" => "true"
  20. ];
  21. /**
  22. * Name of the data object.
  23. *
  24. * @var string
  25. */
  26. private $name = "testDataObject";
  27. /**
  28. * Name of the data object type (e.g. customer, category etc.)
  29. *
  30. * @var string
  31. */
  32. private $type = "testType";
  33. /**
  34. * A flat array containing linked entity name => linked entity type.
  35. *
  36. * @var array
  37. */
  38. private $linkedEntities = [];
  39. /**
  40. * An array contain references to data to be resolved by the api.
  41. *
  42. * @var array
  43. */
  44. private $vars = [];
  45. /**
  46. * A function which will build an Entity Data Object with the params specified by the object.
  47. *
  48. * @return EntityDataObject
  49. */
  50. public function build()
  51. {
  52. return new EntityDataObject(
  53. $this->name,
  54. $this->type,
  55. $this->data,
  56. $this->linkedEntities,
  57. null,
  58. $this->vars
  59. );
  60. }
  61. /**
  62. * Sets the name of the EntityDataObject.
  63. *
  64. * @param string $name
  65. * @return EntityDataObjectBuilder
  66. */
  67. public function withName($name)
  68. {
  69. $this->name = $name;
  70. return $this;
  71. }
  72. /**
  73. * Sets the type of the EntityDataObject.
  74. *
  75. * @param string $type
  76. * @return EntityDataObjectBuilder
  77. */
  78. public function withType($type)
  79. {
  80. $this->type = $type;
  81. return $this;
  82. }
  83. /**
  84. * Sets the data fields on the object to the data field array specified in the argument.
  85. *
  86. * @param array $fields
  87. * @return EntityDataObjectBuilder
  88. */
  89. public function withDataFields($fields)
  90. {
  91. $this->data = $fields;
  92. return $this;
  93. }
  94. /**
  95. * Sets the linked entities specified by the user as a param for Entity Data Object creation.
  96. *
  97. * @param array $linkedEntities
  98. * @return EntityDataObjectBuilder
  99. */
  100. public function withLinkedEntities($linkedEntities)
  101. {
  102. $this->linkedEntities = $linkedEntities;
  103. return $this;
  104. }
  105. }