Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Spamercz committed Apr 4, 2024
1 parent de50521 commit 7840985
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 297 deletions.
2 changes: 1 addition & 1 deletion doc/03_entity_class.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class People extends \Spameri\Elastic\Entity\Collection\AbstractElasticEntityCol
{
/** @var \SpameriTests\Elastic\Data\Entity\Person $entity */
foreach ($this->collection() as $entity) {
if ($imdb->value() === $entity->identification()->imdb()->value()) {
if ($imdb->value() === $entity->identification->imdb->value()) {
return $entity;
}
}
Expand Down
117 changes: 14 additions & 103 deletions tests/SpameriTests/Elastic/Data/Entity/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,28 @@

namespace SpameriTests\Elastic\Data\Entity;

class Person implements \Spameri\Elastic\Entity\ElasticEntityInterface
class Person extends \Spameri\Elastic\Entity\AbstractElasticEntity
{


public function __construct(
#[\Spameri\Elastic\Mapping\Entity(class: \Spameri\Elastic\Entity\Property\ElasticId::class)]
public \Spameri\Elastic\Entity\Property\ElasticIdInterface $id,
private \SpameriTests\Elastic\Data\Entity\Video\Identification $identification,
private \SpameriTests\Elastic\Data\Entity\Property\Name $name,
private \SpameriTests\Elastic\Data\Entity\Property\Description $description,
private \Spameri\Elastic\Entity\Property\Date|null $birth,
private \Spameri\Elastic\Entity\Property\Date|null $death,
private \SpameriTests\Elastic\Data\Entity\Property\Name $alias,

#[\Spameri\Elastic\Mapping\Collection(class: \SpameriTests\Elastic\Data\Entity\Person\Character::class)]
private \Spameri\Elastic\Entity\Collection\AbstractEntityCollection $characters,

#[\Spameri\Elastic\Mapping\Collection(class: \SpameriTests\Elastic\Data\Entity\Person\Job::class)]
private \Spameri\Elastic\Entity\Collection\EntityCollection $jobs,
public \SpameriTests\Elastic\Data\Entity\Video\Identification $identification,
public \SpameriTests\Elastic\Data\Entity\Property\Name $name,
public \SpameriTests\Elastic\Data\Entity\Property\Description $description,
public \Spameri\Elastic\Entity\Property\Date|null $birth,
public \Spameri\Elastic\Entity\Property\Date|null $death,
public \SpameriTests\Elastic\Data\Entity\Property\Name $alias,

#[\Spameri\Elastic\Mapping\Collection]
public \Spameri\Elastic\Entity\Collection\AbstractEntityCollection $characters,

#[\Spameri\Elastic\Mapping\Collection]
public \Spameri\Elastic\Entity\Collection\AbstractEntityCollection $jobs,
)
{
}


public function entityVariables(): array
{
return \get_object_vars($this);
}


public function id(): \Spameri\Elastic\Entity\Property\ElasticIdInterface
{
return $this->id;
}


public function identification(): \SpameriTests\Elastic\Data\Entity\Video\Identification
{
return $this->identification;
}


public function name(): \SpameriTests\Elastic\Data\Entity\Property\Name
{
return $this->name;
}


public function rename(\SpameriTests\Elastic\Data\Entity\Property\Name $name): void
{
$this->name = $name;
}


public function description(): \SpameriTests\Elastic\Data\Entity\Property\Description
{
return $this->description;
}


public function changeDescription(\SpameriTests\Elastic\Data\Entity\Property\Description $description): void
{
$this->description = $description;
}


public function birth(): \Spameri\Elastic\Entity\Property\Date|null
{
return $this->birth;
}


public function setBirth(\Spameri\Elastic\Entity\Property\Date|null $birth): void
{
$this->birth = $birth;
}


public function death(): \Spameri\Elastic\Entity\Property\Date|null
{
return $this->death;
}


public function setDeath(\Spameri\Elastic\Entity\Property\Date|null $death): void
{
$this->death = $death;
}


public function alias(): \SpameriTests\Elastic\Data\Entity\Property\Name
{
return $this->alias;
}


public function setAlias(\SpameriTests\Elastic\Data\Entity\Property\Name $alias): void
{
$this->alias = $alias;
}


public function characters(): \SpameriTests\Elastic\Data\Entity\Person\CharacterCollectionElastic
{
return $this->characters;
}


public function jobs(): \SpameriTests\Elastic\Data\Entity\Person\JobCollectionElastic
{
return $this->jobs;
parent::__construct($id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ public function character(
foreach ($this->collection() as $character) {
if ($episode) {
if (
$character->id()->value() === $id->value()
&& $character->episode()
&& $character->episode()->value() === $episode->value()
$character->id === $id->value()
&& $character->episode->value() === $episode->value()
) {
return $character;
}

} else {
if ($character->id()->value() === $id->value()) {
if ($character->id === $id->value()) {
return $character;
}
}
Expand Down
189 changes: 16 additions & 173 deletions tests/SpameriTests/Elastic/Data/Entity/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,184 +2,27 @@

namespace SpameriTests\Elastic\Data\Entity;

class Video implements \Spameri\Elastic\Entity\ElasticEntityInterface
class Video extends \Spameri\Elastic\Entity\AbstractElasticEntity
{

/**
* @var \Spameri\Elastic\Entity\Property\ElasticIdInterface
*/
public $id;

/**
* @var \SpameriTests\Elastic\Data\Entity\Video\Identification
*/
private $identification;

/**
* @var \SpameriTests\Elastic\Data\Entity\Property\Name
*/
private $name;

/**
* @var \SpameriTests\Elastic\Data\Entity\Property\Year
*/
private $year;

/**
* @var \SpameriTests\Elastic\Data\Entity\Video\Technical
*/
private $technical;

/**
* @var \SpameriTests\Elastic\Data\Entity\Video\Story
*/
private $story;

/**
* @var \SpameriTests\Elastic\Data\Entity\Video\Details
*/
private $details;

/**
* @var \SpameriTests\Elastic\Data\Entity\Video\HighLights
*/
private $highLights;

/**
* @var \SpameriTests\Elastic\Data\Entity\Video\Connections
*/
private $connections;

/**
* @var \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection
*/
private $season;

/**
* @var \SpameriTests\Elastic\Data\Entity\Video\People
*/
private $people;


public function __construct(
\Spameri\Elastic\Entity\Property\ElasticIdInterface $id,
\SpameriTests\Elastic\Data\Entity\Video\Identification $identification,
\SpameriTests\Elastic\Data\Entity\Property\Name $name,
\SpameriTests\Elastic\Data\Entity\Property\Year $year,
\SpameriTests\Elastic\Data\Entity\Video\Technical $technical,
\SpameriTests\Elastic\Data\Entity\Video\Story $story,
\SpameriTests\Elastic\Data\Entity\Video\Details $details,
\SpameriTests\Elastic\Data\Entity\Video\HighLights $highLights,
\SpameriTests\Elastic\Data\Entity\Video\Connections $connections,
\SpameriTests\Elastic\Data\Entity\Video\People $people,
\SpameriTests\Elastic\Data\Entity\Video\SeasonCollection $season = NULL,
#[\Spameri\Elastic\Mapping\Entity(class: \Spameri\Elastic\Entity\Property\ElasticId::class)]
public \Spameri\Elastic\Entity\Property\ElasticIdInterface $id,
public \SpameriTests\Elastic\Data\Entity\Video\Identification $identification,
public \SpameriTests\Elastic\Data\Entity\Property\Name $name,
public \SpameriTests\Elastic\Data\Entity\Property\Year $year,
public \SpameriTests\Elastic\Data\Entity\Video\Technical $technical,
public \SpameriTests\Elastic\Data\Entity\Video\Story $story,
public \SpameriTests\Elastic\Data\Entity\Video\Details $details,
public \SpameriTests\Elastic\Data\Entity\Video\HighLights $highLights,
public \SpameriTests\Elastic\Data\Entity\Video\Connections $connections,
public \SpameriTests\Elastic\Data\Entity\Video\People $people,

#[\Spameri\Elastic\Mapping\Collection]
public \Spameri\Elastic\Entity\Collection\AbstractEntityCollection $season,
)
{
$this->id = $id;
$this->identification = $identification;
$this->name = $name;
$this->year = $year;
$this->technical = $technical;
$this->story = $story;
$this->details = $details;
$this->highLights = $highLights;
$this->connections = $connections;

if ($season === NULL) {
$season = new \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection();
}
$this->season = $season;
$this->people = $people;
}


public function entityVariables(): array
{
return \get_object_vars($this);
}


public function id(): \Spameri\Elastic\Entity\Property\ElasticIdInterface
{
return $this->id;
}


public function identification(): \SpameriTests\Elastic\Data\Entity\Video\Identification
{
return $this->identification;
}


public function name(): \SpameriTests\Elastic\Data\Entity\Property\Name
{
return $this->name;
}


public function rename(\SpameriTests\Elastic\Data\Entity\Property\Name $name): void
{
$this->name = $name;
}


public function year(): \SpameriTests\Elastic\Data\Entity\Property\Year
{
return $this->year;
}


public function setYear(\SpameriTests\Elastic\Data\Entity\Property\Year $year): void
{
$this->year = $year;
}


public function technical(): \SpameriTests\Elastic\Data\Entity\Video\Technical
{
return $this->technical;
}


public function setTechnicalFromImdb(\SpameriTests\Elastic\Data\Entity\Video\Technical $technical): void
{
$this->technical = $technical;
}


public function story(): \SpameriTests\Elastic\Data\Entity\Video\Story
{
return $this->story;
}


public function details(): \SpameriTests\Elastic\Data\Entity\Video\Details
{
return $this->details;
}


public function highLights(): \SpameriTests\Elastic\Data\Entity\Video\HighLights
{
return $this->highLights;
}


public function connections(): \SpameriTests\Elastic\Data\Entity\Video\Connections
{
return $this->connections;
}


public function season(): \SpameriTests\Elastic\Data\Entity\Video\SeasonCollection
{
return $this->season;
}


public function people(): \SpameriTests\Elastic\Data\Entity\Video\People
{
return $this->people;
parent::__construct($id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Identification implements \Spameri\Elastic\Entity\EntityInterface
{

public function __construct(
private \SpameriTests\Elastic\Data\Entity\Property\ImdbId $imdb,
public \SpameriTests\Elastic\Data\Entity\Property\ImdbId $imdb,
)
{
}
Expand All @@ -23,10 +23,4 @@ public function entityVariables(): array
return \get_object_vars($this);
}


public function imdb(): \SpameriTests\Elastic\Data\Entity\Property\ImdbId
{
return $this->imdb;
}

}
2 changes: 1 addition & 1 deletion tests/SpameriTests/Elastic/Data/Entity/Video/People.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function personByImdb(
{
/** @var \SpameriTests\Elastic\Data\Entity\Person $entity */
foreach ($this->collection() as $entity) {
if ($imdb->value() === $entity->identification()->imdb()->value()) {
if ($imdb->value() === $entity->identification->imdb->value()) {
return $entity;
}
}
Expand Down
Loading

0 comments on commit 7840985

Please sign in to comment.