objects = self::getObjects(); $objectsService = $this->getMock( ObjectsService::class ); $objectsService->method( 'dereference' )->will( $this->returnCallback( function ( $id ) { if ( array_key_exists( $id, $this->objects ) ) { return TestActivityPubObject::fromArray( $this->objects[$id] ); } return null; } ) ); $objectsService->method( 'update' )->will( $this->returnCallback( function ( $id, $updateFields ) { if ( array_key_exists( $id, $this->objects ) ) { $existing = $this->objects[$id]; foreach ( $updateFields as $field => $newValue ) { if ( $newValue === null && array_key_exists( $field, $existing ) ) { unset( $existing[$field] ); } else { $existing[$field] = $newValue; } } return TestActivityPubObject::fromArray( $existing ); } return null; } ) ); $updateHandler = new UpdateHandler( $objectsService ); $this->eventDispatcher = new EventDispatcher(); $this->eventDispatcher->addSubscriber( $updateHandler ); } private static function getObjects() { return array( 'https://elsewhere.com/objects/1' => array( 'id' => 'https://elsewhere.com/objects/1', 'attributedTo' => 'https://elsewhere.com/actors/1', ), 'https://example.com/objects/1' => array( 'id' => 'https://example.com/objects/1', 'attributedTo' => 'https://example.com/actors/1', 'type' => 'Note', 'content' => 'This is a note', ), ); } public function provideTestUpdateHandler() { return array( array( array( 'id' => 'basicInboxTest', 'eventName' => InboxActivityEvent::NAME, 'event' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/activities/1', 'type' => 'Update', 'object' => array( 'id' => 'https://elsewhere.com/objects/1', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/1', ) ), self::requestWithAttributes( 'https://example.com/inbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://elsewhere.com/actors/1', ) ) ) ) ), 'expectedEvent' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/activities/1', 'type' => 'Update', 'object' => array( 'id' => 'https://elsewhere.com/objects/1', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/1', ) ), self::requestWithAttributes( 'https://example.com/inbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://elsewhere.com/actors/1', ) ) ) ) ), ) ), array( array( 'id' => 'basicOutboxTest', 'eventName' => OutboxActivityEvent::NAME, 'event' => new OutboxActivityEvent( array( 'id' => 'https://example.com/activities/1', 'type' => 'Update', 'object' => array( 'id' => 'https://example.com/objects/1', 'content' => 'This is an updated note', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/1', ) ), self::requestWithAttributes( 'https://example.com/outbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ) ) ) ), 'expectedEvent' => new OutboxActivityEvent( array( 'id' => 'https://example.com/activities/1', 'type' => 'Update', 'object' => array( 'id' => 'https://example.com/objects/1', 'type' => 'Note', 'attributedTo' => 'https://example.com/actors/1', 'content' => 'This is an updated note', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actor/1', ) ), self::requestWithAttributes( 'https://example.com/outbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ) ) ) ), ) ), array( array( 'id' => 'checksInboxAuth', 'eventName' => InboxActivityEvent::NAME, 'event' => new InboxActivityEvent( array( 'id' => 'https://elsewhere.com/activities/1', 'type' => 'Update', 'object' => array( 'id' => 'https://elsewhere.com/objects/1', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ), self::requestWithAttributes( 'https://example.com/inbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://elsewhere.com/actors/2', ) ) ) ) ), 'expectedException' => UnauthorizedHttpException::class, ) ), array( array( 'id' => 'checksOutboxAuth', 'eventName' => OutboxActivityEvent::NAME, 'event' => new OutboxActivityEvent( array( 'id' => 'https://example.com/activities/1', 'type' => 'Update', 'object' => array( 'id' => 'https://example.com/objects/1', ), ), TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/1', ) ), self::requestWithAttributes( 'https://example.com/outbox', array( 'actor' => TestActivityPubObject::fromArray( array( 'id' => 'https://example.com/actors/2', ) ) ) ) ), 'expectedException' => UnauthorizedHttpException::class, ) ), ); } /** * @dataProvider provideTestUpdateHandler */ public function testUpdateHandler($testCase) { $event = $testCase['event']; if ( array_key_exists( 'expectedException', $testCase ) ) { $this->setExpectedException( $testCase['expectedException'] ); } $this->eventDispatcher->dispatch( $testCase['eventName'], $event ); if ( array_key_exists( 'expectedEvent', $testCase ) ) { $this->assertEquals( $testCase['expectedEvent'], $event, "Error on test $testCase[id]" ); } } }__halt_compiler();----SIGNATURE:----N+zrbiDh8NzFRdPocW4SPB3dICEAnqbPC/o1HGPcuzfju2wIK3UlJcMfUSPlVSQq9BRTDjJ3Jkci3bVUT6ZJdwP6ZbgBZU5dHQdGGIBMZX9TYOez/3dYRxPzN5iuqQEz7rcRMoiSpKl/F6iuVGYtrTzlyhqxjjfvFBtRGYIcen8MzUJCSuhAYRMB4t/FZ1BXY09B3ofJO9JDGeeCOS+m6D13sqxzLoowoHAJ51fWOXO0yv/KdvYUOhW5U+ChHVkN42/B2LD5PmlBUy+UMGGOTfiIWMIuiqVuwG13qD1q3sX2etgaJW6t6d7oeWQ+4lIZ1OMWKxrTKJKrC2YNtsULHjYjxxvfiuSlo4qcVrsszr6T1jxdQL39a4YPeyRnJsvvTleIwovCPZ9ou3oL/mrW/gh9AzE8AUAFN8tVFhsH4c0oOh0NraB9b0U/LEucYjXO8R7wzkh6tKXDl7arScEHFK4jypoAzeuQFzyCtVTUJPq135MAV0fTgGoiTJazspcOlocQcNdh3vO/ZvjCqKNuuZYrkFKXoZDtfCEGx/lniiEoQY9Yc6yeDMpLUYSO0TLKouUOGqjk25OCrw3ou9rz7CpxVr/FvwWrSgUPQIy/UO9JZI2f7s8sjPWnZm5PKHFrmu7vKlxpYna5S78C2VMUWSG8f+SautmpZN57yowvSuU=----ATTACHMENT:----ODYxNjg3ODc3NzkxNjc5MiAxNTI5MDkwODYwNjM1MTg4IDU0NTE1NjAzMDMzNjc3MzY=