feat: add url mapping value objects
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace WPContentSync\Tests\Unit\Url;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use WPContentSync\Url\UrlMapping;
|
||||
use WPContentSync\Url\UrlMappingCollection;
|
||||
|
||||
class UrlMappingCollectionTest extends TestCase {
|
||||
public function test_it_normalizes_mapping_urls_without_trailing_slashes(): void {
|
||||
$mapping = new UrlMapping( 'https://example.test/', 'https://staging.example.test/' );
|
||||
|
||||
self::assertSame( 'https://example.test', $mapping->sourceUrl() );
|
||||
self::assertSame( 'https://staging.example.test', $mapping->destinationUrl() );
|
||||
}
|
||||
|
||||
public function test_it_rejects_empty_mapping_urls(): void {
|
||||
$this->expectException( \InvalidArgumentException::class );
|
||||
$this->expectExceptionMessage( 'Source and destination URLs are required.' );
|
||||
|
||||
new UrlMapping( '', 'https://staging.example.test' );
|
||||
}
|
||||
|
||||
public function test_it_returns_mappings_in_order(): void {
|
||||
$first = new UrlMapping( 'https://example.test', 'https://staging.example.test' );
|
||||
$second = new UrlMapping( 'https://cdn.example.test', 'https://cdn.staging.example.test' );
|
||||
$collection = new UrlMappingCollection( array( $first, $second ) );
|
||||
|
||||
self::assertSame( array( $first, $second ), $collection->all() );
|
||||
}
|
||||
|
||||
public function test_it_rejects_non_mapping_items(): void {
|
||||
$this->expectException( \InvalidArgumentException::class );
|
||||
$this->expectExceptionMessage( 'URL mapping collections only accept UrlMapping instances.' );
|
||||
|
||||
new UrlMappingCollection( array( new \stdClass() ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user