-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
290 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Attachment; | ||
|
||
use Phpro\ResourceStream\Factory\MemoryStream; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment; | ||
use Soap\Psr18AttachmentsMiddleware\Attachment\AttachmentsCollection; | ||
use Soap\Psr18AttachmentsMiddleware\Exception\AttachmentNotFoundException; | ||
|
||
final class AttachmentsCollectionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_can_contain_attachments(): void | ||
{ | ||
$collection = new AttachmentsCollection( | ||
$attachment1 = Attachment::create('filename.pdf', MemoryStream::create()), | ||
$attachment2 = Attachment::create('filename.jpg', MemoryStream::create()), | ||
); | ||
|
||
static::assertCount(2, $collection); | ||
static::assertSame([$attachment1, $attachment2], [...$collection]); | ||
} | ||
|
||
#[Test] | ||
public function it_can_add_an_item_mutably(): void | ||
{ | ||
$collection = new AttachmentsCollection(); | ||
$collection->add($attachment = Attachment::create('filename.pdf', MemoryStream::create())); | ||
|
||
static::assertCount(1, $collection); | ||
static::assertSame([$attachment], [...$collection]); | ||
} | ||
|
||
#[Test] | ||
public function it_can_find_an_attachment_by_id(): void | ||
{ | ||
$collection = new AttachmentsCollection( | ||
$attachment1 = Attachment::create('filename.pdf', MemoryStream::create()), | ||
$attachment2 = Attachment::create('filename.jpg', MemoryStream::create()), | ||
); | ||
|
||
static::assertSame($attachment1, $collection->findById($attachment1->id)); | ||
} | ||
|
||
#[Test] | ||
public function it_can_fail_finding_an_attachment_by_id(): void | ||
{ | ||
$collection = new AttachmentsCollection( | ||
Attachment::create('filename.pdf', MemoryStream::create()), | ||
); | ||
|
||
$this->expectExceptionObject(AttachmentNotFoundException::withId('not-found')); | ||
$collection->findById('not-found'); | ||
} | ||
} |
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,21 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Attachment; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Soap\Psr18AttachmentsMiddleware\Attachment\IdGenerator; | ||
|
||
final class IdGeneratorTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_can_generate_a_random_id(): void | ||
{ | ||
$id1 = IdGenerator::generate(); | ||
$id2 = IdGenerator::generate(); | ||
|
||
static::assertNotSame($id1, $id2); | ||
static::assertSame(16, mb_strlen($id1)); | ||
static::assertSame(16, mb_strlen($id2)); | ||
} | ||
} |
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,73 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Encoding\Xop; | ||
|
||
use Phpro\ResourceStream\Factory\MemoryStream; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Soap\Encoding\Encoder\Context; | ||
use Soap\Encoding\EncoderRegistry; | ||
use Soap\Engine\Metadata\Collection\MethodCollection; | ||
use Soap\Engine\Metadata\Collection\TypeCollection; | ||
use Soap\Engine\Metadata\InMemoryMetadata; | ||
use Soap\Engine\Metadata\Model\XsdType; | ||
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment; | ||
use Soap\Psr18AttachmentsMiddleware\Encoding\Xop\XopIncludeEncoder; | ||
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorage; | ||
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorageInterface; | ||
use Soap\WsdlReader\Model\Definitions\Namespaces; | ||
|
||
final class XopIncludeEncoderTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_can_encode_xop_include_attachment(): void | ||
{ | ||
$encoder = $this->createEncoder( | ||
$storage = $this->createStorage() | ||
); | ||
$iso = $encoder->iso($this->createContext()); | ||
|
||
$result = $iso->to( | ||
$attachment = new Attachment('foo', 'file.pdf', 'application/pdf', MemoryStream::create()) | ||
); | ||
|
||
static::assertSame('<xop:Include href="cid:foo" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>', $result); | ||
static::assertSame($attachment, $storage->requestAttachments()->findById('foo')); | ||
} | ||
|
||
#[Test] | ||
public function it_can_decode_xop_include_attachment(): void | ||
{ | ||
$encoder = $this->createEncoder( | ||
$storage = $this->createStorage() | ||
); | ||
$iso = $encoder->iso($this->createContext()); | ||
|
||
$storage->responseAttachments()->add( | ||
$attachment = new Attachment('foo', 'file.pdf', 'application/pdf', MemoryStream::create()) | ||
); | ||
$result = $iso->from('<xop:Include href="cid:foo" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>'); | ||
|
||
static::assertSame($attachment, $result); | ||
} | ||
|
||
private function createStorage(): AttachmentStorageInterface | ||
{ | ||
return new AttachmentStorage(); | ||
} | ||
|
||
private function createEncoder(AttachmentStorageInterface $storage): XopIncludeEncoder | ||
{ | ||
return new XopIncludeEncoder($storage); | ||
} | ||
|
||
private function createContext(): Context | ||
{ | ||
return new Context( | ||
XsdType::any(), | ||
new InMemoryMetadata(new TypeCollection(), new MethodCollection()), | ||
EncoderRegistry::default(), | ||
new Namespaces([], []), | ||
); | ||
} | ||
} |
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,22 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Exception; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Soap\Engine\Exception\RuntimeException; | ||
use Soap\Psr18AttachmentsMiddleware\Exception\AttachmentNotFoundException; | ||
|
||
final class AttachmentNotFoundExceptionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_can_throw_by_id(): void | ||
{ | ||
$exception = AttachmentNotFoundException::withId('foo'); | ||
|
||
$this->expectException(AttachmentNotFoundException::class); | ||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('Attachment with id "foo" can not be found.'); | ||
throw $exception; | ||
} | ||
} |
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,23 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Exception; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Soap\Engine\Exception\RuntimeException; | ||
use Soap\Psr18AttachmentsMiddleware\Exception\SoapMessageNotFoundException; | ||
|
||
final class SoapMessageNotFoundExceptionTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_can_throw_from_multipart_context(): void | ||
{ | ||
$exception = SoapMessageNotFoundException::insideMultipart('soapmessage', 'application/soap+xml'); | ||
|
||
$this->expectException(SoapMessageNotFoundException::class); | ||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('Soap message with id "soapmessage" and type "application/soap+xml" can not be found inside multipart response.'); | ||
throw $exception; | ||
} | ||
|
||
} |
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,10 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Middleware; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AttachmentsMiddlewareTest extends TestCase | ||
{ | ||
|
||
} |
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,10 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Multipart; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class RequestBuilderTest extends TestCase | ||
{ | ||
|
||
} |
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,10 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Multipart; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
final class ResponseBuilderTest extends TestCase | ||
{ | ||
|
||
} |
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,62 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Storage; | ||
|
||
use Phpro\ResourceStream\Factory\MemoryStream; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment; | ||
use Soap\Psr18AttachmentsMiddleware\Attachment\AttachmentsCollection; | ||
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorage; | ||
|
||
final class AttachmentStorageTest extends TestCase | ||
{ | ||
#[Test] | ||
public function it_contains_request_attachments(): void | ||
{ | ||
$attachments = $this->createStorage()->requestAttachments(); | ||
|
||
static::assertEquals(new AttachmentsCollection(), $attachments); | ||
} | ||
|
||
#[Test] | ||
public function it_contains_response_attachments(): void | ||
{ | ||
$attachments = $this->createStorage()->responseAttachments(); | ||
|
||
static::assertEquals(new AttachmentsCollection(), $attachments); | ||
} | ||
|
||
#[Test] | ||
public function it_can_reset_request_attachments(): void | ||
{ | ||
$storage = $this->createStorage(); | ||
$attachments = $storage->requestAttachments()->add( | ||
Attachment::create('foo.png', MemoryStream::create()) | ||
); | ||
$storage->resetRequestAttachments(); | ||
$newAttachments = $storage->requestAttachments(); | ||
|
||
static::assertNotSame($attachments, $newAttachments); | ||
static::assertEquals(new AttachmentsCollection(), $storage->requestAttachments()); | ||
} | ||
|
||
#[Test] | ||
public function it_can_reset_response_attachments(): void | ||
{ | ||
$storage = $this->createStorage(); | ||
$attachments = $storage->responseAttachments()->add( | ||
Attachment::create('foo.png', MemoryStream::create()) | ||
); | ||
$storage->resetResponseAttachments(); | ||
$newAttachments = $storage->responseAttachments(); | ||
|
||
static::assertNotSame($attachments, $newAttachments); | ||
static::assertEquals(new AttachmentsCollection(), $storage->responseAttachments()); | ||
} | ||
|
||
private function createStorage(): AttachmentStorage | ||
{ | ||
return new AttachmentStorage(); | ||
} | ||
} |