Skip to content

Commit

Permalink
Merge branch '3.4' into 4.3
Browse files Browse the repository at this point in the history
* 3.4:
  [ProxyManagerBridge] Polyfill for unmaintained version
  SCA: dropped unused mocks, duplicate import and a function alias usage
  [Config] fix test
  Improve fa (persian) translation
  • Loading branch information
nicolas-grekas committed Aug 7, 2019
2 parents 465da03 + 4123465 commit 3cd7726
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 32 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
"Symfony\\Component\\": "src/Symfony/Component/"
},
"classmap": [
"src/Symfony/Component/Intl/Resources/stubs"
"src/Symfony/Component/Intl/Resources/stubs",
"src/Symfony/Bridge/ProxyManager/Legacy/ProxiedMethodReturnExpression.php"
],
"exclude-from-classmap": [
"**/Tests/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function getProxyCode(Definition $definition)
);
}

if (version_compare(self::getProxyManagerVersion(), '2.5', '<')) {
$code = str_replace(' \Closure::bind(function ', ' \Closure::bind(static function ', $code);
}

return $code;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ProxyManager\Generator\Util;

use Composer\Autoload\ClassLoader;
use ProxyManager\Version;

if (class_exists(Version::class) && version_compare(\defined(Version::class.'::VERSION') ? Version::VERSION : Version::getVersion(), '2.5', '<')) {
/**
* Utility class to generate return expressions in method, given a method signature.
*
* This is required since return expressions may be forbidden by the method signature (void).
*
* @author Marco Pivetta <ocramius@gmail.com>
* @license MIT
*
* @see https://github.com/Ocramius/ProxyManager
*/
final class ProxiedMethodReturnExpression
{
public static function generate(string $returnedValueExpression, ?\ReflectionMethod $originalMethod): string
{
$originalReturnType = null === $originalMethod ? null : $originalMethod->getReturnType();

$originalReturnTypeName = null === $originalReturnType ? null : $originalReturnType->getName();

if ('void' === $originalReturnTypeName) {
return $returnedValueExpression.";\nreturn;";
}

return 'return '.$returnedValueExpression.';';
}
}
} else {
// Fallback to the original class by unregistering this file from composer class loader
$getComposerClassLoader = static function ($functionLoader) use (&$getComposerClassLoader) {
if (\is_array($functionLoader)) {
$functionLoader = $functionLoader[0];
}
if (!\is_object($functionLoader)) {
return;
}
if ($functionLoader instanceof ClassLoader) {
return $functionLoader;
}
if ($functionLoader instanceof \Symfony\Component\Debug\DebugClassLoader) {
return $getComposerClassLoader($functionLoader->getClassLoader());
}
if ($functionLoader instanceof \Symfony\Component\ErrorHandler\DebugClassLoader) {
return $getComposerClassLoader($functionLoader->getClassLoader());
}
};

$classLoader = null;
$functions = spl_autoload_functions();
while (null === $classLoader && $functions) {
$classLoader = $getComposerClassLoader(array_shift($functions));
}
$getComposerClassLoader = null;

if (null !== $classLoader) {
$classLoader->addClassMap([ProxiedMethodReturnExpression::class => null]);
$classLoader->loadClass(ProxiedMethodReturnExpression::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\PhpDumper;

use PHPUnit\Framework\TestCase;
use ProxyManager\Version;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
Expand Down Expand Up @@ -59,6 +60,20 @@ public function testGetProxyCode()
);
}

public function testStaticBinding()
{
if (!class_exists(Version::class) || version_compare(\defined(Version::class.'::VERSION') ? Version::VERSION : Version::getVersion(), '2.1', '<')) {
$this->markTestSkipped('ProxyManager prior to version 2.1 does not support static binding');
}

$definition = new Definition(__CLASS__);
$definition->setLazy(true);

$code = $this->dumper->getProxyCode($definition);

$this->assertStringContainsString('\Closure::bind(static function (\PHPUnit\Framework\TestCase $instance) {', $code);
}

public function testDeterministicProxyCode()
{
$definition = new Definition(__CLASS__);
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/ProxyManager/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"autoload": {
"psr-4": { "Symfony\\Bridge\\ProxyManager\\": "" },
"classmap": [ "Legacy/ProxiedMethodReturnExpression.php" ],
"exclude-from-classmap": [
"/Tests/"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,22 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\FloatNodeDefinition;
use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition;
use Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition as NumericNodeDefinition;

class NumericNodeDefinitionTest extends TestCase
{
public function testIncoherentMinAssertion()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('You cannot define a min(4) as you already have a max(3)');
$def = new NumericNodeDefinition('foo');
$def = new IntegerNodeDefinition('foo');
$def->max(3)->min(4);
}

public function testIncoherentMaxAssertion()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('You cannot define a max(2) as you already have a min(3)');
$node = new NumericNodeDefinition('foo');
$node = new IntegerNodeDefinition('foo');
$node->min(3)->max(2);
}

Expand Down Expand Up @@ -84,7 +83,7 @@ public function testCannotBeEmptyThrowsAnException()
{
$this->expectException('Symfony\Component\Config\Definition\Exception\InvalidDefinitionException');
$this->expectExceptionMessage('->cannotBeEmpty() is not applicable to NumericNodeDefinition.');
$def = new NumericNodeDefinition('foo');
$def = new IntegerNodeDefinition('foo');
$def->cannotBeEmpty();
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Ldap/Tests/LdapTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected function getLdapConfig()
$this->markTestSkipped('No server is listening on LDAP_HOST:LDAP_PORT');
}

ldap_close($h);
ldap_unbind($h);

return [
'host' => getenv('LDAP_HOST'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,43 @@
<body>
<trans-unit id="1">
<source>An authentication exception occurred.</source>
<target>خطایی هنگام تعیین اعتبار اتفاق افتاد.</target>
<target>خطایی هنگام احراز هویت رخ داده است.</target>
</trans-unit>
<trans-unit id="2">
<source>Authentication credentials could not be found.</source>
<target>شرایط تعیین اعتبار پیدا نشد.</target>
<target>شرایط احراز هویت یافت نشد.</target>
</trans-unit>
<trans-unit id="3">
<source>Authentication request could not be processed due to a system problem.</source>
<target>درخواست تعیین اعتبار به دلیل مشکل سیستم قابل بررسی نیست.</target>
<target>درخواست احراز هویت به دلیل وجود مشکل در سیستم قابل پردازش نمی باشد.</target>
</trans-unit>
<trans-unit id="4">
<source>Invalid credentials.</source>
<target>شرایط نامعتبر.</target>
<target>احراز هویت نامعتبر می باشد.</target>
</trans-unit>
<trans-unit id="5">
<source>Cookie has already been used by someone else.</source>
<target>کوکی قبلا برای شخص دیگری استفاده شده است.</target>
<target>Cookie قبلا توسط شخص دیگری استفاده گردیده است.</target>
</trans-unit>
<trans-unit id="6">
<source>Not privileged to request the resource.</source>
<target>دسترسی لازم برای درخواست این منبع را ندارید.</target>
<target>دسترسی لازم برای درخواست از این منبع را دارا نمی باشید.</target>
</trans-unit>
<trans-unit id="7">
<source>Invalid CSRF token.</source>
<target>توکن CSRF معتبر نیست.</target>
<target>توکن CSRF معتبر نمی باشد.</target>
</trans-unit>
<trans-unit id="8">
<source>Digest nonce has expired.</source>
<target>Digest nonce منقضی گردیده است.</target>
</trans-unit>
<trans-unit id="9">
<source>No authentication provider found to support the authentication token.</source>
<target>هیچ ارایه کننده تعیین اعتباری برای ساپورت توکن تعیین اعتبار پیدا نشد.</target>
<target>هیچ ارایه دهنده احراز هویتی برای پشتیبانی از توکن احراز هویت پیدا نشد.</target>
</trans-unit>
<trans-unit id="10">
<source>No session available, it either timed out or cookies are not enabled.</source>
<target>جلسه‌ای در دسترس نیست. این میتواند یا به دلیل پایان یافتن زمان باشد یا اینکه کوکی ها فعال نیستند.</target>
<target>هیچ جلسه‌ای در دسترس نمی باشد. این میتواند به دلیل پایان یافتن زمان و یا فعال نبودن کوکی ها باشد.</target>
</trans-unit>
<trans-unit id="11">
<source>No token could be found.</source>
Expand All @@ -48,19 +52,19 @@
</trans-unit>
<trans-unit id="13">
<source>Account has expired.</source>
<target>حساب کاربری منقضی شده است.</target>
<target>حساب کاربری منقضی گردیده است.</target>
</trans-unit>
<trans-unit id="14">
<source>Credentials have expired.</source>
<target>پارامترهای تعیین اعتبار منقضی شده‌اند.</target>
<target>مجوزهای احراز هویت منقضی گردیده‌اند.</target>
</trans-unit>
<trans-unit id="15">
<source>Account is disabled.</source>
<target>حساب کاربری غیرفعال است.</target>
<target>حساب کاربری غیرفعال می باشد.</target>
</trans-unit>
<trans-unit id="16">
<source>Account is locked.</source>
<target>حساب کاربری قفل شده است.</target>
<target>حساب کاربری قفل گردیده است.</target>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ public function testHandleAuthenticationFailure()
*/
public function testHandleAuthenticationClearsToken($tokenClass, $tokenProviderKey, $actualProviderKey)
{
$token = $this->getMockBuilder($tokenClass)
->disableOriginalConstructor()
->getMock();
$token->expects($this->any())
->method('getProviderKey')
->willReturn($tokenProviderKey);

$this->tokenStorage->expects($this->never())
->method('setToken')
->with(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public function testHandleWhenAuthenticationFails()
'PHP_AUTH_PW' => 'ThePassword',
]);

$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();

$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
$tokenStorage
->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public function testLoginSuccessIsNotProcessedWhenTokenDoesNotContainUserInterfa
$service = $this->getService(null, ['name' => 'foo', 'always_remember_me' => true, 'path' => null, 'domain' => null]);
$request = new Request();
$response = new Response();
$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
$token
->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ public function testProcessMissingAlias()
{
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
$this->expectExceptionMessage('The alias for the tag "translation.extractor" of service "foo.id" must be set.');
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->disableOriginalConstructor()->getMock();
$container = new ContainerBuilder();
$container->register('translation.extractor');
$container->register('foo.id')
->addTag('translation.extractor', []);

$definition->expects($this->never())->method('addMethodCall');

$translationDumperPass = new TranslationExtractorPass();
$translationDumperPass->process($container);
}
Expand Down

0 comments on commit 3cd7726

Please sign in to comment.