Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Require Flow 8.3 #19

Merged
merged 11 commits into from
Feb 12, 2024
Merged
6 changes: 2 additions & 4 deletions .github/workflows/functionaltests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ 7.4 ]
flow-version: [ 5.3 ]
php-version: [ 8.1, 8.2 ]
flow-version: [ 8.3 ]
mysql-version: [5.7]

exclude: []

env:
APP_ENV: true
FLOW_CONTEXT: Testing/Functional
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ 7.4 ]
flow-version: [ 5.3 ]

exclude: []
php-version: [ 8.1, 8.2 ]
flow-version: [ 8.3 ]

env:
FLOW_CONTEXT: Testing/Unit
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/ResourceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* source code.
*/

use GuzzleHttp\Psr7\Uri;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Uri;
use Netlogix\JsonApiOrg\Consumer\Service\ConsumerBackendInterface;

class ResourceProxy implements \ArrayAccess
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/Model/ResourceProxyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

use Neos\Cache\Frontend\VariableFrontend;
use Neos\Flow\Cache\CacheManager;
use Neos\Flow\Http\Uri;
use Neos\Flow\Utility\Now;
use Psr\Http\Message\UriInterface;

class ResourceProxyIterator implements \IteratorAggregate, \Countable
{
Expand Down Expand Up @@ -45,7 +45,7 @@ protected function __construct(string $uri = '')
$this->uri = $uri;
}

public static function fromUri(Uri $uri): self
public static function fromUri(UriInterface $uri): self
{
return new static((string)$uri);
}
Expand Down
19 changes: 6 additions & 13 deletions Classes/Domain/Model/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Uri;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
use Psr\Http\Message\UriInterface;

class Type
{
Expand Down Expand Up @@ -57,7 +57,7 @@ class Type
protected $properties = [];

/**
* @var Uri
* @var UriInterface
*/
protected $uri;

Expand All @@ -76,14 +76,14 @@ class Type
* @param string $typeName
* @param string $resourceClassName
* @param array $properties
* @param Uri $uri
* @param UriInterface $uri
* @param array $defaultIncludes
*/
public function __construct(
$typeName,
$resourceClassName = ResourceProxy::class,
array $properties = [],
Uri $uri = null,
UriInterface $uri = null,
array $defaultIncludes = []
) {
$this->typeName = (string)$typeName;
Expand All @@ -95,19 +95,12 @@ public function __construct(
$this->defaultIncludes = $defaultIncludes;
}

/**
* @return Uri
*/
public function getUri()
public function getUri(): UriInterface
{
return $this->uri;
}

/**
* @param Uri $uri
* @return void
*/
public function setUri(Uri $uri)
public function setUri(UriInterface $uri): void
{
$this->uri = $uri;
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Guzzle/Middleware/EndpointCacheMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(callable $handler)
return $handler($request, $options);
}

$requestPath = $request->getUri()->getPath() ?? '';
$requestPath = $request->getUri()->getPath() ?: '';
if (!self::str_ends_with(rtrim($requestPath, '/'), '/.well-known/endpoint-discovery')) {
return $handler($request, $options);
}
Expand Down
11 changes: 6 additions & 5 deletions Classes/Service/ConsumerBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
*/

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Uri;
use Neos\Cache\Exception\InvalidDataException;
use Neos\Cache\Frontend\StringFrontend;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Http\Helper\UriHelper;
use Neos\Flow\Http\Uri;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\Arguments\PageInterface;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\Arguments\SortInterface;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\ResourceProxy;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\ResourceProxyIterator;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\Type;
use Netlogix\JsonApiOrg\Consumer\Guzzle\ClientProvider;
use Psr\Http\Message\UriInterface;

/**
* @Flow\Scope("singleton")
Expand Down Expand Up @@ -83,11 +84,11 @@ public function getType($typeName)
}

/**
* @param Uri $endpointDiscovery
* @param UriInterface $endpointDiscovery
* @throws InvalidDataException
* @throws \Neos\Cache\Exception
*/
public function registerEndpointsByEndpointDiscovery(Uri $endpointDiscovery)
public function registerEndpointsByEndpointDiscovery(UriInterface $endpointDiscovery)
{
$result = $this->requestJson($endpointDiscovery);
foreach ($result['links'] as $link) {
Expand Down Expand Up @@ -180,12 +181,12 @@ public function getQueryUriForFindByTypeAndFilter(
}

/**
* @param Uri $queryUri
* @param UriInterface $queryUri
* @return ResourceProxyIterator
* @throws InvalidDataException
* @throws \Neos\Cache\Exception
*/
public function fetchFromUri(Uri $queryUri)
public function fetchFromUri(UriInterface $queryUri)
{
$resourceProxy = ResourceProxyIterator::fromUri($queryUri);
$resourceProxy = $resourceProxy->loadFromCache();
Expand Down
10 changes: 5 additions & 5 deletions Classes/Service/ConsumerBackendInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* source code.
*/

use Neos\Flow\Http\Uri;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\Arguments\PageInterface;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\Arguments\SortInterface;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\ResourceProxy;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\ResourceProxyIterator;
use Netlogix\JsonApiOrg\Consumer\Domain\Model\Type;
use Psr\Http\Message\UriInterface;

interface ConsumerBackendInterface
{
Expand All @@ -31,9 +31,9 @@ public function addType(Type $type);
public function getType($typeName);

/**
* @param Uri $endpointDiscovery
* @param UriInterface $endpointDiscovery
*/
public function registerEndpointsByEndpointDiscovery(Uri $endpointDiscovery);
public function registerEndpointsByEndpointDiscovery(UriInterface $endpointDiscovery);

/**
* @param string $type
Expand All @@ -46,10 +46,10 @@ public function registerEndpointsByEndpointDiscovery(Uri $endpointDiscovery);
public function findByTypeAndFilter($type, $filter = [], $include = [], PageInterface $page = null, SortInterface $sort = null);

/**
* @param Uri $queryUri
* @param UriInterface $queryUri
* @return ResourceProxyIterator
*/
public function fetchFromUri(Uri $queryUri);
public function fetchFromUri(UriInterface $queryUri);

/**
* @param mixed $type
Expand Down
9 changes: 9 additions & 0 deletions Tests/Common/Guzzle/NoResponseQueued.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Netlogix\JsonApiOrg\Consumer\Tests\Common\Guzzle;

class NoResponseQueued extends \RuntimeException
{
}
4 changes: 2 additions & 2 deletions Tests/Common/Guzzle/TestingClientProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function createClient(): Client
}

if (strpos($uri, 'resource://') === 0
|| strpos($uri, 'data://') === 0) {
|| strpos($uri, 'data:') === 0) {
$uri = (string) $requestUri
->withQuery('')
->withFragment('');
Expand All @@ -72,7 +72,7 @@ public function createClient(): Client
);
}

throw new \RuntimeException(sprintf('No Response queued for URI "%s"', $uri), 1624304664);
throw new NoResponseQueued(sprintf('No Response queued for URI "%s"', $uri), 1624304664);
};

$handlerStack = HandlerStack::create($requestHandler);
Expand Down
35 changes: 25 additions & 10 deletions Tests/Functional/CachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

namespace Netlogix\JsonApiOrg\Consumer\Tests\Functional;

use GuzzleHttp\Psr7\Uri;
use Neos\Cache\Backend\FileBackendEntryDto;
use Neos\Cache\Backend\WithSetupInterface;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Flow\Cache\CacheManager;
use Netlogix\JsonApiOrg\Consumer\Domain\Model as JsonApi;
use Netlogix\JsonApiOrg\Consumer\Tests\Common\Guzzle\NoResponseQueued;

class CachingTest extends FunctionalTestCase
{
Expand All @@ -22,6 +25,7 @@ public function setUp(): void
if ($cache->getBackend() instanceof WithSetupInterface) {
$cache->getBackend()->setup();
}
$cache->flush();
}

/**
Expand All @@ -30,7 +34,7 @@ public function setUp(): void
*/
public function JSON_data_can_be_saved_to_cache(array $jsonApiFixture)
{
$uri = $this->asDataUri([]);
$uri = new Uri('https://some-url.example/foo');

JsonApi\ResourceProxyIterator::fromUri($uri)
->withJsonResult($jsonApiFixture)
Expand All @@ -50,19 +54,30 @@ public function JSON_data_can_be_saved_to_cache(array $jsonApiFixture)
*/
public function Cached_data_respects_cache_lifetime(array $jsonApiFixture)
{
$uri = $this->asDataUri([]);
$uri = new Uri('https://some-url.example/foo');

JsonApi\ResourceProxyIterator::fromUri($uri)
->withJsonResult($jsonApiFixture)
->saveToCache(1);

/**
* @see FileBackendEntryDto::isExpired()
*/
$previousTime = $_SERVER['REQUEST_TIME'];
$_SERVER['REQUEST_TIME'] = time() + 2;
sleep(2);

$result = $this->consumerBackend
->fetchFromUri($uri)
->getArrayCopy();
self::expectException(NoResponseQueued::class);

$this->assertCount(0, $result);
try {
$this->consumerBackend
->fetchFromUri($uri)
->getArrayCopy();
} catch (\Throwable $t) {
throw $t;
} finally {
$_SERVER['REQUEST_TIME'] = $previousTime;
}
}

/**
Expand All @@ -71,7 +86,7 @@ public function Cached_data_respects_cache_lifetime(array $jsonApiFixture)
*/
public function Cached_data_will_not_be_written_to_cache_again_with_same_lifetime_and_tags(array $jsonApiFixture)
{
$uri = $this->asDataUri([]);
$uri = new Uri('https://some-url.example/foo');
$tags = ['foo', 'bar', 'baz'];

JsonApi\ResourceProxyIterator::fromUri($uri)
Expand Down Expand Up @@ -101,7 +116,7 @@ public function Cached_data_will_not_be_written_to_cache_again_with_same_lifetim
*/
public function Cached_data_will_not_be_written_to_cache_again_with_same_lifetime_and_differently_ordered_tags(array $jsonApiFixture)
{
$uri = $this->asDataUri([]);
$uri = new Uri('https://some-url.example/foo');
$tags = ['foo', 'bar', 'baz'];

JsonApi\ResourceProxyIterator::fromUri($uri)
Expand Down Expand Up @@ -131,7 +146,7 @@ public function Cached_data_will_not_be_written_to_cache_again_with_same_lifetim
*/
public function Cached_data_will_be_written_to_cache_again_if_lifetime_differs(array $jsonApiFixture)
{
$uri = $this->asDataUri([]);
$uri = new Uri('https://some-url.example/foo');
$tags = ['foo', 'bar', 'baz'];

JsonApi\ResourceProxyIterator::fromUri($uri)
Expand Down Expand Up @@ -161,7 +176,7 @@ public function Cached_data_will_be_written_to_cache_again_if_lifetime_differs(a
*/
public function Cached_data_will_be_written_to_cache_again_if_tags_differs(array $jsonApiFixture)
{
$uri = $this->asDataUri([]);
$uri = new Uri('https://some-url.example/foo');
$tags = ['foo', 'bar', 'baz'];

JsonApi\ResourceProxyIterator::fromUri($uri)
Expand Down
7 changes: 4 additions & 3 deletions Tests/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

namespace Netlogix\JsonApiOrg\Consumer\Tests\Functional;

use Neos\Flow\Http\Uri;
use GuzzleHttp\Psr7\Uri;
use Neos\Flow\Tests\FunctionalTestCase as BaseTestCase;
use Netlogix\JsonApiOrg\Consumer\Domain\Model as JsonApi;
use Netlogix\JsonApiOrg\Consumer\Service\ConsumerBackend;
use Psr\Http\Message\UriInterface;

class FunctionalTestCase extends BaseTestCase
{
Expand Down Expand Up @@ -49,13 +50,13 @@ public function createEmptyResource(): JsonApi\ResourceProxy
$this->type->__consumerBackend = $this->consumerBackend;
}

public function asDataUri(array $fixture): Uri
public function asDataUri(array $fixture): UriInterface
{
$dataUri = 'data:application/json;base64,' . base64_encode(json_encode($fixture));
return new Uri($dataUri);
}

public function provideJsonResponse()
public static function provideJsonResponse()
{
$entity = [
'id' => 0,
Expand Down
12 changes: 12 additions & 0 deletions Tests/Unit/Guzzle/Middleware/ClosureLike.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Netlogix\JsonApiOrg\Consumer\Tests\Unit\Guzzle\Middleware;

use Psr\Http\Message\RequestInterface;

interface ClosureLike
{
public function __invoke(RequestInterface $request, array $options);
}
Loading