Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add last edited by database property
- Loading branch information
1 parent
b8a6de7
commit 69239eb
Showing
4 changed files
with
89 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Notion\Databases\Properties; | ||
|
||
/** | ||
* @psalm-type LastEditedByJson = array{ | ||
* id: string, | ||
* name: string, | ||
* type: "last_edited_by", | ||
* last_edited_by: array<empty, empty>, | ||
* } | ||
*/ | ||
class LastEditedBy implements PropertyInterface | ||
{ | ||
private const TYPE = Property::TYPE_LAST_EDITED_BY; | ||
|
||
private Property $property; | ||
|
||
private function __construct(Property $property) | ||
{ | ||
$this->property = $property; | ||
} | ||
|
||
public static function create(string $propertyName = "LastEditedBy"): self | ||
{ | ||
$property = Property::create("", $propertyName, self::TYPE); | ||
|
||
return new self($property); | ||
} | ||
|
||
public function property(): Property | ||
{ | ||
return $this->property; | ||
} | ||
|
||
public static function fromArray(array $array): self | ||
{ | ||
/** @psalm-var LastEditedByJson $array */ | ||
$property = Property::fromArray($array); | ||
|
||
return new self($property); | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
$array = $this->property->toArray(); | ||
$array[self::TYPE] = []; | ||
|
||
return $array; | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
|
||
namespace Notion\Test\Unit\Databases\Properties; | ||
|
||
use Notion\Databases\Properties\Factory; | ||
use Notion\Databases\Properties\LastEditedBy; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class LastEditedByTest extends TestCase | ||
{ | ||
public function test_create(): void | ||
{ | ||
$lastEditedBy = LastEditedBy::create("Dummy prop name"); | ||
|
||
$this->assertEquals("Dummy prop name", $lastEditedBy->property()->name()); | ||
$this->assertTrue($lastEditedBy->property()->isLastEditedBy()); | ||
} | ||
|
||
public function test_array_conversion(): void | ||
{ | ||
$array = [ | ||
"id" => "abc", | ||
"name" => "dummy", | ||
"type" => "last_edited_by", | ||
"last_edited_by" => [], | ||
]; | ||
$lastEditedBy = LastEditedBy::fromArray($array); | ||
$fromFactory = Factory::fromArray($array); | ||
|
||
$this->assertEquals($array, $lastEditedBy->toArray()); | ||
$this->assertEquals($array, $fromFactory->toArray()); | ||
} | ||
} |