Skip to content
This repository has been archived by the owner on Apr 3, 2021. It is now read-only.

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
## 2.0.0 - 2019-03-22
### Added
- Added parameters to the Request interface and implementation.

### Changed
- Order of constructor parameters
- Default value of the request method.

### Removed
- SearchCriteria dependency by expecting GET parameters as an associative array.
  • Loading branch information
mfrankruijter authored Mar 22, 2019
1 parent 8acde64 commit 5d5bbfd
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 41 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.0.0 - 2019-03-22
### Added
- Added parameters to the Request interface and implementation.

### Changed
- Order of constructor parameters
- Default value of the request method.

### Deprecated
- Nothing

### Removed
- SearchCriteria dependency by expecting GET parameters as an associative array.

### Fixed
- Nothing

### Security
- Nothing


## 1.0.0 - 2019-03-05
### Added
- Initial implementation of ulrack/transaction
Expand All @@ -29,4 +50,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
- Nothing

[Unreleased]: https://github.com/ulrack/transaction/compare/1.0.0...HEAD
[Unreleased]: https://github.com/ulrack/transaction/compare/2.0.0...HEAD
[1.0.0]: https://github.com/ulrack/transaction/compare/1.0.0...2.0.0
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@ The implementation of a `\Ulrack\Transaction\Common\RequestInterface` is provide
in `\Ulrack\Transaction\Transaction\Request`.
Requests expect their arguments in the constructor.

The first argument expects a method. This method can be picked from the

The first argument expects a target for the request.
In the case of a HTTP request this would the URI for the request.

The second argument is the payload of the request.
The payload would be the body of a request, in the case of a HTTP POST request, this would be the form data.

The third argument expects a method. This method can be picked from the
`\Ulrack\Transaction\Common\RequestInterface` and should be one of:
- `RequestInterface::METHOD_GET`
- `RequestInterface::METHOD_POST`
- `RequestInterface::METHOD_PUT`
- `RequestInterface::METHOD_PATCH`
- `RequestInterface::METHOD_DELETE`

The second argument expects a target for the request.
In the case of a HTTP request this would the URI for the request.

The third argument is the payload of the request.
The payload would be the body of a request, in the case of a HTTP POST request, this would be the form data.

The fourth argument is optional and expects an associative array with headers.
The fourth argument is optional and expects an associative array with parameters.
In the case of a HTTP request, this expects the GET parameters.

The fifth argument is also optional and expects a `SearchCriteriaInterface` object.
In the case of a HTTP GET request this would be cause the GET parameters to be filled.
The fifth argument is optional and expects an associative array with headers.

### Response

Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"prefer-stable": true,
"minimum-stability": "stable",
"require": {
"php": "^7.2",
"ulrack/search": "^1.0"
"php": "^7.2"
},
"authors": [
{
Expand Down
8 changes: 3 additions & 5 deletions src/Common/RequestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

namespace Ulrack\Transaction\Common;

use Ulrack\Search\Common\SearchCriteriaInterface;

interface RequestInterface
{
/**
Expand Down Expand Up @@ -88,9 +86,9 @@ public function getTarget(): string;
public function getPayload();

/**
* Retrieves the search criteria for the request.
* Retrieves a associative array of parameters of the request.
*
* @return SearchCriteriaInterface|null
* @return array|null
*/
public function getSearchCriteria(): ?SearchCriteriaInterface;
public function getParameters(): ?array;
}
33 changes: 16 additions & 17 deletions src/Transaction/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

use Ulrack\Transaction\Common\RequestInterface;
use Ulrack\Transaction\Exception\HeaderNotFoundException;
use Ulrack\Search\Common\SearchCriteriaInterface;

class Request implements RequestInterface
{
Expand All @@ -24,30 +23,30 @@ class Request implements RequestInterface
/** @var mixed */
private $payload;

/** @var SearchCriteriaInterface|null */
private $searchCriteria;
/** @var array|null */
private $parameters;

/**
* Constructor
*
* @param string $method
* @param string $target
* @param mixed $payload
* @param array|null $headers
* @param SearchCriteriaInterface|null $searchCriteria
* @param string $target
* @param mixed $payload
* @param array $parameters
* @param string $method
* @param array|null $headers
*/
public function __construct(
string $method,
string $target,
$payload,
string $method = RequestInterface::METHOD_GET,
array $headers = null,
SearchCriteriaInterface $searchCriteria = null
array $parameters = null
) {
$this->method = $method;
$this->headers = $headers;
$this->target = $target;
$this->payload = $payload;
$this->searchCriteria = $searchCriteria;
$this->method = $method;
$this->headers = $headers;
$this->parameters = $parameters;
}

/**
Expand Down Expand Up @@ -109,12 +108,12 @@ public function getPayload()
}

/**
* Retrieves the search criteria for the request.
* Retrieves a associative array of parameters of the request.
*
* @return SearchCriteriaInterface|null
* @return array|null
*/
public function getSearchCriteria(): ?SearchCriteriaInterface
public function getParameters(): ?array
{
return $this->searchCriteria;
return $this->parameters;
}
}
10 changes: 4 additions & 6 deletions tests/Transaction/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPUnit\Framework\TestCase;
use Ulrack\Transaction\Transaction\Request;
use Ulrack\Transaction\Common\RequestInterface;
use Ulrack\Search\Common\SearchCriteriaInterface;
use Ulrack\Transaction\Exception\HeaderNotFoundException;

/**
Expand All @@ -27,17 +26,16 @@ class RequestTest extends TestCase
* @covers ::getHeader
* @covers ::getTarget
* @covers ::getPayload
* @covers ::getSearchCriteria
* @covers ::getParameters
*/
public function testRequest(): void
{
$searchCriteria = $this->createMock(SearchCriteriaInterface::class);
$subject = new Request(
RequestInterface::METHOD_GET,
'foo',
['bar' => 'baz'],
RequestInterface::METHOD_GET,
['baz' => 'qux'],
$searchCriteria
['foo' => 'bar']
);

$this->assertInstanceOf(Request::class, $subject);
Expand All @@ -46,7 +44,7 @@ public function testRequest(): void
$this->assertEquals('qux', $subject->getHeader('baz'));
$this->assertEquals('foo', $subject->getTarget());
$this->assertEquals(['bar' => 'baz'], $subject->getPayload());
$this->assertEquals($searchCriteria, $subject->getSearchCriteria());
$this->assertEquals(['foo' => 'bar'], $subject->getParameters());
$this->expectException(HeaderNotFoundException::class);
$subject->getHeader('foo');
}
Expand Down

0 comments on commit 5d5bbfd

Please sign in to comment.