-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from veewee/events-allow-immutable-messages
Allow immutable changes on event request / response
- Loading branch information
Showing
9 changed files
with
174 additions
and
9 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
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
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
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
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
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
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
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhproTest\SoapClient\Unit; | ||
|
||
use Phpro\SoapClient\Client; | ||
use Phpro\SoapClient\Event\RequestEvent; | ||
use Phpro\SoapClient\Type\RequestInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
|
||
class RequestEventTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
/** | ||
* @var Client & ObjectProphecy | ||
*/ | ||
private Client $client; | ||
|
||
/** | ||
* @var RequestInterface & ObjectProphecy | ||
*/ | ||
private RequestInterface $request; | ||
|
||
private RequestEvent $event; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->client = $this->prophesize(Client::class)->reveal(); | ||
$this->request = $this->prophesize(RequestInterface::class)->reveal(); | ||
$this->event = new RequestEvent($this->client, 'method', $this->request); | ||
} | ||
|
||
/** @test */ | ||
public function it_contains_a_client(): void | ||
{ | ||
self::assertSame($this->client, $this->event->getClient()); | ||
} | ||
|
||
/** @test */ | ||
public function it_contains_a_request(): void | ||
{ | ||
self::assertSame($this->request, $this->event->getRequest()); | ||
} | ||
|
||
/** @test */ | ||
public function it_contains_a_method(): void | ||
{ | ||
self::assertSame('method', $this->event->getMethod()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_overwrite_request(): void | ||
{ | ||
$new = $this->prophesize(RequestInterface::class)->reveal(); | ||
$this->event->registerRequest($new); | ||
|
||
self::assertSame($new, $this->event->getRequest()); | ||
self::assertNotSame($this->request, $this->event->getRequest()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
test/PhproTest/SoapClient/Unit/Event/ResponseEventTest.php
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhproTest\SoapClient\Unit; | ||
|
||
use Phpro\SoapClient\Client; | ||
use Phpro\SoapClient\Event\RequestEvent; | ||
use Phpro\SoapClient\Event\ResponseEvent; | ||
use Phpro\SoapClient\Type\RequestInterface; | ||
use Phpro\SoapClient\Type\ResultInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use Prophecy\Prophecy\ObjectProphecy; | ||
|
||
class ResponseEventTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
/** | ||
* @var Client & ObjectProphecy | ||
*/ | ||
private Client $client; | ||
|
||
/** | ||
* @var RequestInterface & ObjectProphecy | ||
*/ | ||
private RequestInterface $request; | ||
|
||
/** | ||
* @var ResultInterface & ObjectProphecy | ||
*/ | ||
private ResultInterface $response; | ||
|
||
private RequestEvent $requestEvent; | ||
private ResponseEvent $event; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->client = $this->prophesize(Client::class)->reveal(); | ||
$this->request = $this->prophesize(RequestInterface::class)->reveal(); | ||
$this->response = $this->prophesize(ResultInterface::class)->reveal(); | ||
$this->requestEvent = new RequestEvent($this->client, 'method', $this->request); | ||
|
||
$this->event = new ResponseEvent($this->client, $this->requestEvent, $this->response); | ||
} | ||
|
||
/** @test */ | ||
public function it_contains_a_client(): void | ||
{ | ||
self::assertSame($this->client, $this->event->getClient()); | ||
} | ||
|
||
/** @test */ | ||
public function it_contains_a_request_event(): void | ||
{ | ||
self::assertSame($this->requestEvent, $this->event->getRequestEvent()); | ||
} | ||
|
||
/** @test */ | ||
public function it_contains_a_response(): void | ||
{ | ||
self::assertSame($this->response, $this->event->getResponse()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_overwrite_response(): void | ||
{ | ||
$new = $this->prophesize(ResultInterface::class)->reveal(); | ||
$this->event->registerResponse($new); | ||
|
||
self::assertSame($new, $this->event->getResponse()); | ||
self::assertNotSame($this->response, $this->event->getResponse()); | ||
} | ||
} |