Skip to content

Commit

Permalink
Merge pull request #28 from Ricorocks-Digital-Agency/header-fix
Browse files Browse the repository at this point in the history
Header fixes
  • Loading branch information
lukeraymonddowning authored Jun 19, 2021
2 parents ef907e5 + 1270f33 commit ef89e74
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Header implements Arrayable
public $actor;
public $mustUnderstand;

public function __construct(?string $name = null, ?string $namespace = null, $data = null, bool $mustUnderstand = false, ?string $actor = null)
public function __construct(?string $name = null, ?string $namespace = null, $data = null, bool $mustUnderstand = false, $actor = null)
{
$this->name = $name;
$this->namespace = $namespace;
Expand All @@ -36,7 +36,7 @@ public function data($data = null): self
return tap($this, fn () => $this->data = $data);
}

public function actor(?string $actor = null): self
public function actor($actor = null): self
{
return tap($this, fn () => $this->actor = $actor);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Request/SoapClientRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ protected function constructHeaders()
'namespace' => $header->namespace,
'name' => $header->name,
'data' => $header->data,
'mustUnderstand' => $header->mustUnderstand,
'actor' => $header->actor
'mustunderstand' => $header->mustUnderstand,
'actor' => $header->actor ?? SOAP_ACTOR_NONE
]),
$this->headers
);
Expand Down
4 changes: 2 additions & 2 deletions src/Soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function node($attributes = []): Node
return new Node($attributes);
}

public function header(?string $name = null, ?string $namespace = null, $data = null): Header
public function header(?string $name = null, ?string $namespace = null, $data = null, bool $mustUnderstand = false, $actor = null): Header
{
return new Header($name, $namespace, $data);
return new Header($name, $namespace, $data, $mustUnderstand, $actor);
}

public function include($parameters)
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function soap_node($attributes = []) {
}

if (!function_exists('soap_header')) {
function soap_header(?string $name = null, ?string $namespace = null, $data = null, bool $mustUnderstand = false, ?string $actor = null) {
function soap_header(?string $name = null, ?string $namespace = null, $data = null, bool $mustUnderstand = false, $actor = null) {
return Soap::header($name, $namespace, $data, $mustUnderstand, $actor);
}
}
43 changes: 38 additions & 5 deletions tests/Headers/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use RicorocksDigitalAgency\Soap\Facades\Soap;
use RicorocksDigitalAgency\Soap\Request\SoapClientRequest;
use RicorocksDigitalAgency\Soap\Tests\TestCase;
use SoapHeader;
use SoapVar;

class HeadersTest extends TestCase
Expand Down Expand Up @@ -178,22 +179,54 @@ function (SoapClientRequest $request, $response) {
}

/** @test */
public function the_optional_parameters_of_the_SoapHeader_are_optional()
public function the_data_parameter_is_optional()
{
Soap::fake();

Soap::to(static::EXAMPLE_SOAP_ENDPOINT)
->withHeaders(Soap::header('Auth', 'test.com')->data(null)->actor(null))
->withHeaders(soap_header('Brand', 'test.com', null, false, null))
->withHeaders(Soap::header('Auth', 'test.com')->data(null))
->withHeaders(soap_header('Brand', 'test.com', null))
->call('Add', ['intA' => 10, 'intB' => 25]);

Soap::assertSent(
function (SoapClientRequest $request, $response) {
return $request->getHeaders() == [
Soap::header('Auth', 'test.com', null, false, null),
Soap::header('Brand', 'test.com', null, false, null),
Soap::header('Auth', 'test.com', null),
Soap::header('Brand', 'test.com', null),
];
}
);
}

/** @test */
public function if_the_actor_is_provided_it_is_passed_to_the_php_soap_header()
{
$this->markTestSkipped('This makes a real API call to assert the correct header construction');

$this->app->afterResolving(SoapHeader::class, function ($header) {
$this->assertEquals('test.com', $header->actor);
});

Soap::to(static::EXAMPLE_SOAP_ENDPOINT)
->withHeaders(Soap::header('Auth', 'test.com')->actor('test.com'))
->withHeaders(soap_header('Brand', 'test.com', ['hi'], false, 'test.com'))
->withHeaders(soap_header('Service', 'bar.com')->actor('test.com'))
->call('Add', ['intA' => 10, 'intB' => 25]);
}

/** @test */
public function if_the_actor_is_not_provided_the_php_soap_actor_none_constant_is_passed()
{
$this->markTestSkipped('This makes a real API call to assert the correct header construction');

$this->app->afterResolving(SoapHeader::class, function ($header) {
$this->assertEquals(SOAP_ACTOR_NONE, $header->actor);
});

Soap::to(static::EXAMPLE_SOAP_ENDPOINT)
->withHeaders(Soap::header('Auth', 'test.com')->actor(null))
->withHeaders(soap_header('Brand', 'test.com', null, false, null))
->withHeaders(soap_header('Service', 'bar.com'))
->call('Add', ['intA' => 10, 'intB' => 25]);
}
}

0 comments on commit ef89e74

Please sign in to comment.