Skip to content

Commit

Permalink
Test DTO generator feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Mar 4, 2024
1 parent e47b2ff commit 6d46d98
Show file tree
Hide file tree
Showing 6 changed files with 3,339 additions and 95 deletions.
70 changes: 67 additions & 3 deletions config/dto.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,70 @@
<field name="dueOn" type="string"/>
</dto>

<dto name="Test/Schema/Assignee">
<field name="name" type="string"/>
<field name="email" type="string"/>
<field name="login" type="string" required="true"/>
<field name="id" type="int" required="true"/>
<field name="nodeId" type="string" required="true"/>
<field name="avatarUrl" type="string" required="true"/>
<field name="gravatarId" type="string"/>
<field name="url" type="string" required="true"/>
<field name="htmlUrl" type="string" required="true"/>
<field name="followersUrl" type="string" required="true"/>
<field name="followingUrl" type="string" required="true"/>
<field name="gistsUrl" type="string" required="true"/>
<field name="starredUrl" type="string" required="true"/>
<field name="subscriptionsUrl" type="string" required="true"/>
<field name="organizationsUrl" type="string" required="true"/>
<field name="reposUrl" type="string" required="true"/>
<field name="eventsUrl" type="string" required="true"/>
<field name="receivedEventsUrl" type="string" required="true"/>
<field name="type" type="string" required="true"/>
<field name="siteAdmin" type="bool" required="true"/>
<field name="starredAt" type="string"/>
</dto>

<dto name="Test/Schema/RequestedReviewer">
<field name="name" type="string"/>
<field name="email" type="string"/>
<field name="login" type="string" required="true"/>
<field name="id" type="int" required="true"/>
<field name="nodeId" type="string" required="true"/>
<field name="avatarUrl" type="string" required="true"/>
<field name="gravatarId" type="string"/>
<field name="url" type="string" required="true"/>
<field name="htmlUrl" type="string" required="true"/>
<field name="followersUrl" type="string" required="true"/>
<field name="followingUrl" type="string" required="true"/>
<field name="gistsUrl" type="string" required="true"/>
<field name="starredUrl" type="string" required="true"/>
<field name="subscriptionsUrl" type="string" required="true"/>
<field name="organizationsUrl" type="string" required="true"/>
<field name="reposUrl" type="string" required="true"/>
<field name="eventsUrl" type="string" required="true"/>
<field name="receivedEventsUrl" type="string" required="true"/>
<field name="type" type="string" required="true"/>
<field name="siteAdmin" type="bool" required="true"/>
<field name="starredAt" type="string"/>
</dto>

<dto name="Test/Schema/RequestedTeam">
<field name="id" type="int" required="true"/>
<field name="nodeId" type="string" required="true"/>
<field name="url" type="string" required="true"/>
<field name="membersUrl" type="string" required="true"/>
<field name="name" type="string" required="true"/>
<field name="description" type="string"/>
<field name="permission" type="string" required="true"/>
<field name="privacy" type="string"/>
<field name="notificationSetting" type="string"/>
<field name="htmlUrl" type="string" required="true"/>
<field name="repositoriesUrl" type="string" required="true"/>
<field name="slug" type="string" required="true"/>
<field name="ldapDn" type="string"/>
</dto>

<dto name="Test/Schema/Owner">
<field name="avatarUrl" type="string" required="true"/>
<field name="eventsUrl" type="string" required="true"/>
Expand Down Expand Up @@ -266,9 +330,9 @@
<field name="mergedAt" type="string"/>
<field name="mergeCommitSha" type="string"/>
<field name="assignee" type="Test/Schema/SimpleUser"/>
<field name="assignees" type="array"/>
<field name="requestedReviewers" type="array"/>
<field name="requestedTeams" type="array"/>
<field name="assignees" type="Test/Schema/Assignee[]" singular="assignee" associative="true" key="login"/>
<field name="requestedReviewers" type="Test/Schema/RequestedReviewer[]" singular="requestedReviewer" associative="true" key="login"/>
<field name="requestedTeams" type="Test/Schema/RequestedTeam[]" singular="requestedTeam" associative="true" key="slug"/>
<field name="head" type="Test/Schema/Head" required="true"/>
<field name="base" type="Test/Schema/Base" required="true"/>
<field name="authorAssociation" type="string" required="true"/>
Expand Down
132 changes: 116 additions & 16 deletions src/Dto/Test/Data/ObjectDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,12 @@ class ObjectDto extends \CakeDto\Dto\AbstractDto {
'labels' => [
'name' => 'labels',
'type' => '\App\Dto\Test\Data\LabelDto[]|\ArrayObject',
'associative' => true,
'key' => 'name',
'required' => false,
'defaultValue' => null,
'dto' => null,
'collectionType' => '\ArrayObject',
'associative' => false,
'key' => null,
'serialize' => null,
'factory' => null,
'singularType' => '\App\Dto\Test\Data\LabelDto',
Expand Down Expand Up @@ -678,12 +678,12 @@ class ObjectDto extends \CakeDto\Dto\AbstractDto {
'assignees' => [
'name' => 'assignees',
'type' => '\App\Dto\Test\Data\AssigneeDto[]|\ArrayObject',
'associative' => true,
'key' => 'login',
'required' => false,
'defaultValue' => null,
'dto' => null,
'collectionType' => '\ArrayObject',
'associative' => false,
'key' => null,
'serialize' => null,
'factory' => null,
'singularType' => '\App\Dto\Test\Data\AssigneeDto',
Expand All @@ -693,12 +693,12 @@ class ObjectDto extends \CakeDto\Dto\AbstractDto {
'requestedReviewers' => [
'name' => 'requestedReviewers',
'type' => '\App\Dto\Test\Data\RequestedReviewerDto[]|\ArrayObject',
'associative' => true,
'key' => 'login',
'required' => false,
'defaultValue' => null,
'dto' => null,
'collectionType' => '\ArrayObject',
'associative' => false,
'key' => null,
'serialize' => null,
'factory' => null,
'singularType' => '\App\Dto\Test\Data\RequestedReviewerDto',
Expand All @@ -708,12 +708,12 @@ class ObjectDto extends \CakeDto\Dto\AbstractDto {
'requestedTeams' => [
'name' => 'requestedTeams',
'type' => '\App\Dto\Test\Data\RequestedTeamDto[]|\ArrayObject',
'associative' => true,
'key' => 'slug',
'required' => false,
'defaultValue' => null,
'dto' => null,
'collectionType' => '\ArrayObject',
'associative' => false,
'key' => null,
'serialize' => null,
'factory' => null,
'singularType' => '\App\Dto\Test\Data\RequestedTeamDto',
Expand Down Expand Up @@ -2007,6 +2007,21 @@ public function getLabels(): \ArrayObject {
return $this->labels;
}

/**
* @param string|int $key
*
* @return \App\Dto\Test\Data\LabelDto
*
* @throws \RuntimeException If value with this key is not set.
*/
public function getLabel($key): \App\Dto\Test\Data\LabelDto {
if (!isset($this->labels[$key])) {
throw new \RuntimeException(sprintf('Value not set for field `labels` and key `%s` (expected to be not null)', $key));
}

return $this->labels[$key];
}

/**
* @return bool
*/
Expand All @@ -2017,16 +2032,26 @@ public function hasLabels(): bool {

return $this->labels->count() > 0;
}

/**
* @param string|int $key
* @return bool
*/
public function hasLabel($key): bool {
return isset($this->labels[$key]);
}

/**
* @param string|int $key
* @param \App\Dto\Test\Data\LabelDto $label
* @return $this
*/
public function addLabel(\App\Dto\Test\Data\LabelDto $label) {
public function addLabel($key, \App\Dto\Test\Data\LabelDto $label) {
if ($this->labels === null) {
$this->labels = new \ArrayObject([]);
}

$this->labels[] = $label;
$this->labels[$key] = $label;
$this->_touchedFields[self::FIELD_LABELS] = true;

return $this;
Expand Down Expand Up @@ -2479,6 +2504,21 @@ public function getAssignees(): \ArrayObject {
return $this->assignees;
}

/**
* @param string|int $key
*
* @return \App\Dto\Test\Data\AssigneeDto
*
* @throws \RuntimeException If value with this key is not set.
*/
public function getAssignee($key): \App\Dto\Test\Data\AssigneeDto {

Check failure on line 2514 in src/Dto/Test/Data/ObjectDto.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Cannot redeclare method App\Dto\Test\Data\ObjectDto::getAssignee().

Check failure on line 2514 in src/Dto/Test/Data/ObjectDto.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Cannot redeclare method App\Dto\Test\Data\ObjectDto::getAssignee().
if (!isset($this->assignees[$key])) {
throw new \RuntimeException(sprintf('Value not set for field `assignees` and key `%s` (expected to be not null)', $key));
}

return $this->assignees[$key];
}

/**
* @return bool
*/
Expand All @@ -2489,16 +2529,26 @@ public function hasAssignees(): bool {

return $this->assignees->count() > 0;
}

/**
* @param string|int $key
* @return bool
*/
public function hasAssignee($key): bool {

Check failure on line 2537 in src/Dto/Test/Data/ObjectDto.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Cannot redeclare method App\Dto\Test\Data\ObjectDto::hasAssignee().

Check failure on line 2537 in src/Dto/Test/Data/ObjectDto.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Cannot redeclare method App\Dto\Test\Data\ObjectDto::hasAssignee().
return isset($this->assignees[$key]);
}

/**
* @param string|int $key
* @param \App\Dto\Test\Data\AssigneeDto $assignee
* @return $this
*/
public function addAssignee(\App\Dto\Test\Data\AssigneeDto $assignee) {
public function addAssignee($key, \App\Dto\Test\Data\AssigneeDto $assignee) {
if ($this->assignees === null) {
$this->assignees = new \ArrayObject([]);
}

$this->assignees[] = $assignee;
$this->assignees[$key] = $assignee;
$this->_touchedFields[self::FIELD_ASSIGNEES] = true;

return $this;
Expand Down Expand Up @@ -2527,6 +2577,21 @@ public function getRequestedReviewers(): \ArrayObject {
return $this->requestedReviewers;
}

/**
* @param string|int $key
*
* @return \App\Dto\Test\Data\RequestedReviewerDto
*
* @throws \RuntimeException If value with this key is not set.
*/
public function getRequestedReviewer($key): \App\Dto\Test\Data\RequestedReviewerDto {
if (!isset($this->requestedReviewers[$key])) {
throw new \RuntimeException(sprintf('Value not set for field `requestedReviewers` and key `%s` (expected to be not null)', $key));
}

return $this->requestedReviewers[$key];
}

/**
* @return bool
*/
Expand All @@ -2537,16 +2602,26 @@ public function hasRequestedReviewers(): bool {

return $this->requestedReviewers->count() > 0;
}

/**
* @param string|int $key
* @return bool
*/
public function hasRequestedReviewer($key): bool {
return isset($this->requestedReviewers[$key]);
}

/**
* @param string|int $key
* @param \App\Dto\Test\Data\RequestedReviewerDto $requestedReviewer
* @return $this
*/
public function addRequestedReviewer(\App\Dto\Test\Data\RequestedReviewerDto $requestedReviewer) {
public function addRequestedReviewer($key, \App\Dto\Test\Data\RequestedReviewerDto $requestedReviewer) {
if ($this->requestedReviewers === null) {
$this->requestedReviewers = new \ArrayObject([]);
}

$this->requestedReviewers[] = $requestedReviewer;
$this->requestedReviewers[$key] = $requestedReviewer;
$this->_touchedFields[self::FIELD_REQUESTED_REVIEWERS] = true;

return $this;
Expand Down Expand Up @@ -2575,6 +2650,21 @@ public function getRequestedTeams(): \ArrayObject {
return $this->requestedTeams;
}

/**
* @param string|int $key
*
* @return \App\Dto\Test\Data\RequestedTeamDto
*
* @throws \RuntimeException If value with this key is not set.
*/
public function getRequestedTeam($key): \App\Dto\Test\Data\RequestedTeamDto {
if (!isset($this->requestedTeams[$key])) {
throw new \RuntimeException(sprintf('Value not set for field `requestedTeams` and key `%s` (expected to be not null)', $key));
}

return $this->requestedTeams[$key];
}

/**
* @return bool
*/
Expand All @@ -2585,16 +2675,26 @@ public function hasRequestedTeams(): bool {

return $this->requestedTeams->count() > 0;
}

/**
* @param string|int $key
* @return bool
*/
public function hasRequestedTeam($key): bool {
return isset($this->requestedTeams[$key]);
}

/**
* @param string|int $key
* @param \App\Dto\Test\Data\RequestedTeamDto $requestedTeam
* @return $this
*/
public function addRequestedTeam(\App\Dto\Test\Data\RequestedTeamDto $requestedTeam) {
public function addRequestedTeam($key, \App\Dto\Test\Data\RequestedTeamDto $requestedTeam) {
if ($this->requestedTeams === null) {
$this->requestedTeams = new \ArrayObject([]);
}

$this->requestedTeams[] = $requestedTeam;
$this->requestedTeams[$key] = $requestedTeam;
$this->_touchedFields[self::FIELD_REQUESTED_TEAMS] = true;

return $this;
Expand Down
Loading

0 comments on commit 6d46d98

Please sign in to comment.