feat: add sync result value object
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for sync result summaries.
|
||||
*
|
||||
* @package WPContentSync
|
||||
*/
|
||||
|
||||
namespace WPContentSync\Tests\Unit\Sync;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use WPContentSync\Sync\SyncResult;
|
||||
|
||||
class SyncResultTest extends TestCase {
|
||||
public function test_it_tracks_successful_counts(): void {
|
||||
$result = SyncResult::success(
|
||||
array(
|
||||
'created' => 2,
|
||||
'updated' => 3,
|
||||
'skipped' => 1,
|
||||
'conflicts' => 1,
|
||||
)
|
||||
);
|
||||
|
||||
self::assertTrue( $result->isSuccessful() );
|
||||
self::assertSame( 2, $result->created() );
|
||||
self::assertSame( 3, $result->updated() );
|
||||
self::assertSame( 1, $result->skipped() );
|
||||
self::assertSame( 1, $result->conflicts() );
|
||||
self::assertSame( array(), $result->errors() );
|
||||
self::assertSame(
|
||||
array(
|
||||
'successful' => true,
|
||||
'created' => 2,
|
||||
'updated' => 3,
|
||||
'skipped' => 1,
|
||||
'conflicts' => 1,
|
||||
'errors' => array(),
|
||||
),
|
||||
$result->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_tracks_failed_results(): void {
|
||||
$result = SyncResult::failure( array( 'posts import failed.' ) );
|
||||
|
||||
self::assertFalse( $result->isSuccessful() );
|
||||
self::assertSame( array( 'posts import failed.' ), $result->errors() );
|
||||
}
|
||||
|
||||
public function test_it_merges_multiple_results(): void {
|
||||
$result = SyncResult::merge(
|
||||
array(
|
||||
SyncResult::success( array( 'created' => 1 ) ),
|
||||
SyncResult::success(
|
||||
array(
|
||||
'updated' => 2,
|
||||
'skipped' => 1,
|
||||
'conflicts' => 1,
|
||||
)
|
||||
),
|
||||
SyncResult::failure( array( 'terms import failed.' ) ),
|
||||
)
|
||||
);
|
||||
|
||||
self::assertFalse( $result->isSuccessful() );
|
||||
self::assertSame( 1, $result->created() );
|
||||
self::assertSame( 2, $result->updated() );
|
||||
self::assertSame( 1, $result->skipped() );
|
||||
self::assertSame( 1, $result->conflicts() );
|
||||
self::assertSame( array( 'terms import failed.' ), $result->errors() );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user