- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
62 lines
2.3 KiB
PHP
62 lines
2.3 KiB
PHP
<?php
|
|
|
|
use App\Framework\MagicLinks\ValueObjects\MagicLinkPayload;
|
|
|
|
describe('MagicLinkPayload', function () {
|
|
it('creates payload from array', function () {
|
|
$payload = MagicLinkPayload::fromArray(['email' => 'test@example.com', 'user_id' => 123]);
|
|
|
|
expect($payload->toArray())->toBe(['email' => 'test@example.com', 'user_id' => 123]);
|
|
});
|
|
|
|
it('throws exception for empty payload', function () {
|
|
expect(fn() => MagicLinkPayload::fromArray([]))
|
|
->toThrow(InvalidArgumentException::class, 'Payload cannot be empty');
|
|
});
|
|
|
|
it('retrieves value with get method', function () {
|
|
$payload = MagicLinkPayload::fromArray(['email' => 'test@example.com']);
|
|
|
|
expect($payload->get('email'))->toBe('test@example.com');
|
|
expect($payload->get('missing', 'default'))->toBe('default');
|
|
});
|
|
|
|
it('checks if key exists', function () {
|
|
$payload = MagicLinkPayload::fromArray(['email' => 'test@example.com']);
|
|
|
|
expect($payload->has('email'))->toBeTrue();
|
|
expect($payload->has('missing'))->toBeFalse();
|
|
});
|
|
|
|
it('creates new instance with added value', function () {
|
|
$payload = MagicLinkPayload::fromArray(['email' => 'test@example.com']);
|
|
$updated = $payload->with('user_id', 123);
|
|
|
|
expect($payload->has('user_id'))->toBeFalse();
|
|
expect($updated->has('user_id'))->toBeTrue();
|
|
expect($updated->get('user_id'))->toBe(123);
|
|
});
|
|
|
|
it('creates new instance without key', function () {
|
|
$payload = MagicLinkPayload::fromArray(['email' => 'test@example.com', 'user_id' => 123]);
|
|
$updated = $payload->without('user_id');
|
|
|
|
expect($payload->has('user_id'))->toBeTrue();
|
|
expect($updated->has('user_id'))->toBeFalse();
|
|
});
|
|
|
|
it('throws exception when removing last key', function () {
|
|
$payload = MagicLinkPayload::fromArray(['email' => 'test@example.com']);
|
|
|
|
expect(fn() => $payload->without('email'))
|
|
->toThrow(InvalidArgumentException::class, 'Payload cannot be empty after removal');
|
|
});
|
|
|
|
it('returns keys and values', function () {
|
|
$payload = MagicLinkPayload::fromArray(['email' => 'test@example.com', 'user_id' => 123]);
|
|
|
|
expect($payload->keys())->toBe(['email', 'user_id']);
|
|
expect($payload->values())->toBe(['test@example.com', 123]);
|
|
});
|
|
});
|