[更新]修改粉丝同步及ComposerUpdate

This commit is contained in:
Anyon 2019-08-27 11:41:27 +08:00
parent 4e4d3c6917
commit 83da4c6bc0
8 changed files with 141 additions and 272 deletions

View File

@ -54,29 +54,28 @@ class Fans extends Command
/** /**
* 同步微信粉丝列表 * 同步微信粉丝列表
* @param string $next * @param string $next
* @param integer $index * @param integer $done
* @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException * @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
protected function _list($next = '', $index = 0) protected function _list($next = '', $done = 0)
{ {
$appid = WechatService::getAppid(); $appid = WechatService::getAppid();
$wechat = WechatService::WeChatUser(); $wechat = WechatService::WeChatUser();
$this->output->comment('preparing synchronize fans list ...'); $this->output->comment('preparing synchronize fans list ...');
while (true) if (is_array($result = $wechat->getUserList($next)) && !empty($result['data']['openid'])) { while ($next !== null && is_array($result = $wechat->getUserList($next)) && !empty($result['data']['openid'])) {
foreach (array_chunk($result['data']['openid'], 100) as $chunk) { foreach (array_chunk($result['data']['openid'], 100) as $chunk) {
if (is_array($list = $wechat->getBatchUserInfo($chunk)) && !empty($list['user_info_list'])) { if (is_array($list = $wechat->getBatchUserInfo($chunk)) && !empty($list['user_info_list'])) {
foreach ($list['user_info_list'] as $user) { foreach ($list['user_info_list'] as $user) {
$indexString = str_pad(++$index, strlen($result['total']), '0', STR_PAD_LEFT); $indexString = str_pad(++$done, strlen($result['total']), '0', STR_PAD_LEFT);
$this->output->writeln("({$indexString}/{$result['total']}) updating wechat user {$user['openid']} {$user['nickname']}"); $this->output->writeln("({$indexString}/{$result['total']}) updating wechat user {$user['openid']} {$user['nickname']}");
\app\wechat\service\FansService::set($user, $appid); \app\wechat\service\FansService::set($user, $appid);
} }
} }
} }
if (in_array($result['next_openid'], $result['data']['openid'])) break; $next = $result['total'] > $done ? $result['next_openid'] : null;
else $next = $result['next_openid'];
} }
$this->output->comment('synchronized fans list successful.'); $this->output->comment('synchronized fans list successful.');
} }
@ -84,27 +83,25 @@ class Fans extends Command
/** /**
* 同步粉丝黑名单列表 * 同步粉丝黑名单列表
* @param string $next * @param string $next
* @param integer $index * @param integer $done
* @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException * @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\Exception * @throws \think\Exception
* @throws \think\exception\PDOException * @throws \think\exception\PDOException
*/ */
public function _black($next = '', $index = 0) public function _black($next = '', $done = 0)
{ {
$wechat = WechatService::WeChatUser(); $wechat = WechatService::WeChatUser();
$this->output->comment('prepare synchronize fans black ...'); $this->output->comment('prepare synchronize fans black ...');
while (true) if (is_array($result = $wechat->getBlackList($next)) && !empty($result['data']['openid'])) { while ($next !== null && is_array($result = $wechat->getBlackList($next)) && !empty($result['data']['openid'])) {
foreach (array_chunk($result['data']['openid'], 100) as $chunk) { foreach (array_chunk($result['data']['openid'], 100) as $chunk) {
foreach ($chunk as $openid) { foreach ($chunk as $openid) {
$indexString = str_pad(++$index, strlen($result['total']), '0', STR_PAD_LEFT); $indexString = str_pad(++$done, strlen($result['total']), '0', STR_PAD_LEFT);
$this->output->writeln("({$indexString}/{$result['total']}) updating wechat black {$openid}"); $this->output->writeln("({$indexString}/{$result['total']}) updating wechat black {$openid}");
} }
$where = [['is_black', 'eq', '0'], ['openid', 'in', $chunk]]; Db::name('WechatFans')->where(['is_black' => '0'])->whereIn('openid', $chunk)->update(['is_black' => '1']);
Db::name('WechatFans')->where($where)->update(['is_black' => '1']);
} }
if (in_array($result['next_openid'], $result['data']['openid'])) break; $next = $result['total'] > $done ? $result['next_openid'] : null;
else $next = $result['next_openid'];
} }
$this->output->comment('synchronized fans black successful.'); $this->output->comment('synchronized fans black successful.');
} }

View File

@ -48,24 +48,27 @@ class WechatQueue extends Queue
{ {
$appid = WechatService::getAppid(); $appid = WechatService::getAppid();
$wechat = WechatService::WeChatUser(); $wechat = WechatService::WeChatUser();
$next = ''; // 获取远程粉丝 // 获取远程粉丝
list($next, $done) = ['', 0];
$output->writeln('Start synchronizing fans from the Wechat server'); $output->writeln('Start synchronizing fans from the Wechat server');
while (is_array($result = $wechat->getUserList($next)) && !empty($result['data']['openid'])) { while ($next !== null && is_array($result = $wechat->getUserList($next)) && !empty($result['data']['openid'])) {
foreach (array_chunk($result['data']['openid'], 100) as $chunk) $done += $result['count'];
if (is_array($list = $wechat->getBatchUserInfo($chunk)) && !empty($list['user_info_list']))
foreach ($list['user_info_list'] as $user) FansService::set($user, $appid);
if (in_array($result['next_openid'], $result['data']['openid'])) break;
$next = $result['next_openid'];
}
$next = ''; // 同步粉丝黑名单
$output->writeln('Start synchronizing black from the Wechat server');
while (is_array($result = $wechat->getBlackList($next)) && !empty($result['data']['openid'])) {
foreach (array_chunk($result['data']['openid'], 100) as $chunk) { foreach (array_chunk($result['data']['openid'], 100) as $chunk) {
$where = [['is_black', 'eq', '0'], ['openid', 'in', $chunk]]; if (is_array($list = $wechat->getBatchUserInfo($chunk)) && !empty($list['user_info_list'])) {
Db::name('WechatFans')->where($where)->update(['is_black' => '1']); foreach ($list['user_info_list'] as $user) FansService::set($user, $appid);
}
} }
if (in_array($result['next_openid'], $result['data']['openid'])) break; $next = $result['total'] > $done ? $result['next_openid'] : null;
$next = $result['next_openid']; }
// 同步粉丝黑名单
list($next, $done) = ['', 0];
$output->writeln('Start synchronizing black from the Wechat server');
while ($next !== null && is_array($result = $wechat->getBlackList($next)) && !empty($result['data']['openid'])) {
$done += $result['count'];
foreach (array_chunk($result['data']['openid'], 100) as $chunk) {
Db::name('WechatFans')->where(['is_black' => '0'])->whereIn('openid', $chunk)->update(['is_black' => '1']);
}
$next = $result['total'] > $done ? $result['next_openid'] : null;
} }
// 同步粉丝标签列表 // 同步粉丝标签列表
$output->writeln('Start synchronizing tags from the Wechat server'); $output->writeln('Start synchronizing tags from the Wechat server');

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967::getLoader(); return ComposerAutoloaderInit51aa80bd984c4321321fc668067c748f::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967 class ComposerAutoloaderInit51aa80bd984c4321321fc668067c748f
{ {
private static $loader; private static $loader;
@ -19,15 +19,15 @@ class ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit51aa80bd984c4321321fc668067c748f', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit51aa80bd984c4321321fc668067c748f', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) { if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php'; require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInita2c8b4b934204259b6591513a0ea2967::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInit51aa80bd984c4321321fc668067c748f::getInitializer($loader));
} else { } else {
$map = require __DIR__ . '/autoload_namespaces.php'; $map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) { foreach ($map as $namespace => $path) {
@ -48,19 +48,19 @@ class ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967
$loader->register(true); $loader->register(true);
if ($useStaticLoader) { if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInita2c8b4b934204259b6591513a0ea2967::$files; $includeFiles = Composer\Autoload\ComposerStaticInit51aa80bd984c4321321fc668067c748f::$files;
} else { } else {
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
} }
foreach ($includeFiles as $fileIdentifier => $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequirea2c8b4b934204259b6591513a0ea2967($fileIdentifier, $file); composerRequire51aa80bd984c4321321fc668067c748f($fileIdentifier, $file);
} }
return $loader; return $loader;
} }
} }
function composerRequirea2c8b4b934204259b6591513a0ea2967($fileIdentifier, $file) function composerRequire51aa80bd984c4321321fc668067c748f($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file; require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInita2c8b4b934204259b6591513a0ea2967 class ComposerStaticInit51aa80bd984c4321321fc668067c748f
{ {
public static $files = array ( public static $files = array (
'841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php', '841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php',
@ -314,9 +314,9 @@ class ComposerStaticInita2c8b4b934204259b6591513a0ea2967
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInita2c8b4b934204259b6591513a0ea2967::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit51aa80bd984c4321321fc668067c748f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita2c8b4b934204259b6591513a0ea2967::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit51aa80bd984c4321321fc668067c748f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita2c8b4b934204259b6591513a0ea2967::$classMap; $loader->classMap = ComposerStaticInit51aa80bd984c4321321fc668067c748f::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

View File

@ -177,17 +177,17 @@
}, },
{ {
"name": "symfony/options-resolver", "name": "symfony/options-resolver",
"version": "v3.4.30", "version": "v3.4.31",
"version_normalized": "3.4.30.0", "version_normalized": "3.4.31.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/options-resolver.git", "url": "https://github.com/symfony/options-resolver.git",
"reference": "ed3b397f9c07c8ca388b2a1ef744403b4d4ecc44" "reference": "a7c00586a9ef70acf0f17085e51c399bf9620e03"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/options-resolver/zipball/ed3b397f9c07c8ca388b2a1ef744403b4d4ecc44", "url": "https://api.github.com/repos/symfony/options-resolver/zipball/a7c00586a9ef70acf0f17085e51c399bf9620e03",
"reference": "ed3b397f9c07c8ca388b2a1ef744403b4d4ecc44", "reference": "a7c00586a9ef70acf0f17085e51c399bf9620e03",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -199,7 +199,7 @@
"require": { "require": {
"php": "^5.5.9|>=7.0.8" "php": "^5.5.9|>=7.0.8"
}, },
"time": "2019-04-10T16:00:48+00:00", "time": "2019-08-03T21:15:25+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {

View File

@ -36,12 +36,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertNull($debug->getDefault($option)); $this->assertNull($debug->getDefault($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No default value was set for the "foo" option.
*/
public function testGetDefaultThrowsOnNoConfiguredValue() public function testGetDefaultThrowsOnNoConfiguredValue()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException');
$this->expectExceptionMessage('No default value was set for the "foo" option.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo'); $resolver->setDefined($option = 'foo');
@ -49,12 +47,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame('bar', $debug->getDefault($option)); $this->assertSame('bar', $debug->getDefault($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetDefaultThrowsOnNotDefinedOption() public function testGetDefaultThrowsOnNotDefinedOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->expectExceptionMessage('The option "foo" does not exist.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver); $debug = new OptionsResolverIntrospector($resolver);
@ -71,12 +67,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame($closures, $debug->getLazyClosures($option)); $this->assertSame($closures, $debug->getLazyClosures($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No lazy closures were set for the "foo" option.
*/
public function testGetLazyClosuresThrowsOnNoConfiguredValue() public function testGetLazyClosuresThrowsOnNoConfiguredValue()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException');
$this->expectExceptionMessage('No lazy closures were set for the "foo" option.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo'); $resolver->setDefined($option = 'foo');
@ -84,12 +78,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame('bar', $debug->getLazyClosures($option)); $this->assertSame('bar', $debug->getLazyClosures($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetLazyClosuresThrowsOnNotDefinedOption() public function testGetLazyClosuresThrowsOnNotDefinedOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->expectExceptionMessage('The option "foo" does not exist.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver); $debug = new OptionsResolverIntrospector($resolver);
@ -106,12 +98,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame($allowedTypes, $debug->getAllowedTypes($option)); $this->assertSame($allowedTypes, $debug->getAllowedTypes($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No allowed types were set for the "foo" option.
*/
public function testGetAllowedTypesThrowsOnNoConfiguredValue() public function testGetAllowedTypesThrowsOnNoConfiguredValue()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException');
$this->expectExceptionMessage('No allowed types were set for the "foo" option.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo'); $resolver->setDefined($option = 'foo');
@ -119,12 +109,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame('bar', $debug->getAllowedTypes($option)); $this->assertSame('bar', $debug->getAllowedTypes($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetAllowedTypesThrowsOnNotDefinedOption() public function testGetAllowedTypesThrowsOnNotDefinedOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->expectExceptionMessage('The option "foo" does not exist.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver); $debug = new OptionsResolverIntrospector($resolver);
@ -141,12 +129,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame($allowedValues, $debug->getAllowedValues($option)); $this->assertSame($allowedValues, $debug->getAllowedValues($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No allowed values were set for the "foo" option.
*/
public function testGetAllowedValuesThrowsOnNoConfiguredValue() public function testGetAllowedValuesThrowsOnNoConfiguredValue()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException');
$this->expectExceptionMessage('No allowed values were set for the "foo" option.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo'); $resolver->setDefined($option = 'foo');
@ -154,12 +140,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame('bar', $debug->getAllowedValues($option)); $this->assertSame('bar', $debug->getAllowedValues($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetAllowedValuesThrowsOnNotDefinedOption() public function testGetAllowedValuesThrowsOnNotDefinedOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->expectExceptionMessage('The option "foo" does not exist.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver); $debug = new OptionsResolverIntrospector($resolver);
@ -176,12 +160,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame($normalizer, $debug->getNormalizer($option)); $this->assertSame($normalizer, $debug->getNormalizer($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException
* @expectedExceptionMessage No normalizer was set for the "foo" option.
*/
public function testGetNormalizerThrowsOnNoConfiguredValue() public function testGetNormalizerThrowsOnNoConfiguredValue()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException');
$this->expectExceptionMessage('No normalizer was set for the "foo" option.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$resolver->setDefined($option = 'foo'); $resolver->setDefined($option = 'foo');
@ -189,12 +171,10 @@ class OptionsResolverIntrospectorTest extends TestCase
$this->assertSame('bar', $debug->getNormalizer($option)); $this->assertSame('bar', $debug->getNormalizer($option));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist.
*/
public function testGetNormalizerThrowsOnNotDefinedOption() public function testGetNormalizerThrowsOnNotDefinedOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->expectExceptionMessage('The option "foo" does not exist.');
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$debug = new OptionsResolverIntrospector($resolver); $debug = new OptionsResolverIntrospector($resolver);

View File

@ -29,35 +29,29 @@ class OptionsResolverTest extends TestCase
$this->resolver = new OptionsResolver(); $this->resolver = new OptionsResolver();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The option "foo" does not exist. Defined options are: "a", "z".
*/
public function testResolveFailsIfNonExistingOption() public function testResolveFailsIfNonExistingOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->expectExceptionMessage('The option "foo" does not exist. Defined options are: "a", "z".');
$this->resolver->setDefault('z', '1'); $this->resolver->setDefault('z', '1');
$this->resolver->setDefault('a', '2'); $this->resolver->setDefault('a', '2');
$this->resolver->resolve(['foo' => 'bar']); $this->resolver->resolve(['foo' => 'bar']);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
* @expectedExceptionMessage The options "baz", "foo", "ping" do not exist. Defined options are: "a", "z".
*/
public function testResolveFailsIfMultipleNonExistingOptions() public function testResolveFailsIfMultipleNonExistingOptions()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->expectExceptionMessage('The options "baz", "foo", "ping" do not exist. Defined options are: "a", "z".');
$this->resolver->setDefault('z', '1'); $this->resolver->setDefault('z', '1');
$this->resolver->setDefault('a', '2'); $this->resolver->setDefault('a', '2');
$this->resolver->resolve(['ping' => 'pong', 'foo' => 'bar', 'baz' => 'bam']); $this->resolver->resolve(['ping' => 'pong', 'foo' => 'bar', 'baz' => 'bam']);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testResolveFailsFromLazyOption() public function testResolveFailsFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->resolve([]); $options->resolve([]);
}); });
@ -81,11 +75,9 @@ class OptionsResolverTest extends TestCase
], $this->resolver->resolve()); ], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfSetDefaultFromLazyOption() public function testFailIfSetDefaultFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('lazy', function (Options $options) { $this->resolver->setDefault('lazy', function (Options $options) {
$options->setDefault('default', 42); $options->setDefault('default', 42);
}); });
@ -225,11 +217,9 @@ class OptionsResolverTest extends TestCase
$this->assertSame($this->resolver, $this->resolver->setRequired('foo')); $this->assertSame($this->resolver, $this->resolver->setRequired('foo'));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfSetRequiredFromLazyOption() public function testFailIfSetRequiredFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->setRequired('bar'); $options->setRequired('bar');
}); });
@ -237,11 +227,9 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException
*/
public function testResolveFailsIfRequiredOptionMissing() public function testResolveFailsIfRequiredOptionMissing()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\MissingOptionsException');
$this->resolver->setRequired('foo'); $this->resolver->setRequired('foo');
$this->resolver->resolve(); $this->resolver->resolve();
@ -353,11 +341,9 @@ class OptionsResolverTest extends TestCase
$this->assertSame(['bar'], $this->resolver->getMissingOptions()); $this->assertSame(['bar'], $this->resolver->getMissingOptions());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfSetDefinedFromLazyOption() public function testFailIfSetDefinedFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->setDefined('bar'); $options->setDefined('bar');
}); });
@ -450,11 +436,9 @@ class OptionsResolverTest extends TestCase
$this->assertFalse($this->resolver->isDefined('foo')); $this->assertFalse($this->resolver->isDefined('foo'));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testSetAllowedTypesFailsIfUnknownOption() public function testSetAllowedTypesFailsIfUnknownOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->resolver->setAllowedTypes('foo', 'string'); $this->resolver->setAllowedTypes('foo', 'string');
} }
@ -467,11 +451,9 @@ class OptionsResolverTest extends TestCase
$this->assertSame(['foo' => ['bar', 'baz']], $options); $this->assertSame(['foo' => ['bar', 'baz']], $options);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfSetAllowedTypesFromLazyOption() public function testFailIfSetAllowedTypesFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->setAllowedTypes('bar', 'string'); $options->setAllowedTypes('bar', 'string');
}); });
@ -481,36 +463,30 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "DateTime[]".
*/
public function testResolveFailsIfInvalidTypedArray() public function testResolveFailsIfInvalidTypedArray()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "DateTime[]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[]'); $this->resolver->setAllowedTypes('foo', 'int[]');
$this->resolver->resolve(['foo' => [new \DateTime()]]); $this->resolver->resolve(['foo' => [new \DateTime()]]);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value "bar" is expected to be of type "int[]", but is of type "string".
*/
public function testResolveFailsWithNonArray() public function testResolveFailsWithNonArray()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value "bar" is expected to be of type "int[]", but is of type "string".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[]'); $this->resolver->setAllowedTypes('foo', 'int[]');
$this->resolver->resolve(['foo' => 'bar']); $this->resolver->resolve(['foo' => 'bar']);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "stdClass[]".
*/
public function testResolveFailsIfTypedArrayContainsInvalidTypes() public function testResolveFailsIfTypedArrayContainsInvalidTypes()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "stdClass[]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[]'); $this->resolver->setAllowedTypes('foo', 'int[]');
$values = range(1, 5); $values = range(1, 5);
@ -522,12 +498,10 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(['foo' => $values]); $this->resolver->resolve(['foo' => $values]);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "double[][]".
*/
public function testResolveFailsWithCorrectLevelsButWrongScalar() public function testResolveFailsWithCorrectLevelsButWrongScalar()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "double[][]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[][]'); $this->resolver->setAllowedTypes('foo', 'int[][]');
@ -546,12 +520,8 @@ class OptionsResolverTest extends TestCase
$this->resolver->setDefined('option'); $this->resolver->setDefined('option');
$this->resolver->setAllowedTypes('option', $allowedType); $this->resolver->setAllowedTypes('option', $allowedType);
if (method_exists($this, 'expectException')) { $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->expectExceptionMessage($exceptionMessage);
$this->expectExceptionMessage($exceptionMessage);
} else {
$this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException', $exceptionMessage);
}
$this->resolver->resolve(['option' => $actualType]); $this->resolver->resolve(['option' => $actualType]);
} }
@ -578,12 +548,10 @@ class OptionsResolverTest extends TestCase
$this->assertNotEmpty($this->resolver->resolve()); $this->assertNotEmpty($this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string" or "bool", but is of type "integer".
*/
public function testResolveFailsIfInvalidTypeMultiple() public function testResolveFailsIfInvalidTypeMultiple()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value 42 is expected to be of type "string" or "bool", but is of type "integer".');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->setAllowedTypes('foo', ['string', 'bool']); $this->resolver->setAllowedTypes('foo', ['string', 'bool']);
@ -621,30 +589,24 @@ class OptionsResolverTest extends TestCase
$this->assertEquals($data, $result); $this->assertEquals($data, $result);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfNotInstanceOfClass() public function testResolveFailsIfNotInstanceOfClass()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 'bar'); $this->resolver->setDefault('foo', 'bar');
$this->resolver->setAllowedTypes('foo', '\stdClass'); $this->resolver->setAllowedTypes('foo', '\stdClass');
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testAddAllowedTypesFailsIfUnknownOption() public function testAddAllowedTypesFailsIfUnknownOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->resolver->addAllowedTypes('foo', 'string'); $this->resolver->addAllowedTypes('foo', 'string');
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfAddAllowedTypesFromLazyOption() public function testFailIfAddAllowedTypesFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->addAllowedTypes('bar', 'string'); $options->addAllowedTypes('bar', 'string');
}); });
@ -654,11 +616,9 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfInvalidAddedType() public function testResolveFailsIfInvalidAddedType()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->addAllowedTypes('foo', 'string'); $this->resolver->addAllowedTypes('foo', 'string');
@ -673,11 +633,9 @@ class OptionsResolverTest extends TestCase
$this->assertNotEmpty($this->resolver->resolve()); $this->assertNotEmpty($this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfInvalidAddedTypeMultiple() public function testResolveFailsIfInvalidAddedTypeMultiple()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->addAllowedTypes('foo', ['string', 'bool']); $this->resolver->addAllowedTypes('foo', ['string', 'bool']);
@ -714,19 +672,15 @@ class OptionsResolverTest extends TestCase
$this->assertNotEmpty($this->resolver->resolve()); $this->assertNotEmpty($this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testSetAllowedValuesFailsIfUnknownOption() public function testSetAllowedValuesFailsIfUnknownOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->resolver->setAllowedValues('foo', 'bar'); $this->resolver->setAllowedValues('foo', 'bar');
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfSetAllowedValuesFromLazyOption() public function testFailIfSetAllowedValuesFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->setAllowedValues('bar', 'baz'); $options->setAllowedValues('bar', 'baz');
}); });
@ -736,35 +690,29 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar".
*/
public function testResolveFailsIfInvalidValue() public function testResolveFailsIfInvalidValue()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value 42 is invalid. Accepted values are: "bar".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedValues('foo', 'bar'); $this->resolver->setAllowedValues('foo', 'bar');
$this->resolver->resolve(['foo' => 42]); $this->resolver->resolve(['foo' => 42]);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value null is invalid. Accepted values are: "bar".
*/
public function testResolveFailsIfInvalidValueIsNull() public function testResolveFailsIfInvalidValueIsNull()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value null is invalid. Accepted values are: "bar".');
$this->resolver->setDefault('foo', null); $this->resolver->setDefault('foo', null);
$this->resolver->setAllowedValues('foo', 'bar'); $this->resolver->setAllowedValues('foo', 'bar');
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfInvalidValueStrict() public function testResolveFailsIfInvalidValueStrict()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->setAllowedValues('foo', '42'); $this->resolver->setAllowedValues('foo', '42');
@ -787,12 +735,10 @@ class OptionsResolverTest extends TestCase
$this->assertEquals(['foo' => null], $this->resolver->resolve()); $this->assertEquals(['foo' => null], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.
*/
public function testResolveFailsIfInvalidValueMultiple() public function testResolveFailsIfInvalidValueMultiple()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->setAllowedValues('foo', ['bar', false, null]); $this->resolver->setAllowedValues('foo', ['bar', false, null]);
@ -838,11 +784,9 @@ class OptionsResolverTest extends TestCase
$this->assertSame('bar', $passedValue); $this->assertSame('bar', $passedValue);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfAllClosuresReturnFalse() public function testResolveFailsIfAllClosuresReturnFalse()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->setAllowedValues('foo', [ $this->resolver->setAllowedValues('foo', [
function () { return false; }, function () { return false; },
@ -865,19 +809,15 @@ class OptionsResolverTest extends TestCase
$this->assertEquals(['foo' => 'bar'], $this->resolver->resolve()); $this->assertEquals(['foo' => 'bar'], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testAddAllowedValuesFailsIfUnknownOption() public function testAddAllowedValuesFailsIfUnknownOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->resolver->addAllowedValues('foo', 'bar'); $this->resolver->addAllowedValues('foo', 'bar');
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfAddAllowedValuesFromLazyOption() public function testFailIfAddAllowedValuesFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->addAllowedValues('bar', 'baz'); $options->addAllowedValues('bar', 'baz');
}); });
@ -887,11 +827,9 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfInvalidAddedValue() public function testResolveFailsIfInvalidAddedValue()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->addAllowedValues('foo', 'bar'); $this->resolver->addAllowedValues('foo', 'bar');
@ -914,11 +852,9 @@ class OptionsResolverTest extends TestCase
$this->assertEquals(['foo' => null], $this->resolver->resolve()); $this->assertEquals(['foo' => null], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfInvalidAddedValueMultiple() public function testResolveFailsIfInvalidAddedValueMultiple()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->addAllowedValues('foo', ['bar', 'baz']); $this->resolver->addAllowedValues('foo', ['bar', 'baz']);
@ -951,11 +887,9 @@ class OptionsResolverTest extends TestCase
$this->assertEquals(['foo' => 'baz'], $this->resolver->resolve()); $this->assertEquals(['foo' => 'baz'], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveFailsIfAllAddedClosuresReturnFalse() public function testResolveFailsIfAllAddedClosuresReturnFalse()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 42); $this->resolver->setDefault('foo', 42);
$this->resolver->setAllowedValues('foo', function () { return false; }); $this->resolver->setAllowedValues('foo', function () { return false; });
$this->resolver->addAllowedValues('foo', function () { return false; }); $this->resolver->addAllowedValues('foo', function () { return false; });
@ -997,19 +931,15 @@ class OptionsResolverTest extends TestCase
$this->assertEquals(['foo' => 'normalized'], $this->resolver->resolve()); $this->assertEquals(['foo' => 'normalized'], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testSetNormalizerFailsIfUnknownOption() public function testSetNormalizerFailsIfUnknownOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
$this->resolver->setNormalizer('foo', function () {}); $this->resolver->setNormalizer('foo', function () {});
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfSetNormalizerFromLazyOption() public function testFailIfSetNormalizerFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->setNormalizer('foo', function () {}); $options->setNormalizer('foo', function () {});
}); });
@ -1043,11 +973,9 @@ class OptionsResolverTest extends TestCase
$this->assertEquals(['foo' => 'normalized[baz]'], $resolved); $this->assertEquals(['foo' => 'normalized[baz]'], $resolved);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testValidateTypeBeforeNormalization() public function testValidateTypeBeforeNormalization()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 'bar'); $this->resolver->setDefault('foo', 'bar');
$this->resolver->setAllowedTypes('foo', 'int'); $this->resolver->setAllowedTypes('foo', 'int');
@ -1059,11 +987,9 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testValidateValueBeforeNormalization() public function testValidateValueBeforeNormalization()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->resolver->setDefault('foo', 'bar'); $this->resolver->setDefault('foo', 'bar');
$this->resolver->setAllowedValues('foo', 'baz'); $this->resolver->setAllowedValues('foo', 'baz');
@ -1113,11 +1039,9 @@ class OptionsResolverTest extends TestCase
], $this->resolver->resolve()); ], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
*/
public function testFailIfCyclicDependencyBetweenNormalizers() public function testFailIfCyclicDependencyBetweenNormalizers()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\OptionDefinitionException');
$this->resolver->setDefault('norm1', 'bar'); $this->resolver->setDefault('norm1', 'bar');
$this->resolver->setDefault('norm2', 'baz'); $this->resolver->setDefault('norm2', 'baz');
@ -1132,11 +1056,9 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
*/
public function testFailIfCyclicDependencyBetweenNormalizerAndLazyOption() public function testFailIfCyclicDependencyBetweenNormalizerAndLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\OptionDefinitionException');
$this->resolver->setDefault('lazy', function (Options $options) { $this->resolver->setDefault('lazy', function (Options $options) {
$options['norm']; $options['norm'];
}); });
@ -1254,11 +1176,9 @@ class OptionsResolverTest extends TestCase
], $this->resolver->resolve()); ], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfSetDefaultsFromLazyOption() public function testFailIfSetDefaultsFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->setDefaults(['two' => '2']); $options->setDefaults(['two' => '2']);
}); });
@ -1335,11 +1255,9 @@ class OptionsResolverTest extends TestCase
$this->assertSame(['foo' => 'bar'], $this->resolver->resolve()); $this->assertSame(['foo' => 'bar'], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfRemoveFromLazyOption() public function testFailIfRemoveFromLazyOption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->remove('bar'); $options->remove('bar');
}); });
@ -1411,11 +1329,9 @@ class OptionsResolverTest extends TestCase
$this->assertSame(['foo' => 'bar'], $this->resolver->resolve()); $this->assertSame(['foo' => 'bar'], $this->resolver->resolve());
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testFailIfClearFromLazyption() public function testFailIfClearFromLazyption()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', function (Options $options) { $this->resolver->setDefault('foo', function (Options $options) {
$options->clear(); $options->clear();
}); });
@ -1470,50 +1386,40 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(['default2' => 42, 'required' => 'value']); $this->resolver->resolve(['default2' => 42, 'required' => 'value']);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testArrayAccessGetFailsOutsideResolve() public function testArrayAccessGetFailsOutsideResolve()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('default', 0); $this->resolver->setDefault('default', 0);
$this->resolver['default']; $this->resolver['default'];
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testArrayAccessExistsFailsOutsideResolve() public function testArrayAccessExistsFailsOutsideResolve()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('default', 0); $this->resolver->setDefault('default', 0);
isset($this->resolver['default']); isset($this->resolver['default']);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testArrayAccessSetNotSupported() public function testArrayAccessSetNotSupported()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver['default'] = 0; $this->resolver['default'] = 0;
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/
public function testArrayAccessUnsetNotSupported() public function testArrayAccessUnsetNotSupported()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('default', 0); $this->resolver->setDefault('default', 0);
unset($this->resolver['default']); unset($this->resolver['default']);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoSuchOptionException
* @expectedExceptionMessage The option "undefined" does not exist. Defined options are: "foo", "lazy".
*/
public function testFailIfGetNonExisting() public function testFailIfGetNonExisting()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\NoSuchOptionException');
$this->expectExceptionMessage('The option "undefined" does not exist. Defined options are: "foo", "lazy".');
$this->resolver->setDefault('foo', 'bar'); $this->resolver->setDefault('foo', 'bar');
$this->resolver->setDefault('lazy', function (Options $options) { $this->resolver->setDefault('lazy', function (Options $options) {
@ -1523,12 +1429,10 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\NoSuchOptionException
* @expectedExceptionMessage The optional option "defined" has no value set. You should make sure it is set with "isset" before reading it.
*/
public function testFailIfGetDefinedButUnset() public function testFailIfGetDefinedButUnset()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\NoSuchOptionException');
$this->expectExceptionMessage('The optional option "defined" has no value set. You should make sure it is set with "isset" before reading it.');
$this->resolver->setDefined('defined'); $this->resolver->setDefined('defined');
$this->resolver->setDefault('lazy', function (Options $options) { $this->resolver->setDefault('lazy', function (Options $options) {
@ -1538,11 +1442,9 @@ class OptionsResolverTest extends TestCase
$this->resolver->resolve(); $this->resolver->resolve();
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException
*/
public function testFailIfCyclicDependency() public function testFailIfCyclicDependency()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\OptionDefinitionException');
$this->resolver->setDefault('lazy1', function (Options $options) { $this->resolver->setDefault('lazy1', function (Options $options) {
$options['lazy2']; $options['lazy2'];
}); });
@ -1572,11 +1474,10 @@ class OptionsResolverTest extends TestCase
* In resolve() we count the options that are actually set (which may be * In resolve() we count the options that are actually set (which may be
* only a subset of the defined options). Outside of resolve(), it's not * only a subset of the defined options). Outside of resolve(), it's not
* clear what is counted. * clear what is counted.
*
* @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException
*/ */
public function testCountFailsOutsideResolve() public function testCountFailsOutsideResolve()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException');
$this->resolver->setDefault('foo', 0); $this->resolver->setDefault('foo', 0);
$this->resolver->setRequired('bar'); $this->resolver->setRequired('bar');
$this->resolver->setDefined('bar'); $this->resolver->setDefined('bar');
@ -1631,12 +1532,10 @@ class OptionsResolverTest extends TestCase
)); ));
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "float[][][][]", but one of the elements is of type "integer[][][][]".
*/
public function testNestedArraysException() public function testNestedArraysException()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "float[][][][]", but one of the elements is of type "integer[][][][]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'float[][][][]'); $this->resolver->setAllowedTypes('foo', 'float[][][][]');
@ -1651,12 +1550,10 @@ class OptionsResolverTest extends TestCase
]); ]);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "boolean[][]".
*/
public function testNestedArrayException1() public function testNestedArrayException1()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "boolean[][]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[][]'); $this->resolver->setAllowedTypes('foo', 'int[][]');
$this->resolver->resolve([ $this->resolver->resolve([
@ -1666,12 +1563,10 @@ class OptionsResolverTest extends TestCase
]); ]);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "boolean[][]".
*/
public function testNestedArrayException2() public function testNestedArrayException2()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[][]", but one of the elements is of type "boolean[][]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'int[][]'); $this->resolver->setAllowedTypes('foo', 'int[][]');
$this->resolver->resolve([ $this->resolver->resolve([
@ -1681,12 +1576,10 @@ class OptionsResolverTest extends TestCase
]); ]);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "string[][][]", but one of the elements is of type "string[][]".
*/
public function testNestedArrayException3() public function testNestedArrayException3()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[][][]", but one of the elements is of type "string[][]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'string[][][]'); $this->resolver->setAllowedTypes('foo', 'string[][][]');
$this->resolver->resolve([ $this->resolver->resolve([
@ -1696,12 +1589,10 @@ class OptionsResolverTest extends TestCase
]); ]);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "string[][][]", but one of the elements is of type "integer[][][]".
*/
public function testNestedArrayException4() public function testNestedArrayException4()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[][][]", but one of the elements is of type "integer[][][]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'string[][][]'); $this->resolver->setAllowedTypes('foo', 'string[][][]');
$this->resolver->resolve([ $this->resolver->resolve([
@ -1712,12 +1603,10 @@ class OptionsResolverTest extends TestCase
]); ]);
} }
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value array is expected to be of type "string[]", but one of the elements is of type "array[]".
*/
public function testNestedArrayException5() public function testNestedArrayException5()
{ {
$this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "string[]", but one of the elements is of type "array[]".');
$this->resolver->setDefined('foo'); $this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'string[]'); $this->resolver->setAllowedTypes('foo', 'string[]');
$this->resolver->resolve([ $this->resolver->resolve([