Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Matej\Model\Command; | ||
|
||
/** | ||
* Merge two users. DELETES source user! | ||
*/ | ||
class UserMerge extends AbstractCommand | ||
{ | ||
/** @var string */ | ||
private $sourceUserId; | ||
/** @var string */ | ||
private $targetUserId; | ||
|
||
/** | ||
* Merge source user to target user AND DELETE SOURCE USER. | ||
*/ | ||
public function __construct(string $sourceUserId, string $targetUserId) | ||
{ | ||
$this->sourceUserId = $sourceUserId; | ||
$this->targetUserId = $targetUserId; | ||
} | ||
|
||
public function getCommandType(): string | ||
{ | ||
return 'user-merge'; | ||
} | ||
|
||
public function getCommandParameters(): array | ||
{ | ||
return [ | ||
'target_user_id' => $this->targetUserId, | ||
'source_user_id' => $this->sourceUserId, | ||
]; | ||
} | ||
|
||
/** | ||
* Merge source user to target user AND DELETE SOURCE USER. | ||
*/ | ||
public static function create(string $sourceUserId, string $targetUserId): self | ||
{ | ||
return new static($sourceUserId, $targetUserId); | ||
} | ||
|
||
/** | ||
* Merge source user into target user AND DELETE SOURCE USER. | ||
*/ | ||
public static function mergeInto(string $targetUserId, string $sourceUserId): self | ||
{ | ||
return new static($sourceUserId, $targetUserId); | ||
} | ||
} |
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,45 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Lmc\Matej\Model\Command; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class UserMergeTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldGenerateCorrectSignature(): void | ||
{ | ||
$sourceUserId = 'source-user'; | ||
$targetUserId = 'target-user'; | ||
|
||
$command = UserMerge::create($sourceUserId, $targetUserId); | ||
$this->assertUserMergeObject($command, $sourceUserId, $targetUserId); | ||
|
||
$command = UserMerge::mergeInto($targetUserId, $sourceUserId); | ||
$this->assertUserMergeObject($command, $sourceUserId, $targetUserId); | ||
|
||
$command = new UserMerge($sourceUserId, $targetUserId); | ||
$this->assertUserMergeObject($command, $sourceUserId, $targetUserId); | ||
} | ||
|
||
/** | ||
* Execute asserts against user merge object | ||
* @param object $object | ||
*/ | ||
private function assertUserMergeObject($object, string $sourceUserId, string $targetUserId): void | ||
{ | ||
$this->assertInstanceOf(UserMerge::class, $object); | ||
$this->assertSame( | ||
[ | ||
'type' => 'user-merge', | ||
'parameters' => [ | ||
'target_user_id' => $targetUserId, | ||
'source_user_id' => $sourceUserId, | ||
], | ||
], | ||
$object->jsonSerialize() | ||
); | ||
} | ||
} |