Skip to content

Commit

Permalink
PHP 8.0 support
Browse files Browse the repository at this point in the history
Signed-off-by: Eugene Kosogin <[email protected]>
  • Loading branch information
ekosogin authored and weierophinney committed Jun 23, 2021
1 parent b23d60e commit 148829c
Show file tree
Hide file tree
Showing 13 changed files with 1,184 additions and 550 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/coveralls-upload.json
/phpunit.xml
/vendor/
/.phpunit.result.cache
/.phpcs-cache
23 changes: 12 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
}
},
"require": {
"php": "^7.3",
"laminas-api-tools/api-tools-api-problem": "^1.2.1",
"laminas-api-tools/api-tools-content-negotiation": "^1.2.2",
"laminas-api-tools/api-tools-content-validation": "^1.3.3",
"php": "^7.3 || ~8.0.0",
"laminas-api-tools/api-tools-api-problem": "^1.4",
"laminas-api-tools/api-tools-content-negotiation": "^1.5",
"laminas-api-tools/api-tools-content-validation": "^1.9",
"laminas-api-tools/api-tools-hal": "^1.4.1",
"laminas-api-tools/api-tools-mvc-auth": "^1.4.1",
"laminas-api-tools/api-tools-oauth2": "^1.4",
"laminas-api-tools/api-tools-provider": "^1.2",
"laminas-api-tools/api-tools-rest": "^1.3.1",
"laminas-api-tools/api-tools-rpc": "^1.3",
"laminas-api-tools/api-tools-versioning": "^1.2",
"laminas-api-tools/api-tools-mvc-auth": "^1.6.0",
"laminas-api-tools/api-tools-oauth2": "^1.7",
"laminas-api-tools/api-tools-provider": "^1.4",
"laminas-api-tools/api-tools-rest": "^1.6.0",
"laminas-api-tools/api-tools-rpc": "^1.5",
"laminas-api-tools/api-tools-versioning": "^1.4",
"laminas/laminas-db": "^2.8.1",
"laminas/laminas-eventmanager": "^2.6.3 || ^3.0.1",
"laminas/laminas-loader": "^2.5.1",
Expand All @@ -49,7 +49,8 @@
"require-dev": {
"laminas/laminas-coding-standard": "~2.3.0",
"laminas/laminas-http": "^2.5.4",
"phpunit/phpunit": "^7.1.5"
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.3"
},
"suggest": {
"alcaeus/mongo-php-adapter": "^1.0.5, if you are using ext/mongodb and wish to use the MongoConnectedListener.",
Expand Down
1,614 changes: 1,103 additions & 511 deletions composer.lock

Large diffs are not rendered by default.

26 changes: 11 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="api-tools Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="api-tools Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions src/DbConnectedResourceAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Laminas\ApiTools;

use Interop\Container\ContainerInterface;
use Laminas\ApiTools\Rest\Resource;
use Laminas\Db\TableGateway\TableGatewayInterface;
use Laminas\Paginator\Paginator;
use Laminas\ServiceManager\AbstractFactoryInterface;
Expand Down Expand Up @@ -169,8 +170,7 @@ protected function getIdentifierFromConfig(array $config)
* @param array $config
* @param string $requestedName
* @return string
* @throws ServiceNotCreatedException If the discovered collection class
* does not exist.
* @throws ServiceNotCreatedException If the discovered collection class does not exist.
*/
protected function getCollectionFromConfig(array $config, $requestedName)
{
Expand Down
1 change: 0 additions & 1 deletion src/MvcAuth/UnauthenticatedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Laminas\ApiTools\ApiProblem\ApiProblem;
use Laminas\ApiTools\ApiProblem\ApiProblemResponse;
use Laminas\ApiTools\MvcAuth\MvcAuthEvent;

class UnauthenticatedListener
{
Expand Down
1 change: 0 additions & 1 deletion src/MvcAuth/UnauthorizedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Laminas\ApiTools\ApiProblem\ApiProblem;
use Laminas\ApiTools\ApiProblem\ApiProblemResponse;
use Laminas\ApiTools\MvcAuth\MvcAuthEvent;

class UnauthorizedListener
{
Expand Down
7 changes: 6 additions & 1 deletion test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
use Laminas\Mvc\MvcEvent;
use Laminas\ServiceManager\ServiceManager;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;

class ApplicationTest extends TestCase
{
protected function setUp()
use ProphecyTrait;

protected function setUp(): void
{
$events = new EventManager();

Expand Down Expand Up @@ -86,6 +90,7 @@ public function setUpServices($services, EventManager $events, $request, $respon
/**
* @param ObjectProphecy&PhpEnvironment\Request $request
* @param ObjectProphecy&PhpEnvironment\Response $response
* @throws ReflectionException
*/
public function setUpMvcEvent(Application $app, $request, $response): Application
{
Expand Down
1 change: 1 addition & 0 deletions test/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class AutoloaderTest extends TestCase
{
/** @psalm-return array<string, array{0: class-string}> */
public function classesToAutoload(): array
{
return [
Expand Down
8 changes: 7 additions & 1 deletion test/DbConnectedResourceAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
use Laminas\ApiTools\DbConnectedResourceAbstractFactory;
use Laminas\Db\TableGateway\TableGateway;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;

class DbConnectedResourceAbstractFactoryTest extends TestCase
{
protected function setUp()
use ProphecyTrait;

protected function setUp(): void
{
$this->services = $this->prophesize(ContainerInterface::class);
$this->factory = new DbConnectedResourceAbstractFactory();
Expand Down Expand Up @@ -69,6 +72,7 @@ public function invalidConfig(): array
}

/**
* @param array $configForDbConnected
* @dataProvider invalidConfig
*/
public function testWillNotCreateServiceIfDbConnectedSegmentIsInvalidConfiguration(
Expand All @@ -93,6 +97,7 @@ public function testWillNotCreateServiceIfDbConnectedSegmentIsInvalidConfigurati
$this->assertFalse($this->factory->canCreate($this->services->reveal(), 'Foo'));
}

/** @psalm-return array<string, array{0: array<string, string>, 1: string}> */
public function validConfig(): array
{
return [
Expand Down Expand Up @@ -123,6 +128,7 @@ public function testWillCreateServiceIfDbConnectedSegmentIsValid(
}

/**
* @param array $configForDbConnected
* @dataProvider validConfig
*/
public function testFactoryReturnsResourceBasedOnConfiguration(
Expand Down
9 changes: 8 additions & 1 deletion test/DbConnectedResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,23 @@
use Laminas\Db\TableGateway\TableGateway;
use Laminas\InputFilter\InputFilter;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionException;
use ReflectionObject;

class DbConnectedResourceTest extends TestCase
{
protected function setUp()
use ProphecyTrait;

protected function setUp(): void
{
$this->table = $this->prophesize(TableGateway::class);
$this->resource = new DbConnectedResource($this->table->reveal(), 'id', ArrayObject::class);
}

/**
* @throws ReflectionException
*/
protected function setInputFilter(
DbConnectedResource $resource,
InputFilter $inputFilter
Expand Down
14 changes: 11 additions & 3 deletions test/Model/MongoConnectedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MongoConnectedListenerTest extends TestCase
/** @var MongoDB */
protected static $mongoDb;

protected function setUp()
protected function setUp(): void
{
if (
! (extension_loaded('mongodb') || extension_loaded('mongo'))
Expand All @@ -40,14 +40,17 @@ protected function setUp()
$this->mongoListener = new MongoConnectedListener($collection);
}

public static function tearDownAfterClass()
public static function tearDownAfterClass(): void
{
if (static::$mongoDb instanceof MongoDB) {
static::$mongoDb->drop();
}
}

public function testCreate(): string
/**
* @return null|string|int
*/
public function testCreate()
{
$data = ['foo' => 'bar'];
$result = $this->mongoListener->create($data);
Expand All @@ -56,6 +59,8 @@ public function testCreate(): string
}

/**
* @param mixed $lastId
* @return mixed
* @depends testCreate
*/
public function testFetch(string $lastId): string
Expand All @@ -73,6 +78,8 @@ public function testFetch(string $lastId): string
}

/**
* @param mixed $lastId
* @return mixed
* @depends testFetch
*/
public function testPatch(string $lastId): string
Expand All @@ -88,6 +95,7 @@ public function testPatch(string $lastId): string
}

/**
* @param mixed $lastId
* @depends testPatch
*/
public function testDelete(string $lastId): void
Expand Down
24 changes: 21 additions & 3 deletions test/TableGatewayAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
use Laminas\Hydrator\ClassMethodsHydrator;
use Laminas\Hydrator\HydratorPluginManager;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use ReflectionException;
use ReflectionProperty;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Adapter\AdapterInterface;

use function class_exists;

class TableGatewayAbstractFactoryTest extends TestCase
{
protected function setUp()
use ProphecyTrait;

protected function setUp(): void
{
$this->services = $this->prophesize(ContainerInterface::class);
$this->factory = new TableGatewayAbstractFactory();
Expand Down Expand Up @@ -137,6 +142,7 @@ public function testWillCreateServiceIfConfigContainsValidTableNameNoAdapterName
$this->assertTrue($this->factory->canCreate($this->services->reveal(), 'Foo\Table'));
}

/** @psalm-return array<string, array{0: class-string}> */
public function validConfig(): array
{
return [
Expand Down Expand Up @@ -193,7 +199,8 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfiguration(strin
$resultSet = $gateway->getResultSetPrototype();
$this->assertInstanceOf(HydratingResultSet::class, $resultSet);
$this->assertSame($hydrator, $resultSet->getHydrator());
$this->assertAttributeInstanceOf(TestAsset\Foo::class, 'objectPrototype', $resultSet);

$this->assertObjectPrototypeProperty($resultSet, TestAsset\Foo::class);
}

/**
Expand Down Expand Up @@ -241,7 +248,8 @@ public function testFactoryReturnsTableGatewayInstanceBasedOnConfigurationWithou
$resultSet = $gateway->getResultSetPrototype();
$this->assertInstanceOf(HydratingResultSet::class, $resultSet);
$this->assertInstanceOf($this->getClassMethodsHydratorClassName(), $resultSet->getHydrator());
$this->assertAttributeInstanceOf(TestAsset\Bar::class, 'objectPrototype', $resultSet);

$this->assertObjectPrototypeProperty($resultSet, TestAsset\Bar::class);
}

/**
Expand All @@ -258,4 +266,14 @@ private function getClassMethodsHydratorClassName()

return ClassMethods::class;
}

/**
* @throws ReflectionException
*/
private function assertObjectPrototypeProperty(HydratingResultSet $resultSet, string $expectedClassName): void
{
$objectPrototypeProperty = new ReflectionProperty($resultSet, 'objectPrototype');
$objectPrototypeProperty->setAccessible(true);
$this->assertInstanceOf($expectedClassName, $objectPrototypeProperty->getValue($resultSet));
}
}

0 comments on commit 148829c

Please sign in to comment.