Skip to content

Commit fb37a8a

Browse files
committed
Rename namespaces
1 parent cb4f7c8 commit fb37a8a

20 files changed

+118
-46
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
composer.lock
22
vendor
33
.php-cs-fixer.cache
4+
.phpunit.cache

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ This middleware is used to add attachments to your SOAP request:
2828
```php
2929
use Http\Client\Common\PluginClient;
3030
use Soap\Psr18Transport\Psr18Transport;
31-
use Soap\Psr18AttachmentMiddleware\Middleware\AttachmentsMiddleware;
32-
use Soap\Psr18AttachmentMiddleware\Multipart\AttachmentType;
33-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorage;
31+
use Soap\Psr18AttachmentsMiddleware\Middleware\AttachmentsMiddleware;
32+
use Soap\Psr18AttachmentsMiddleware\Multipart\AttachmentType;
33+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorage;
3434

3535
// You should store this attachment storage in a central place in your application e.g. inside a service container.
3636
// It is used to store the attachments that are being sent and received.
@@ -54,8 +54,8 @@ Adding attachments to your request is done by using the `AttachmentsStorage` bef
5454
use Http\Client\Common\PluginClient;
5555
use Phpro\ResourceStream\Factory\FileStream;
5656
use Soap\Psr18Transport\Psr18Transport;
57-
use Soap\Psr18AttachmentMiddleware\Attachment\Attachment;
58-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorage;
57+
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment;
58+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorage;
5959

6060
// You should store this attachment storage in a central place in your application.
6161
// It is used to store the attachments that are being sent and received.
@@ -78,8 +78,8 @@ Receiving attachments is done by using the `AttachmentsStorage` after receiving
7878
use Http\Client\Common\PluginClient;
7979
use Phpro\ResourceStream\Factory\FileStream;
8080
use Soap\Psr18Transport\Psr18Transport;
81-
use Soap\Psr18AttachmentMiddleware\Attachment\Attachment;
82-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorage;
81+
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment;
82+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorage;
8383

8484
// You should store this attachment storage in a central place in your application.
8585
// It is used to store the attachments that are being sent and received.
@@ -106,7 +106,7 @@ composer require php-soap/encoder
106106

107107
```php
108108
use Soap\Encoding\EncoderRegistry;
109-
use Soap\Psr18AttachmentMiddleware\Encoding\Xop\XopIncludeEncoder
109+
use Soap\Psr18AttachmentsMiddleware\Encoding\Xop\XopIncludeEncoder
110110

111111
// You should store this attachment storage in a central place in your application.
112112
// It is used to store the attachments that are being sent and received.
@@ -120,7 +120,7 @@ This will allow you to use attachments directly from within your SOAP request an
120120

121121
```php
122122
use Phpro\ResourceStream\Factory\FileStream;
123-
use Soap\Psr18AttachmentMiddleware\Attachment\Attachment;
123+
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment;
124124

125125
// Your request can now contain Attachments directly:
126126
// These attachments will be automatically added to the AttachmentStorageInterface and a <xop:Include> element will be added to your request instead.

composer.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
"Soap\\Psr18AttachmentsMiddleware\\": "src/"
99
}
1010
},
11+
"autoload-dev": {
12+
"psr-4": {
13+
"SoapTest\\Psr18AttachmentsMiddleware\\": "tests/"
14+
}
15+
},
1116
"authors": [
1217
{
1318
"name": "Toon Verwerft",
@@ -27,7 +32,8 @@
2732
"nyholm/psr7": "^1.8",
2833
"php-soap/encoding": "^0.16.0",
2934
"vimeo/psalm": "^5.26",
30-
"php-standard-library/psalm-plugin": "^2.3"
35+
"php-standard-library/psalm-plugin": "^2.3",
36+
"phpunit/phpunit": "^10.5.40"
3137
},
3238
"config": {
3339
"allow-plugins": {

phpunit.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheDirectory=".phpunit.cache"
6+
executionOrder="depends,defects"
7+
requireCoverageMetadata="false"
8+
beStrictAboutCoverageMetadata="false"
9+
beStrictAboutOutputDuringTests="true"
10+
displayDetailsOnTestsThatTriggerDeprecations="true"
11+
failOnRisky="true"
12+
failOnWarning="true">
13+
<testsuites>
14+
<testsuite name="unit">
15+
<directory>tests/Unit</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
20+
<include>
21+
<directory>src</directory>
22+
</include>
23+
</source>
24+
</phpunit>

src/Attachment/Attachment.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Attachment;
3+
namespace Soap\Psr18AttachmentsMiddleware\Attachment;
44

55
use Http\Message\MultipartStream\ApacheMimetypeHelper;
66
use Phpro\ResourceStream\ResourceStream;

src/Attachment/AttachmentsCollection.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Attachment;
3+
namespace Soap\Psr18AttachmentsMiddleware\Attachment;
44

55
use Countable;
66
use IteratorAggregate;
7-
use Soap\Psr18AttachmentMiddleware\Exception\AttachmentNotFoundException;
7+
use Soap\Psr18AttachmentsMiddleware\Exception\AttachmentNotFoundException;
88

99
/**
1010
* @template-implements \IteratorAggregate<int, Attachment>

src/Attachment/IdGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Attachment;
3+
namespace Soap\Psr18AttachmentsMiddleware\Attachment;
44

55
use function Psl\SecureRandom\string;
66

src/Encoding/Xop/XopIncludeEncoder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Encoding\Xop;
3+
namespace Soap\Psr18AttachmentsMiddleware\Encoding\Xop;
44

55
use Soap\Encoding\Encoder\Context;
66
use Soap\Encoding\Encoder\XmlEncoder;
77
use Soap\Encoding\Xml\Node\Element;
8-
use Soap\Psr18AttachmentMiddleware\Attachment\Attachment;
9-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorageInterface;
8+
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment;
9+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorageInterface;
1010
use VeeWee\Reflecta\Iso\Iso;
1111
use VeeWee\Xml\Writer\Writer;
1212
use function VeeWee\Xml\Writer\Builder\attribute;

src/Exception/AttachmentNotFoundException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Exception;
3+
namespace Soap\Psr18AttachmentsMiddleware\Exception;
44

55
use Soap\Engine\Exception\RuntimeException;
66

src/Exception/SoapMessageNotFoundException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Exception;
3+
namespace Soap\Psr18AttachmentsMiddleware\Exception;
44

55
use Soap\Engine\Exception\RuntimeException;
66

src/Middleware/AttachmentsMiddleware.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Middleware;
3+
namespace Soap\Psr18AttachmentsMiddleware\Middleware;
44

55
use Http\Client\Common\Plugin;
66
use Http\Promise\Promise;
77
use Psr\Http\Message\RequestInterface;
88
use Psr\Http\Message\ResponseInterface;
9-
use Soap\Psr18AttachmentMiddleware\Multipart\AttachmentType;
10-
use Soap\Psr18AttachmentMiddleware\Multipart\RequestBuilder;
11-
use Soap\Psr18AttachmentMiddleware\Multipart\RequestBuilderInterface;
12-
use Soap\Psr18AttachmentMiddleware\Multipart\ResponseBuilder;
13-
use Soap\Psr18AttachmentMiddleware\Multipart\ResponseBuilderInterface;
14-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorageInterface;
9+
use Soap\Psr18AttachmentsMiddleware\Multipart\AttachmentType;
10+
use Soap\Psr18AttachmentsMiddleware\Multipart\RequestBuilder;
11+
use Soap\Psr18AttachmentsMiddleware\Multipart\RequestBuilderInterface;
12+
use Soap\Psr18AttachmentsMiddleware\Multipart\ResponseBuilder;
13+
use Soap\Psr18AttachmentsMiddleware\Multipart\ResponseBuilderInterface;
14+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorageInterface;
1515

1616
final readonly class AttachmentsMiddleware implements Plugin
1717
{

src/Multipart/AttachmentType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Multipart;
3+
namespace Soap\Psr18AttachmentsMiddleware\Multipart;
44

55
enum AttachmentType : string
66
{

src/Multipart/RequestBuilder.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Multipart;
3+
namespace Soap\Psr18AttachmentsMiddleware\Multipart;
44

55
use Http\Discovery\Psr17FactoryDiscovery;
66
use Http\Message\MultipartStream\MultipartStreamBuilder;
77
use Psr\Http\Message\RequestFactoryInterface;
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\StreamFactoryInterface;
10-
use Soap\Psr18AttachmentMiddleware\Attachment\Attachment;
11-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorageInterface;
10+
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment;
11+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorageInterface;
1212

1313
final readonly class RequestBuilder implements RequestBuilderInterface
1414
{
@@ -39,7 +39,7 @@ public function __invoke(
3939
$builder = new MultipartStreamBuilder($this->streamFactory);
4040

4141
$builder->addData($request->getBody(), [
42-
'Content-Type' => match ($transportType) {
42+
'Content-Type' => match ($attachmentType) {
4343
AttachmentType::Swa => 'text/xml; charset=UTF-8',
4444
AttachmentType::Mtom => 'application/xop+xml; charset=UTF-8; type=application/soap+xml',
4545
},
@@ -68,15 +68,15 @@ public function __invoke(
6868
$request->getMethod(),
6969
$request->getUri(),
7070
)
71-
->withAddedHeader('Content-Type', match($transportType) {
71+
->withAddedHeader('Content-Type', match($attachmentType) {
7272
AttachmentType::Swa => 'multipart/related; type="text/xml"; boundary="' . $boundary. '"; start="soaprequest"',
7373
AttachmentType::Mtom => 'multipart/related; type="application/xop+xml"; boundary="' . $boundary . '"; start="soaprequest"; start-info="application/soap+xml"',
7474
})
7575
->withBody(
7676
$builder->build()
7777
);
7878

79-
if ($transportType === AttachmentType::Swa) {
79+
if ($attachmentType === AttachmentType::Swa) {
8080
$multipartRequest = $multipartRequest->withAddedHeader('SoapAction', $request->getHeaderLine('SoapAction'));
8181
}
8282

src/Multipart/RequestBuilderInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Multipart;
3+
namespace Soap\Psr18AttachmentsMiddleware\Multipart;
44

55
use Psr\Http\Message\RequestInterface;
6-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorageInterface;
6+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorageInterface;
77

88
interface RequestBuilderInterface
99
{

src/Multipart/ResponseBuilder.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Multipart;
3+
namespace Soap\Psr18AttachmentsMiddleware\Multipart;
44

55
use Http\Discovery\Psr17FactoryDiscovery;
66
use Phpro\ResourceStream\Factory\TmpStream;
@@ -9,10 +9,10 @@
99
use Psr\Http\Message\StreamFactoryInterface;
1010
use Riverline\MultiPartParser\Converters\PSR7;
1111
use Riverline\MultiPartParser\StreamedPart;
12-
use Soap\Psr18AttachmentMiddleware\Attachment\Attachment;
13-
use Soap\Psr18AttachmentMiddleware\Attachment\IdGenerator;
14-
use Soap\Psr18AttachmentMiddleware\Exception\SoapMessageNotFoundException;
15-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorageInterface;
12+
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment;
13+
use Soap\Psr18AttachmentsMiddleware\Attachment\IdGenerator;
14+
use Soap\Psr18AttachmentsMiddleware\Exception\SoapMessageNotFoundException;
15+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorageInterface;
1616
use function Psl\Type\string;
1717

1818
final readonly class ResponseBuilder implements ResponseBuilderInterface

src/Multipart/ResponseBuilderInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Multipart;
3+
namespace Soap\Psr18AttachmentsMiddleware\Multipart;
44

55
use Psr\Http\Message\ResponseInterface;
6-
use Soap\Psr18AttachmentMiddleware\Storage\AttachmentStorageInterface;
6+
use Soap\Psr18AttachmentsMiddleware\Storage\AttachmentStorageInterface;
77

88
interface ResponseBuilderInterface
99
{

src/Storage/AttachmentStorage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Storage;
3+
namespace Soap\Psr18AttachmentsMiddleware\Storage;
44

5-
use Soap\Psr18AttachmentMiddleware\Attachment\AttachmentsCollection;
5+
use Soap\Psr18AttachmentsMiddleware\Attachment\AttachmentsCollection;
66

77
final class AttachmentStorage implements AttachmentStorageInterface
88
{

src/Storage/AttachmentStorageInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php declare(strict_types=1);
22

3-
namespace Soap\Psr18AttachmentMiddleware\Storage;
3+
namespace Soap\Psr18AttachmentsMiddleware\Storage;
44

5-
use Soap\Psr18AttachmentMiddleware\Attachment\AttachmentsCollection;
5+
use Soap\Psr18AttachmentsMiddleware\Attachment\AttachmentsCollection;
66

77
interface AttachmentStorageInterface
88
{

tests/.gitignore

Whitespace-only changes.
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace SoapTest\Psr18AttachmentsMiddleware\Unit\Attachment;
4+
5+
use Phpro\ResourceStream\Factory\MemoryStream;
6+
use PHPUnit\Framework\Attributes\Test;
7+
use PHPUnit\Framework\TestCase;
8+
use Soap\Psr18AttachmentsMiddleware\Attachment\Attachment;
9+
10+
final class AttachmentTest extends TestCase
11+
{
12+
#[Test]
13+
public function it_can_load_attachment(): void
14+
{
15+
$attachment = new Attachment(
16+
'id',
17+
'filename',
18+
'mimeType',
19+
$stream = MemoryStream::create()
20+
);
21+
22+
static::assertSame('id', $attachment->id);
23+
static::assertSame('filename', $attachment->filename);
24+
static::assertSame('mimeType', $attachment->mimeType);
25+
static::assertSame($stream, $attachment->content);
26+
}
27+
28+
#[Test]
29+
public function it_can_create_an_attachment(): void
30+
{
31+
$attachment = Attachment::create(
32+
'filename.pdf',
33+
$stream = MemoryStream::create(),
34+
);
35+
36+
static::assertNotEmpty($attachment->id);
37+
static::assertSame('filename.pdf', $attachment->filename);
38+
static::assertSame('application/pdf', $attachment->mimeType);
39+
static::assertSame($stream, $attachment->content);
40+
}
41+
}

0 commit comments

Comments
 (0)