composer vendor update and .env file fixes, remove debug echo

No more echo for any debug logging
Update .env file sample data
This commit is contained in:
Clemens Schwaighofer
2022-03-16 16:59:12 +09:00
parent b075ee3dc5
commit 35a7229158
38 changed files with 646 additions and 288 deletions

30
www/composer.lock generated
View File

@@ -850,16 +850,16 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.18",
"version": "9.5.19",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "1b5856028273bfd855e60a887278857d872ec67a"
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b5856028273bfd855e60a887278857d872ec67a",
"reference": "1b5856028273bfd855e60a887278857d872ec67a",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807",
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807",
"shasum": ""
},
"require": {
@@ -889,7 +889,7 @@
"sebastian/global-state": "^5.0.1",
"sebastian/object-enumerator": "^4.0.3",
"sebastian/resource-operations": "^3.0.3",
"sebastian/type": "^2.3.4",
"sebastian/type": "^3.0",
"sebastian/version": "^3.0.2"
},
"require-dev": {
@@ -937,7 +937,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.18"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19"
},
"funding": [
{
@@ -949,7 +949,7 @@
"type": "github"
}
],
"time": "2022-03-08T06:52:28+00:00"
"time": "2022-03-15T09:57:31+00:00"
},
{
"name": "sebastian/cli-parser",
@@ -1808,28 +1808,28 @@
},
{
"name": "sebastian/type",
"version": "2.3.4",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/type.git",
"reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914"
"reference": "b233b84bc4465aff7b57cf1c4bc75c86d00d6dad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8cd8a1c753c90bc1a0f5372170e3e489136f914",
"reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914",
"url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b233b84bc4465aff7b57cf1c4bc75c86d00d6dad",
"reference": "b233b84bc4465aff7b57cf1c4bc75c86d00d6dad",
"shasum": ""
},
"require": {
"php": ">=7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.3"
"phpunit/phpunit": "^9.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
"dev-master": "3.0-dev"
}
},
"autoload": {
@@ -1852,7 +1852,7 @@
"homepage": "https://github.com/sebastianbergmann/type",
"support": {
"issues": "https://github.com/sebastianbergmann/type/issues",
"source": "https://github.com/sebastianbergmann/type/tree/2.3.4"
"source": "https://github.com/sebastianbergmann/type/tree/3.0.0"
},
"funding": [
{
@@ -1860,7 +1860,7 @@
"type": "github"
}
],
"time": "2021-06-15T12:49:02+00:00"
"time": "2022-03-15T09:54:48+00:00"
},
{
"name": "sebastian/version",

View File

@@ -2,7 +2,7 @@
BASE_NAME=
G_TITLE=
# DB configs
DB_NAME_TEST=
DB_USER_TEST=
DB_PASS_TEST=
DB_HOST_TEST=
DB_NAME.TEST=
DB_USER.TEST=
DB_PASS.TEST=
DB_HOST.TEST=

View File

@@ -13,10 +13,10 @@ declare(strict_types=1);
// please be VERY carefull only to change the right side
$DB_CONFIG = [
'test' => [
'db_name' => $_ENV['DB_NAME_TEST'] ?? '',
'db_user' => $_ENV['DB_USER_TEST'] ?? '',
'db_pass' => $_ENV['DB_PASS_TEST'] ?? '',
'db_host' => $_ENV['DB_HOST_TEST'] ?? '',
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
'db_user' => $_ENV['DB_USER.TEST'] ?? '',
'db_pass' => $_ENV['DB_PASS.TEST'] ?? '',
'db_host' => $_ENV['DB_HOST.TEST'] ?? '',
'db_port' => 5432,
'db_schema' => 'public',
'db_type' => 'pgsql',

View File

@@ -11,8 +11,9 @@
declare(strict_types=1);
// print debug messages
echo $login->log->printErrorMsg();
echo $cms->log->printErrorMsg();
// remove if no echo output is actually needed
// echo $login->log->printErrorMsg();
// echo $cms->log->printErrorMsg();
$cms->log->debug('DEBUGEND', '==================================== [END]');
// __END__

View File

@@ -652,24 +652,25 @@ return array(
'SebastianBergmann\\Timer\\ResourceUsageFormatter' => $vendorDir . '/phpunit/php-timer/src/ResourceUsageFormatter.php',
'SebastianBergmann\\Timer\\TimeSinceStartOfRequestNotAvailableException' => $vendorDir . '/phpunit/php-timer/src/exceptions/TimeSinceStartOfRequestNotAvailableException.php',
'SebastianBergmann\\Timer\\Timer' => $vendorDir . '/phpunit/php-timer/src/Timer.php',
'SebastianBergmann\\Type\\CallableType' => $vendorDir . '/sebastian/type/src/CallableType.php',
'SebastianBergmann\\Type\\CallableType' => $vendorDir . '/sebastian/type/src/type/CallableType.php',
'SebastianBergmann\\Type\\Exception' => $vendorDir . '/sebastian/type/src/exception/Exception.php',
'SebastianBergmann\\Type\\FalseType' => $vendorDir . '/sebastian/type/src/FalseType.php',
'SebastianBergmann\\Type\\GenericObjectType' => $vendorDir . '/sebastian/type/src/GenericObjectType.php',
'SebastianBergmann\\Type\\IterableType' => $vendorDir . '/sebastian/type/src/IterableType.php',
'SebastianBergmann\\Type\\LogicException' => $vendorDir . '/sebastian/type/src/exception/LogicException.php',
'SebastianBergmann\\Type\\MixedType' => $vendorDir . '/sebastian/type/src/MixedType.php',
'SebastianBergmann\\Type\\NullType' => $vendorDir . '/sebastian/type/src/NullType.php',
'SebastianBergmann\\Type\\ObjectType' => $vendorDir . '/sebastian/type/src/ObjectType.php',
'SebastianBergmann\\Type\\FalseType' => $vendorDir . '/sebastian/type/src/type/FalseType.php',
'SebastianBergmann\\Type\\GenericObjectType' => $vendorDir . '/sebastian/type/src/type/GenericObjectType.php',
'SebastianBergmann\\Type\\IntersectionType' => $vendorDir . '/sebastian/type/src/type/IntersectionType.php',
'SebastianBergmann\\Type\\IterableType' => $vendorDir . '/sebastian/type/src/type/IterableType.php',
'SebastianBergmann\\Type\\MixedType' => $vendorDir . '/sebastian/type/src/type/MixedType.php',
'SebastianBergmann\\Type\\NeverType' => $vendorDir . '/sebastian/type/src/type/NeverType.php',
'SebastianBergmann\\Type\\NullType' => $vendorDir . '/sebastian/type/src/type/NullType.php',
'SebastianBergmann\\Type\\ObjectType' => $vendorDir . '/sebastian/type/src/type/ObjectType.php',
'SebastianBergmann\\Type\\ReflectionMapper' => $vendorDir . '/sebastian/type/src/ReflectionMapper.php',
'SebastianBergmann\\Type\\RuntimeException' => $vendorDir . '/sebastian/type/src/exception/RuntimeException.php',
'SebastianBergmann\\Type\\SimpleType' => $vendorDir . '/sebastian/type/src/SimpleType.php',
'SebastianBergmann\\Type\\StaticType' => $vendorDir . '/sebastian/type/src/StaticType.php',
'SebastianBergmann\\Type\\Type' => $vendorDir . '/sebastian/type/src/Type.php',
'SebastianBergmann\\Type\\SimpleType' => $vendorDir . '/sebastian/type/src/type/SimpleType.php',
'SebastianBergmann\\Type\\StaticType' => $vendorDir . '/sebastian/type/src/type/StaticType.php',
'SebastianBergmann\\Type\\Type' => $vendorDir . '/sebastian/type/src/type/Type.php',
'SebastianBergmann\\Type\\TypeName' => $vendorDir . '/sebastian/type/src/TypeName.php',
'SebastianBergmann\\Type\\UnionType' => $vendorDir . '/sebastian/type/src/UnionType.php',
'SebastianBergmann\\Type\\UnknownType' => $vendorDir . '/sebastian/type/src/UnknownType.php',
'SebastianBergmann\\Type\\VoidType' => $vendorDir . '/sebastian/type/src/VoidType.php',
'SebastianBergmann\\Type\\UnionType' => $vendorDir . '/sebastian/type/src/type/UnionType.php',
'SebastianBergmann\\Type\\UnknownType' => $vendorDir . '/sebastian/type/src/type/UnknownType.php',
'SebastianBergmann\\Type\\VoidType' => $vendorDir . '/sebastian/type/src/type/VoidType.php',
'SebastianBergmann\\Version' => $vendorDir . '/sebastian/version/src/Version.php',
'Smarty' => $baseDir . '/lib/Smarty/Smarty.class.php',
'SmartyBC' => $baseDir . '/lib/Smarty/SmartyBC.class.php',

View File

@@ -717,24 +717,25 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
'SebastianBergmann\\Timer\\ResourceUsageFormatter' => __DIR__ . '/..' . '/phpunit/php-timer/src/ResourceUsageFormatter.php',
'SebastianBergmann\\Timer\\TimeSinceStartOfRequestNotAvailableException' => __DIR__ . '/..' . '/phpunit/php-timer/src/exceptions/TimeSinceStartOfRequestNotAvailableException.php',
'SebastianBergmann\\Timer\\Timer' => __DIR__ . '/..' . '/phpunit/php-timer/src/Timer.php',
'SebastianBergmann\\Type\\CallableType' => __DIR__ . '/..' . '/sebastian/type/src/CallableType.php',
'SebastianBergmann\\Type\\CallableType' => __DIR__ . '/..' . '/sebastian/type/src/type/CallableType.php',
'SebastianBergmann\\Type\\Exception' => __DIR__ . '/..' . '/sebastian/type/src/exception/Exception.php',
'SebastianBergmann\\Type\\FalseType' => __DIR__ . '/..' . '/sebastian/type/src/FalseType.php',
'SebastianBergmann\\Type\\GenericObjectType' => __DIR__ . '/..' . '/sebastian/type/src/GenericObjectType.php',
'SebastianBergmann\\Type\\IterableType' => __DIR__ . '/..' . '/sebastian/type/src/IterableType.php',
'SebastianBergmann\\Type\\LogicException' => __DIR__ . '/..' . '/sebastian/type/src/exception/LogicException.php',
'SebastianBergmann\\Type\\MixedType' => __DIR__ . '/..' . '/sebastian/type/src/MixedType.php',
'SebastianBergmann\\Type\\NullType' => __DIR__ . '/..' . '/sebastian/type/src/NullType.php',
'SebastianBergmann\\Type\\ObjectType' => __DIR__ . '/..' . '/sebastian/type/src/ObjectType.php',
'SebastianBergmann\\Type\\FalseType' => __DIR__ . '/..' . '/sebastian/type/src/type/FalseType.php',
'SebastianBergmann\\Type\\GenericObjectType' => __DIR__ . '/..' . '/sebastian/type/src/type/GenericObjectType.php',
'SebastianBergmann\\Type\\IntersectionType' => __DIR__ . '/..' . '/sebastian/type/src/type/IntersectionType.php',
'SebastianBergmann\\Type\\IterableType' => __DIR__ . '/..' . '/sebastian/type/src/type/IterableType.php',
'SebastianBergmann\\Type\\MixedType' => __DIR__ . '/..' . '/sebastian/type/src/type/MixedType.php',
'SebastianBergmann\\Type\\NeverType' => __DIR__ . '/..' . '/sebastian/type/src/type/NeverType.php',
'SebastianBergmann\\Type\\NullType' => __DIR__ . '/..' . '/sebastian/type/src/type/NullType.php',
'SebastianBergmann\\Type\\ObjectType' => __DIR__ . '/..' . '/sebastian/type/src/type/ObjectType.php',
'SebastianBergmann\\Type\\ReflectionMapper' => __DIR__ . '/..' . '/sebastian/type/src/ReflectionMapper.php',
'SebastianBergmann\\Type\\RuntimeException' => __DIR__ . '/..' . '/sebastian/type/src/exception/RuntimeException.php',
'SebastianBergmann\\Type\\SimpleType' => __DIR__ . '/..' . '/sebastian/type/src/SimpleType.php',
'SebastianBergmann\\Type\\StaticType' => __DIR__ . '/..' . '/sebastian/type/src/StaticType.php',
'SebastianBergmann\\Type\\Type' => __DIR__ . '/..' . '/sebastian/type/src/Type.php',
'SebastianBergmann\\Type\\SimpleType' => __DIR__ . '/..' . '/sebastian/type/src/type/SimpleType.php',
'SebastianBergmann\\Type\\StaticType' => __DIR__ . '/..' . '/sebastian/type/src/type/StaticType.php',
'SebastianBergmann\\Type\\Type' => __DIR__ . '/..' . '/sebastian/type/src/type/Type.php',
'SebastianBergmann\\Type\\TypeName' => __DIR__ . '/..' . '/sebastian/type/src/TypeName.php',
'SebastianBergmann\\Type\\UnionType' => __DIR__ . '/..' . '/sebastian/type/src/UnionType.php',
'SebastianBergmann\\Type\\UnknownType' => __DIR__ . '/..' . '/sebastian/type/src/UnknownType.php',
'SebastianBergmann\\Type\\VoidType' => __DIR__ . '/..' . '/sebastian/type/src/VoidType.php',
'SebastianBergmann\\Type\\UnionType' => __DIR__ . '/..' . '/sebastian/type/src/type/UnionType.php',
'SebastianBergmann\\Type\\UnknownType' => __DIR__ . '/..' . '/sebastian/type/src/type/UnknownType.php',
'SebastianBergmann\\Type\\VoidType' => __DIR__ . '/..' . '/sebastian/type/src/type/VoidType.php',
'SebastianBergmann\\Version' => __DIR__ . '/..' . '/sebastian/version/src/Version.php',
'Smarty' => __DIR__ . '/../..' . '/lib/Smarty/Smarty.class.php',
'SmartyBC' => __DIR__ . '/../..' . '/lib/Smarty/SmartyBC.class.php',

View File

@@ -885,17 +885,17 @@
},
{
"name": "phpunit/phpunit",
"version": "9.5.18",
"version_normalized": "9.5.18.0",
"version": "9.5.19",
"version_normalized": "9.5.19.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "1b5856028273bfd855e60a887278857d872ec67a"
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1b5856028273bfd855e60a887278857d872ec67a",
"reference": "1b5856028273bfd855e60a887278857d872ec67a",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807",
"reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807",
"shasum": ""
},
"require": {
@@ -925,7 +925,7 @@
"sebastian/global-state": "^5.0.1",
"sebastian/object-enumerator": "^4.0.3",
"sebastian/resource-operations": "^3.0.3",
"sebastian/type": "^2.3.4",
"sebastian/type": "^3.0",
"sebastian/version": "^3.0.2"
},
"require-dev": {
@@ -936,7 +936,7 @@
"ext-soap": "*",
"ext-xdebug": "*"
},
"time": "2022-03-08T06:52:28+00:00",
"time": "2022-03-15T09:57:31+00:00",
"bin": [
"phpunit"
],
@@ -975,7 +975,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.18"
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19"
},
"funding": [
{
@@ -1888,30 +1888,30 @@
},
{
"name": "sebastian/type",
"version": "2.3.4",
"version_normalized": "2.3.4.0",
"version": "3.0.0",
"version_normalized": "3.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/type.git",
"reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914"
"reference": "b233b84bc4465aff7b57cf1c4bc75c86d00d6dad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8cd8a1c753c90bc1a0f5372170e3e489136f914",
"reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914",
"url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b233b84bc4465aff7b57cf1c4bc75c86d00d6dad",
"reference": "b233b84bc4465aff7b57cf1c4bc75c86d00d6dad",
"shasum": ""
},
"require": {
"php": ">=7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.3"
"phpunit/phpunit": "^9.5"
},
"time": "2021-06-15T12:49:02+00:00",
"time": "2022-03-15T09:54:48+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
"dev-master": "3.0-dev"
}
},
"installation-source": "dist",
@@ -1935,7 +1935,7 @@
"homepage": "https://github.com/sebastianbergmann/type",
"support": {
"issues": "https://github.com/sebastianbergmann/type/issues",
"source": "https://github.com/sebastianbergmann/type/tree/2.3.4"
"source": "https://github.com/sebastianbergmann/type/tree/3.0.0"
},
"funding": [
{

View File

@@ -5,7 +5,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '40edbe271dad56a18dff101983b5ed25f7cc5e85',
'reference' => 'b075ee3dc5654a33da9e41fab338edb536695a25',
'name' => 'gullevek/corelibs',
'dev' => true,
),
@@ -25,7 +25,7 @@
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => '40edbe271dad56a18dff101983b5ed25f7cc5e85',
'reference' => 'b075ee3dc5654a33da9e41fab338edb536695a25',
'dev_requirement' => false,
),
'myclabs/deep-copy' => array(
@@ -146,12 +146,12 @@
'dev_requirement' => true,
),
'phpunit/phpunit' => array(
'pretty_version' => '9.5.18',
'version' => '9.5.18.0',
'pretty_version' => '9.5.19',
'version' => '9.5.19.0',
'type' => 'library',
'install_path' => __DIR__ . '/../phpunit/phpunit',
'aliases' => array(),
'reference' => '1b5856028273bfd855e60a887278857d872ec67a',
'reference' => '35ea4b7f3acabb26f4bb640f8c30866c401da807',
'dev_requirement' => true,
),
'sebastian/cli-parser' => array(
@@ -281,12 +281,12 @@
'dev_requirement' => true,
),
'sebastian/type' => array(
'pretty_version' => '2.3.4',
'version' => '2.3.4.0',
'pretty_version' => '3.0.0',
'version' => '3.0.0.0',
'type' => 'library',
'install_path' => __DIR__ . '/../sebastian/type',
'aliases' => array(),
'reference' => 'b8cd8a1c753c90bc1a0f5372170e3e489136f914',
'reference' => 'b233b84bc4465aff7b57cf1c4bc75c86d00d6dad',
'dev_requirement' => true,
),
'sebastian/version' => array(

View File

@@ -2,6 +2,14 @@
All notable changes of the PHPUnit 9.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
## [9.5.19] - 2022-03-15
### Fixed
* [#4929](https://github.com/sebastianbergmann/phpunit/issues/4929): Test Double code generator does not handle new expressions inside parameter default values
* [#4932](https://github.com/sebastianbergmann/phpunit/issues/4932): Backport support for intersection types from PHPUnit 10 to PHPUnit 9.5
* [#4933](https://github.com/sebastianbergmann/phpunit/issues/4933): Backport support for `never` type from PHPUnit 10 to PHPUnit 9.5
## [9.5.18] - 2022-03-08
### Fixed
@@ -142,6 +150,7 @@ All notable changes of the PHPUnit 9.5 release series are documented in this fil
* [#4535](https://github.com/sebastianbergmann/phpunit/issues/4535): `getMockFromWsdl()` does not handle methods that do not have parameters correctly
[9.5.19]: https://github.com/sebastianbergmann/phpunit/compare/9.5.18...9.5.19
[9.5.18]: https://github.com/sebastianbergmann/phpunit/compare/9.5.17...9.5.18
[9.5.17]: https://github.com/sebastianbergmann/phpunit/compare/9.5.16...9.5.17
[9.5.16]: https://github.com/sebastianbergmann/phpunit/compare/dc738383c519243b0a967f63943a848d3fd861aa...9.5.16

View File

@@ -47,7 +47,7 @@
"sebastian/global-state": "^5.0.1",
"sebastian/object-enumerator": "^4.0.3",
"sebastian/resource-operations": "^3.0.3",
"sebastian/type": "^2.3.4",
"sebastian/type": "^3.0",
"sebastian/version": "^3.0.2"
},
"require-dev": {

View File

@@ -171,6 +171,67 @@ final class Generator
);
}
/**
* @psalm-param list<class-string> $interfaces
*
* @throws RuntimeException
* @throws UnknownTypeException
*/
public function getMockForInterfaces(array $interfaces, bool $callAutoload = true): MockObject
{
if (count($interfaces) < 2) {
throw new RuntimeException('At least two interfaces must be specified');
}
foreach ($interfaces as $interface) {
if (!interface_exists($interface, $callAutoload)) {
throw new UnknownTypeException($interface);
}
}
sort($interfaces);
$methods = [];
foreach ($interfaces as $interface) {
$methods = array_merge($methods, $this->getClassMethods($interface));
}
if (count(array_unique($methods)) < count($methods)) {
throw new RuntimeException('Interfaces must not declare the same method');
}
$unqualifiedNames = [];
foreach ($interfaces as $interface) {
$parts = explode('\\', $interface);
$unqualifiedNames[] = array_pop($parts);
}
sort($unqualifiedNames);
do {
$intersectionName = sprintf(
'Intersection_%s_%s',
implode('_', $unqualifiedNames),
substr(md5((string) mt_rand()), 0, 8)
);
} while (interface_exists($intersectionName, false));
$template = $this->getTemplate('intersection.tpl');
$template->setVar(
[
'intersection' => $intersectionName,
'interfaces' => implode(', ', $interfaces),
]
);
eval($template->render());
return $this->getMock($intersectionName);
}
/**
* Returns a mock object for the specified abstract class with all abstract
* methods of the class mocked.

View File

@@ -0,0 +1,5 @@
declare(strict_types=1);
interface {intersection} extends {interfaces}
{
}

View File

@@ -121,17 +121,22 @@ final class Invocation implements SelfDescribing
return null;
}
$intersection = false;
$union = false;
if (strpos($this->returnType, '|') !== false) {
$types = explode('|', $this->returnType);
$union = true;
} elseif (strpos($this->returnType, '&') !== false) {
$types = explode('&', $this->returnType);
$intersection = true;
} else {
$types = [$this->returnType];
}
$types = array_map('strtolower', $types);
if (!$intersection) {
if (in_array('', $types, true) ||
in_array('null', $types, true) ||
in_array('mixed', $types, true) ||
@@ -197,6 +202,40 @@ final class Invocation implements SelfDescribing
if (!$union) {
try {
return (new Generator)->getMock($this->returnType, [], [], '', false);
} catch (Throwable $t) {
if ($t instanceof Exception) {
throw $t;
}
throw new RuntimeException(
$t->getMessage(),
(int) $t->getCode(),
$t
);
}
}
}
$reason = '';
if ($union) {
$reason = ' because the declared return type is a union';
} elseif ($intersection) {
$reason = ' because the declared return type is an intersection';
$onlyInterfaces = true;
foreach ($types as $type) {
if (!interface_exists($type)) {
$onlyInterfaces = false;
break;
}
}
if ($onlyInterfaces) {
try {
return (new Generator)->getMockForInterfaces($types);
} catch (Throwable $t) {
throw new RuntimeException(
sprintf(
@@ -209,12 +248,14 @@ final class Invocation implements SelfDescribing
);
}
}
}
throw new RuntimeException(
sprintf(
'Return value for %s::%s() cannot be generated because the declared return type is a union, please configure a return value for this method',
'Return value for %s::%s() cannot be generated%s, please configure a return value for this method',
$this->className,
$this->methodName
$this->methodName,
$reason
)
);
}

View File

@@ -10,14 +10,20 @@
namespace PHPUnit\Framework\MockObject;
use const DIRECTORY_SEPARATOR;
use function explode;
use function implode;
use function is_object;
use function is_string;
use function preg_match;
use function preg_replace;
use function sprintf;
use function strlen;
use function strpos;
use function substr;
use function substr_count;
use function trim;
use function var_export;
use ReflectionIntersectionType;
use ReflectionMethod;
use ReflectionNamedType;
use ReflectionParameter;
@@ -27,7 +33,6 @@ use SebastianBergmann\Template\Template;
use SebastianBergmann\Type\ReflectionMapper;
use SebastianBergmann\Type\Type;
use SebastianBergmann\Type\UnknownType;
use SebastianBergmann\Type\VoidType;
/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
@@ -134,7 +139,7 @@ final class MockMethod
$modifier,
self::getMethodParametersForDeclaration($method),
self::getMethodParametersForCall($method),
(new ReflectionMapper)->fromMethodReturnType($method),
(new ReflectionMapper)->fromReturnType($method),
$reference,
$callOriginalMethod,
$method->isStatic(),
@@ -186,9 +191,9 @@ final class MockMethod
{
if ($this->static) {
$templateFile = 'mocked_static_method.tpl';
} elseif ($this->returnType instanceof VoidType) {
} elseif ($this->returnType->isNever() || $this->returnType->isVoid()) {
$templateFile = sprintf(
'%s_method_void.tpl',
'%s_method_never_or_void.tpl',
$this->callOriginalMethod ? 'proxied' : 'mocked'
);
} else {
@@ -304,7 +309,7 @@ final class MockMethod
}
if ($type !== null) {
if ($typeName !== 'mixed' && $parameter->allowsNull() && !$type instanceof ReflectionUnionType) {
if ($typeName !== 'mixed' && $parameter->allowsNull() && !$type instanceof ReflectionIntersectionType && !$type instanceof ReflectionUnionType) {
$nullable = '?';
}
@@ -317,6 +322,8 @@ final class MockMethod
$type,
$method->getDeclaringClass()->getName()
);
} elseif ($type instanceof ReflectionIntersectionType) {
$typeDeclaration = self::intersectionTypeAsString($type);
}
}
@@ -369,7 +376,25 @@ final class MockMethod
private static function exportDefaultValue(ReflectionParameter $parameter): string
{
try {
return (string) var_export($parameter->getDefaultValue(), true);
$defaultValue = $parameter->getDefaultValue();
if (!is_object($defaultValue)) {
return (string) var_export($defaultValue, true);
}
$parameterAsString = $parameter->__toString();
return (string) explode(
' = ',
substr(
substr(
$parameterAsString,
strpos($parameterAsString, '<optional> ') + strlen('<optional> ')
),
0,
-2
)
)[1];
// @codeCoverageIgnoreStart
} catch (\ReflectionException $e) {
throw new ReflectionException(
@@ -395,4 +420,15 @@ final class MockMethod
return implode('|', $types) . ' ';
}
private static function intersectionTypeAsString(ReflectionIntersectionType $intersection): string
{
$types = [];
foreach ($intersection->getTypes() as $type) {
$types[] = $type;
}
return implode('&', $types) . ' ';
}
}

View File

@@ -41,7 +41,7 @@ final class Version
}
if (self::$version === '') {
self::$version = (new VersionId('9.5.18', dirname(__DIR__, 2)))->getVersion();
self::$version = (new VersionId('9.5.19', dirname(__DIR__, 2)))->getVersion();
}
return self::$version;

View File

@@ -2,6 +2,31 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [4.0.0] - 2022-MM-DD
### Removed
* This component is no longer supported on PHP 7.3 and PHP 7.4
## [3.0.0] - 2022-03-15
### Added
* Support for intersection types introduced in PHP 8.1
* Support for the `never` return type introduced in PHP 8.1
* Added `Type::isCallable()`, `Type::isGenericObject()`, `Type::isIterable()`, `Type::isMixed()`, `Type::isNever()`, `Type::isNull()`, `Type::isObject()`, `Type::isSimple()`, `Type::isStatic()`, `Type::isUnion()`, `Type::isUnknown()`, and `Type::isVoid()`
### Changed
* Renamed `ReflectionMapper::fromMethodReturnType(ReflectionMethod $method)` to `ReflectionMapper::fromReturnType(ReflectionFunctionAbstract $functionOrMethod)`
### Removed
* Removed `Type::getReturnTypeDeclaration()` (use `Type::asString()` instead and prefix its result with `': '`)
* Removed `TypeName::getNamespaceName()` (use `TypeName::namespaceName()` instead)
* Removed `TypeName::getSimpleName()` (use `TypeName::simpleName()` instead)
* Removed `TypeName::getQualifiedName()` (use `TypeName::qualifiedName()` instead)
## [2.3.4] - 2021-06-15
* Fixed regression introduced in 2.3.3
@@ -105,6 +130,8 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release based on [code contributed by Michel Hartmann to PHPUnit](https://github.com/sebastianbergmann/phpunit/pull/3673)
[4.0.0]: https://github.com/sebastianbergmann/type/compare/3.0...master
[3.0.0]: https://github.com/sebastianbergmann/type/compare/2.3.4...3.0.0
[2.3.4]: https://github.com/sebastianbergmann/type/compare/ca39369c41313ed12c071ed38ecda8fcdb248859...2.3.4
[2.3.3]: https://github.com/sebastianbergmann/type/compare/2.3.2...ca39369c41313ed12c071ed38ecda8fcdb248859
[2.3.2]: https://github.com/sebastianbergmann/type/compare/2.3.1...2.3.2

View File

@@ -1,6 +1,6 @@
sebastian/type
Copyright (c) 2019-2020, Sebastian Bergmann <sebastian@phpunit.de>.
Copyright (c) 2019-2022, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@@ -19,7 +19,7 @@
"php": ">=7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.3"
"phpunit/phpunit": "^9.5"
},
"config": {
"platform": {
@@ -38,12 +38,13 @@
"tests/_fixture"
],
"files": [
"tests/_fixture/callback_function.php"
"tests/_fixture/callback_function.php",
"tests/_fixture/functions_that_declare_return_types.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
"dev-master": "3.0-dev"
}
}
}

View File

@@ -10,7 +10,8 @@
namespace SebastianBergmann\Type;
use function assert;
use function sprintf;
use ReflectionFunctionAbstract;
use ReflectionIntersectionType;
use ReflectionMethod;
use ReflectionNamedType;
use ReflectionType;
@@ -18,27 +19,27 @@ use ReflectionUnionType;
final class ReflectionMapper
{
public function fromMethodReturnType(ReflectionMethod $method): Type
public function fromReturnType(ReflectionFunctionAbstract $functionOrMethod): Type
{
if (!$this->reflectionMethodHasReturnType($method)) {
if (!$this->hasReturnType($functionOrMethod)) {
return new UnknownType;
}
$returnType = $this->reflectionMethodGetReturnType($method);
$returnType = $this->returnType($functionOrMethod);
assert($returnType instanceof ReflectionNamedType || $returnType instanceof ReflectionUnionType);
assert($returnType instanceof ReflectionNamedType || $returnType instanceof ReflectionUnionType || $returnType instanceof ReflectionIntersectionType);
if ($returnType instanceof ReflectionNamedType) {
if ($returnType->getName() === 'self') {
if ($functionOrMethod instanceof ReflectionMethod && $returnType->getName() === 'self') {
return ObjectType::fromName(
$method->getDeclaringClass()->getName(),
$functionOrMethod->getDeclaringClass()->getName(),
$returnType->allowsNull()
);
}
if ($returnType->getName() === 'static') {
if ($functionOrMethod instanceof ReflectionMethod && $returnType->getName() === 'static') {
return new StaticType(
TypeName::fromReflection($method->getDeclaringClass()),
TypeName::fromReflection($functionOrMethod->getDeclaringClass()),
$returnType->allowsNull()
);
}
@@ -47,24 +48,9 @@ final class ReflectionMapper
return new MixedType;
}
if ($returnType->getName() === 'parent') {
$parentClass = $method->getDeclaringClass()->getParentClass();
// @codeCoverageIgnoreStart
if ($parentClass === false) {
throw new RuntimeException(
sprintf(
'%s::%s() has a "parent" return type declaration but %s does not have a parent class',
$method->getDeclaringClass()->getName(),
$method->getName(),
$method->getDeclaringClass()->getName()
)
);
}
// @codeCoverageIgnoreEnd
if ($functionOrMethod instanceof ReflectionMethod && $returnType->getName() === 'parent') {
return ObjectType::fromName(
$parentClass->getName(),
$functionOrMethod->getDeclaringClass()->getParentClass()->getName(),
$returnType->allowsNull()
);
}
@@ -75,16 +61,14 @@ final class ReflectionMapper
);
}
assert($returnType instanceof ReflectionUnionType);
assert($returnType instanceof ReflectionUnionType || $returnType instanceof ReflectionIntersectionType);
$types = [];
foreach ($returnType->getTypes() as $type) {
assert($type instanceof ReflectionNamedType);
if ($type->getName() === 'self') {
if ($functionOrMethod instanceof ReflectionMethod && $type->getName() === 'self') {
$types[] = ObjectType::fromName(
$method->getDeclaringClass()->getName(),
$functionOrMethod->getDeclaringClass()->getName(),
false
);
} else {
@@ -92,32 +76,36 @@ final class ReflectionMapper
}
}
if ($returnType instanceof ReflectionUnionType) {
return new UnionType(...$types);
}
private function reflectionMethodHasReturnType(ReflectionMethod $method): bool
return new IntersectionType(...$types);
}
private function hasReturnType(ReflectionFunctionAbstract $functionOrMethod): bool
{
if ($method->hasReturnType()) {
if ($functionOrMethod->hasReturnType()) {
return true;
}
if (!method_exists($method, 'hasTentativeReturnType')) {
if (!method_exists($functionOrMethod, 'hasTentativeReturnType')) {
return false;
}
return $method->hasTentativeReturnType();
return $functionOrMethod->hasTentativeReturnType();
}
private function reflectionMethodGetReturnType(ReflectionMethod $method): ?ReflectionType
private function returnType(ReflectionFunctionAbstract $functionOrMethod): ?ReflectionType
{
if ($method->hasReturnType()) {
return $method->getReturnType();
if ($functionOrMethod->hasReturnType()) {
return $functionOrMethod->getReturnType();
}
if (!method_exists($method, 'getTentativeReturnType')) {
if (!method_exists($functionOrMethod, 'getTentativeReturnType')) {
return null;
}
return $method->getTentativeReturnType();
return $functionOrMethod->getTentativeReturnType();
}
}

View File

@@ -76,36 +76,6 @@ final class TypeName
: $this->namespaceName . '\\' . $this->simpleName;
}
/**
* @deprecated Use namespaceName() instead
*
* @codeCoverageIgnore
*/
public function getNamespaceName(): ?string
{
return $this->namespaceName();
}
/**
* @deprecated Use simpleName() instead
*
* @codeCoverageIgnore
*/
public function getSimpleName(): string
{
return $this->simpleName();
}
/**
* @deprecated Use qualifiedName() instead
*
* @codeCoverageIgnore
*/
public function getQualifiedName(): string
{
return $this->qualifiedName();
}
public function isNamespaced(): bool
{
return $this->namespaceName !== null;

View File

@@ -1,14 +0,0 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type;
final class LogicException extends \LogicException implements Exception
{
}

View File

@@ -17,7 +17,6 @@ use function function_exists;
use function is_array;
use function is_object;
use function is_string;
use function strpos;
use Closure;
use ReflectionClass;
use ReflectionException;
@@ -85,6 +84,11 @@ final class CallableType extends Type
return $this->allowsNull;
}
public function isCallable(): bool
{
return true;
}
private function isClosure(ObjectType $type): bool
{
return !$type->className()->isNamespaced() && $type->className()->simpleName() === Closure::class;

View File

@@ -32,15 +32,8 @@ final class FalseType extends Type
return false;
}
/**
* @deprecated
*
* @codeCoverageIgnore
*
* @throws LogicException
*/
public function getReturnTypeDeclaration(): string
public function isFalse(): bool
{
throw new LogicException;
return true;
}
}

View File

@@ -43,4 +43,9 @@ final class GenericObjectType extends Type
{
return $this->allowsNull;
}
public function isGenericObject(): bool
{
return true;
}
}

View File

@@ -0,0 +1,115 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type;
use function array_unique;
use function assert;
use function count;
use function implode;
use function sort;
final class IntersectionType extends Type
{
/**
* @psalm-var list<Type>
*/
private $types;
/**
* @throws RuntimeException
*/
public function __construct(Type ...$types)
{
$this->ensureMinimumOfTwoTypes(...$types);
$this->ensureOnlyValidTypes(...$types);
$this->ensureNoDuplicateTypes(...$types);
$this->types = $types;
}
public function isAssignable(Type $other): bool
{
return $other->isObject();
}
public function asString(): string
{
return $this->name();
}
public function name(): string
{
$types = [];
foreach ($this->types as $type) {
$types[] = $type->name();
}
sort($types);
return implode('&', $types);
}
public function allowsNull(): bool
{
return false;
}
public function isIntersection(): bool
{
return true;
}
/**
* @throws RuntimeException
*/
private function ensureMinimumOfTwoTypes(Type ...$types): void
{
if (count($types) < 2) {
throw new RuntimeException(
'An intersection type must be composed of at least two types'
);
}
}
/**
* @throws RuntimeException
*/
private function ensureOnlyValidTypes(Type ...$types): void
{
foreach ($types as $type) {
if (!$type->isObject()) {
throw new RuntimeException(
'An intersection type can only be composed of interfaces and classes'
);
}
}
}
/**
* @throws RuntimeException
*/
private function ensureNoDuplicateTypes(Type ...$types): void
{
$names = [];
foreach ($types as $type) {
assert($type instanceof ObjectType);
$names[] = $type->className()->qualifiedName();
}
if (count(array_unique($names)) < count($names)) {
throw new RuntimeException(
'An intersection type must not contain duplicate types'
);
}
}
}

View File

@@ -73,4 +73,9 @@ final class IterableType extends Type
{
return $this->allowsNull;
}
public function isIterable(): bool
{
return true;
}
}

View File

@@ -30,4 +30,9 @@ final class MixedType extends Type
{
return true;
}
public function isMixed(): bool
{
return true;
}
}

View File

@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type;
final class NeverType extends Type
{
public function isAssignable(Type $other): bool
{
return $other instanceof self;
}
public function name(): string
{
return 'never';
}
public function allowsNull(): bool
{
return false;
}
public function isNever(): bool
{
return true;
}
}

View File

@@ -26,18 +26,13 @@ final class NullType extends Type
return 'null';
}
/**
* @deprecated
*
* @codeCoverageIgnore
*/
public function getReturnTypeDeclaration(): string
{
return '';
}
public function allowsNull(): bool
{
return true;
}
public function isNull(): bool
{
return true;
}
}

View File

@@ -63,4 +63,9 @@ final class ObjectType extends Type
{
return $this->className;
}
public function isObject(): bool
{
return true;
}
}

View File

@@ -67,6 +67,11 @@ final class SimpleType extends Type
return $this->value;
}
public function isSimple(): bool
{
return true;
}
private function normalize(string $name): string
{
$name = strtolower($name);

View File

@@ -57,4 +57,9 @@ final class StaticType extends Type
{
return $this->allowsNull;
}
public function isStatic(): bool
{
return true;
}
}

View File

@@ -9,9 +9,11 @@
*/
namespace SebastianBergmann\Type;
use const PHP_VERSION;
use function get_class;
use function gettype;
use function strtolower;
use function version_compare;
abstract class Type
{
@@ -38,6 +40,10 @@ abstract class Type
public static function fromName(string $typeName, bool $allowsNull): self
{
if (version_compare(PHP_VERSION, '8.1.0-dev', '>=') && strtolower($typeName) === 'never') {
return new NeverType;
}
switch (strtolower($typeName)) {
case 'callable':
return new CallableType($allowsNull);
@@ -83,17 +89,77 @@ abstract class Type
return ($this->allowsNull() ? '?' : '') . $this->name();
}
/**
* @deprecated
*
* @codeCoverageIgnore
*/
public function getReturnTypeDeclaration(): string
public function isCallable(): bool
{
return ': ' . $this->asString();
return false;
}
abstract public function isAssignable(Type $other): bool;
public function isFalse(): bool
{
return false;
}
public function isGenericObject(): bool
{
return false;
}
public function isIntersection(): bool
{
return false;
}
public function isIterable(): bool
{
return false;
}
public function isMixed(): bool
{
return false;
}
public function isNever(): bool
{
return false;
}
public function isNull(): bool
{
return false;
}
public function isObject(): bool
{
return false;
}
public function isSimple(): bool
{
return false;
}
public function isStatic(): bool
{
return false;
}
public function isUnion(): bool
{
return false;
}
public function isUnknown(): bool
{
return false;
}
public function isVoid(): bool
{
return false;
}
abstract public function isAssignable(self $other): bool;
abstract public function name(): string;

View File

@@ -47,16 +47,6 @@ final class UnionType extends Type
return $this->name();
}
/**
* @deprecated
*
* @codeCoverageIgnore
*/
public function getReturnTypeDeclaration(): string
{
return ': ' . $this->name();
}
public function name(): string
{
$types = [];
@@ -81,6 +71,11 @@ final class UnionType extends Type
return false;
}
public function isUnion(): bool
{
return true;
}
/**
* @throws RuntimeException
*/

View File

@@ -26,18 +26,13 @@ final class UnknownType extends Type
return '';
}
/**
* @deprecated
*
* @codeCoverageIgnore
*/
public function getReturnTypeDeclaration(): string
{
return '';
}
public function allowsNull(): bool
{
return true;
}
public function isUnknown(): bool
{
return true;
}
}

View File

@@ -25,4 +25,9 @@ final class VoidType extends Type
{
return false;
}
public function isVoid(): bool
{
return true;
}
}