-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AttributesPropertyLister now caches the results in memory.
- Loading branch information
Showing
5 changed files
with
196 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/file-src package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\File\Tests\FileAssociation; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Rekalogika\File\Association\PropertyLister\AttributesPropertyLister; | ||
use Rekalogika\File\Tests\Model\EntityWithAttribute; | ||
use Rekalogika\File\Tests\Model\SubclassOfEntityWithAttribute; | ||
|
||
class PropertyListerTest extends TestCase | ||
{ | ||
public function testAttributePropertyLister(): void | ||
{ | ||
$lister = new AttributesPropertyLister(); | ||
|
||
$entity = new EntityWithAttribute('id'); | ||
$properties = $lister->getFileProperties($entity); | ||
$properties = $properties instanceof \Traversable | ||
? \iterator_to_array($properties) | ||
: $properties; | ||
$this->assertSame(['file'], $properties); | ||
|
||
$subclassedEntity = new SubclassOfEntityWithAttribute('id'); | ||
$properties = $lister->getFileProperties($subclassedEntity); | ||
$properties = $properties instanceof \Traversable | ||
? \iterator_to_array($properties) | ||
: $properties; | ||
$this->assertSame(['anotherFile', 'file'], $properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/file-src package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\File\Tests\Model; | ||
|
||
use Rekalogika\Contracts\File\FileInterface; | ||
use Rekalogika\File\Association\Attribute\AsFileAssociation; | ||
|
||
class EntityWithAttribute | ||
{ | ||
#[AsFileAssociation] | ||
private ?FileInterface $file = null; | ||
|
||
private ?FileInterface $nonAssociatedFile = null; | ||
|
||
public function __construct( | ||
private string $id | ||
) { | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @phpstan-impure | ||
*/ | ||
public function getFile(): ?FileInterface | ||
{ | ||
return $this->file; | ||
} | ||
|
||
public function setFile(?FileInterface $file): self | ||
{ | ||
$this->file = $file; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of nonAssociatedFile | ||
*/ | ||
public function getNonAssociatedFile(): ?FileInterface | ||
{ | ||
return $this->nonAssociatedFile; | ||
} | ||
|
||
/** | ||
* Set the value of nonAssociatedFile | ||
*/ | ||
public function setNonAssociatedFile(?FileInterface $nonAssociatedFile): self | ||
{ | ||
$this->nonAssociatedFile = $nonAssociatedFile; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of rekalogika/file-src package. | ||
* | ||
* (c) Priyadi Iman Nurcahyo <https://rekalogika.dev> | ||
* | ||
* For the full copyright and license information, please view the LICENSE file | ||
* that was distributed with this source code. | ||
*/ | ||
|
||
namespace Rekalogika\File\Tests\Model; | ||
|
||
use Rekalogika\Contracts\File\FileInterface; | ||
use Rekalogika\File\Association\Attribute\AsFileAssociation; | ||
|
||
class SubclassOfEntityWithAttribute extends EntityWithAttribute | ||
{ | ||
#[AsFileAssociation] | ||
private ?FileInterface $anotherFile = null; | ||
|
||
private ?FileInterface $unmanagedFile = null; | ||
|
||
/** | ||
* Get the value of anotherFile | ||
*/ | ||
public function getAnotherFile(): ?FileInterface | ||
{ | ||
return $this->anotherFile; | ||
} | ||
|
||
/** | ||
* Set the value of anotherFile | ||
*/ | ||
public function setAnotherFile(?FileInterface $anotherFile): self | ||
{ | ||
$this->anotherFile = $anotherFile; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of unmanagedFile | ||
*/ | ||
public function getUnmanagedFile(): ?FileInterface | ||
{ | ||
return $this->unmanagedFile; | ||
} | ||
|
||
/** | ||
* Set the value of unmanagedFile | ||
*/ | ||
public function setUnmanagedFile(?FileInterface $unmanagedFile): self | ||
{ | ||
$this->unmanagedFile = $unmanagedFile; | ||
|
||
return $this; | ||
} | ||
} |