diff --git a/application/wechat/command/Fans.php b/application/wechat/command/Fans.php index 40f287d88..ef54d63c8 100644 --- a/application/wechat/command/Fans.php +++ b/application/wechat/command/Fans.php @@ -54,29 +54,28 @@ class Fans extends Command /** * 同步微信粉丝列表 * @param string $next - * @param integer $index + * @param integer $done * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException * @throws \think\Exception * @throws \think\exception\PDOException */ - protected function _list($next = '', $index = 0) + protected function _list($next = '', $done = 0) { $appid = WechatService::getAppid(); $wechat = WechatService::WeChatUser(); $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) { if (is_array($list = $wechat->getBatchUserInfo($chunk)) && !empty($list['user_info_list'])) { 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']}"); \app\wechat\service\FansService::set($user, $appid); } } } - if (in_array($result['next_openid'], $result['data']['openid'])) break; - else $next = $result['next_openid']; + $next = $result['total'] > $done ? $result['next_openid'] : null; } $this->output->comment('synchronized fans list successful.'); } @@ -84,27 +83,25 @@ class Fans extends Command /** * 同步粉丝黑名单列表 * @param string $next - * @param integer $index + * @param integer $done * @throws \WeChat\Exceptions\InvalidResponseException * @throws \WeChat\Exceptions\LocalCacheException * @throws \think\Exception * @throws \think\exception\PDOException */ - public function _black($next = '', $index = 0) + public function _black($next = '', $done = 0) { $wechat = WechatService::WeChatUser(); $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 ($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}"); } - $where = [['is_black', 'eq', '0'], ['openid', 'in', $chunk]]; - Db::name('WechatFans')->where($where)->update(['is_black' => '1']); + Db::name('WechatFans')->where(['is_black' => '0'])->whereIn('openid', $chunk)->update(['is_black' => '1']); } - if (in_array($result['next_openid'], $result['data']['openid'])) break; - else $next = $result['next_openid']; + $next = $result['total'] > $done ? $result['next_openid'] : null; } $this->output->comment('synchronized fans black successful.'); } diff --git a/application/wechat/queue/WechatQueue.php b/application/wechat/queue/WechatQueue.php index 6cf386876..6211eb9e8 100644 --- a/application/wechat/queue/WechatQueue.php +++ b/application/wechat/queue/WechatQueue.php @@ -48,24 +48,27 @@ class WechatQueue extends Queue { $appid = WechatService::getAppid(); $wechat = WechatService::WeChatUser(); - $next = ''; // 获取远程粉丝 + // 获取远程粉丝 + list($next, $done) = ['', 0]; $output->writeln('Start synchronizing fans from the Wechat server'); - while (is_array($result = $wechat->getUserList($next)) && !empty($result['data']['openid'])) { - foreach (array_chunk($result['data']['openid'], 100) as $chunk) - 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'])) { + while ($next !== null && is_array($result = $wechat->getUserList($next)) && !empty($result['data']['openid'])) { + $done += $result['count']; foreach (array_chunk($result['data']['openid'], 100) as $chunk) { - $where = [['is_black', 'eq', '0'], ['openid', 'in', $chunk]]; - Db::name('WechatFans')->where($where)->update(['is_black' => '1']); + 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 = $result['total'] > $done ? $result['next_openid'] : null; + } + // 同步粉丝黑名单 + 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'); diff --git a/vendor/autoload.php b/vendor/autoload.php index 173005b69..030c87087 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967::getLoader(); +return ComposerAutoloaderInit51aa80bd984c4321321fc668067c748f::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 27f8e3a38..df00aca4c 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967 +class ComposerAutoloaderInit51aa80bd984c4321321fc668067c748f { private static $loader; @@ -19,15 +19,15 @@ class ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967 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(); - 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()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInita2c8b4b934204259b6591513a0ea2967::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit51aa80bd984c4321321fc668067c748f::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ class ComposerAutoloaderInita2c8b4b934204259b6591513a0ea2967 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInita2c8b4b934204259b6591513a0ea2967::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit51aa80bd984c4321321fc668067c748f::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequirea2c8b4b934204259b6591513a0ea2967($fileIdentifier, $file); + composerRequire51aa80bd984c4321321fc668067c748f($fileIdentifier, $file); } return $loader; } } -function composerRequirea2c8b4b934204259b6591513a0ea2967($fileIdentifier, $file) +function composerRequire51aa80bd984c4321321fc668067c748f($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index d7019ddf7..5e3ac04f4 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInita2c8b4b934204259b6591513a0ea2967 +class ComposerStaticInit51aa80bd984c4321321fc668067c748f { public static $files = array ( '841780ea2e1d6545ea3a253239d59c05' => __DIR__ . '/..' . '/qiniu/php-sdk/src/Qiniu/functions.php', @@ -314,9 +314,9 @@ class ComposerStaticInita2c8b4b934204259b6591513a0ea2967 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInita2c8b4b934204259b6591513a0ea2967::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInita2c8b4b934204259b6591513a0ea2967::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInita2c8b4b934204259b6591513a0ea2967::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit51aa80bd984c4321321fc668067c748f::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit51aa80bd984c4321321fc668067c748f::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit51aa80bd984c4321321fc668067c748f::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 3200b081b..0bcd4fedf 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -177,17 +177,17 @@ }, { "name": "symfony/options-resolver", - "version": "v3.4.30", - "version_normalized": "3.4.30.0", + "version": "v3.4.31", + "version_normalized": "3.4.31.0", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "ed3b397f9c07c8ca388b2a1ef744403b4d4ecc44" + "reference": "a7c00586a9ef70acf0f17085e51c399bf9620e03" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/ed3b397f9c07c8ca388b2a1ef744403b4d4ecc44", - "reference": "ed3b397f9c07c8ca388b2a1ef744403b4d4ecc44", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/a7c00586a9ef70acf0f17085e51c399bf9620e03", + "reference": "a7c00586a9ef70acf0f17085e51c399bf9620e03", "shasum": "", "mirrors": [ { @@ -199,7 +199,7 @@ "require": { "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", "extra": { "branch-alias": { diff --git a/vendor/symfony/options-resolver/Tests/Debug/OptionsResolverIntrospectorTest.php b/vendor/symfony/options-resolver/Tests/Debug/OptionsResolverIntrospectorTest.php index 8dd7997dd..8d6e9f63f 100644 --- a/vendor/symfony/options-resolver/Tests/Debug/OptionsResolverIntrospectorTest.php +++ b/vendor/symfony/options-resolver/Tests/Debug/OptionsResolverIntrospectorTest.php @@ -36,12 +36,10 @@ class OptionsResolverIntrospectorTest extends TestCase $this->assertNull($debug->getDefault($option)); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException - * @expectedExceptionMessage No default value was set for the "foo" option. - */ 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->setDefined($option = 'foo'); @@ -49,12 +47,10 @@ class OptionsResolverIntrospectorTest extends TestCase $this->assertSame('bar', $debug->getDefault($option)); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - * @expectedExceptionMessage The option "foo" does not exist. - */ public function testGetDefaultThrowsOnNotDefinedOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); + $this->expectExceptionMessage('The option "foo" does not exist.'); $resolver = new OptionsResolver(); $debug = new OptionsResolverIntrospector($resolver); @@ -71,12 +67,10 @@ class OptionsResolverIntrospectorTest extends TestCase $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() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException'); + $this->expectExceptionMessage('No lazy closures were set for the "foo" option.'); $resolver = new OptionsResolver(); $resolver->setDefined($option = 'foo'); @@ -84,12 +78,10 @@ class OptionsResolverIntrospectorTest extends TestCase $this->assertSame('bar', $debug->getLazyClosures($option)); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - * @expectedExceptionMessage The option "foo" does not exist. - */ public function testGetLazyClosuresThrowsOnNotDefinedOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); + $this->expectExceptionMessage('The option "foo" does not exist.'); $resolver = new OptionsResolver(); $debug = new OptionsResolverIntrospector($resolver); @@ -106,12 +98,10 @@ class OptionsResolverIntrospectorTest extends TestCase $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() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException'); + $this->expectExceptionMessage('No allowed types were set for the "foo" option.'); $resolver = new OptionsResolver(); $resolver->setDefined($option = 'foo'); @@ -119,12 +109,10 @@ class OptionsResolverIntrospectorTest extends TestCase $this->assertSame('bar', $debug->getAllowedTypes($option)); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - * @expectedExceptionMessage The option "foo" does not exist. - */ public function testGetAllowedTypesThrowsOnNotDefinedOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); + $this->expectExceptionMessage('The option "foo" does not exist.'); $resolver = new OptionsResolver(); $debug = new OptionsResolverIntrospector($resolver); @@ -141,12 +129,10 @@ class OptionsResolverIntrospectorTest extends TestCase $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() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException'); + $this->expectExceptionMessage('No allowed values were set for the "foo" option.'); $resolver = new OptionsResolver(); $resolver->setDefined($option = 'foo'); @@ -154,12 +140,10 @@ class OptionsResolverIntrospectorTest extends TestCase $this->assertSame('bar', $debug->getAllowedValues($option)); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - * @expectedExceptionMessage The option "foo" does not exist. - */ public function testGetAllowedValuesThrowsOnNotDefinedOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); + $this->expectExceptionMessage('The option "foo" does not exist.'); $resolver = new OptionsResolver(); $debug = new OptionsResolverIntrospector($resolver); @@ -176,12 +160,10 @@ class OptionsResolverIntrospectorTest extends TestCase $this->assertSame($normalizer, $debug->getNormalizer($option)); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\NoConfigurationException - * @expectedExceptionMessage No normalizer was set for the "foo" option. - */ public function testGetNormalizerThrowsOnNoConfiguredValue() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\NoConfigurationException'); + $this->expectExceptionMessage('No normalizer was set for the "foo" option.'); $resolver = new OptionsResolver(); $resolver->setDefined($option = 'foo'); @@ -189,12 +171,10 @@ class OptionsResolverIntrospectorTest extends TestCase $this->assertSame('bar', $debug->getNormalizer($option)); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - * @expectedExceptionMessage The option "foo" does not exist. - */ public function testGetNormalizerThrowsOnNotDefinedOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); + $this->expectExceptionMessage('The option "foo" does not exist.'); $resolver = new OptionsResolver(); $debug = new OptionsResolverIntrospector($resolver); diff --git a/vendor/symfony/options-resolver/Tests/OptionsResolverTest.php b/vendor/symfony/options-resolver/Tests/OptionsResolverTest.php index d85bbe8fd..cbdaaf024 100644 --- a/vendor/symfony/options-resolver/Tests/OptionsResolverTest.php +++ b/vendor/symfony/options-resolver/Tests/OptionsResolverTest.php @@ -29,35 +29,29 @@ class OptionsResolverTest extends TestCase $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() { + $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('a', '2'); $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() { + $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('a', '2'); $this->resolver->resolve(['ping' => 'pong', 'foo' => 'bar', 'baz' => 'bam']); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testResolveFailsFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->resolve([]); }); @@ -81,11 +75,9 @@ class OptionsResolverTest extends TestCase ], $this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfSetDefaultFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('lazy', function (Options $options) { $options->setDefault('default', 42); }); @@ -225,11 +217,9 @@ class OptionsResolverTest extends TestCase $this->assertSame($this->resolver, $this->resolver->setRequired('foo')); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfSetRequiredFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->setRequired('bar'); }); @@ -237,11 +227,9 @@ class OptionsResolverTest extends TestCase $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException - */ public function testResolveFailsIfRequiredOptionMissing() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\MissingOptionsException'); $this->resolver->setRequired('foo'); $this->resolver->resolve(); @@ -353,11 +341,9 @@ class OptionsResolverTest extends TestCase $this->assertSame(['bar'], $this->resolver->getMissingOptions()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfSetDefinedFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->setDefined('bar'); }); @@ -450,11 +436,9 @@ class OptionsResolverTest extends TestCase $this->assertFalse($this->resolver->isDefined('foo')); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - */ public function testSetAllowedTypesFailsIfUnknownOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); $this->resolver->setAllowedTypes('foo', 'string'); } @@ -467,11 +451,9 @@ class OptionsResolverTest extends TestCase $this->assertSame(['foo' => ['bar', 'baz']], $options); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfSetAllowedTypesFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->setAllowedTypes('bar', 'string'); }); @@ -481,36 +463,30 @@ class OptionsResolverTest extends TestCase $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() { + $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->setAllowedTypes('foo', 'int[]'); $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() { + $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->setAllowedTypes('foo', 'int[]'); $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() { + $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->setAllowedTypes('foo', 'int[]'); $values = range(1, 5); @@ -522,12 +498,10 @@ class OptionsResolverTest extends TestCase $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() { + $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->setAllowedTypes('foo', 'int[][]'); @@ -546,12 +520,8 @@ class OptionsResolverTest extends TestCase $this->resolver->setDefined('option'); $this->resolver->setAllowedTypes('option', $allowedType); - if (method_exists($this, 'expectException')) { - $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); - $this->expectExceptionMessage($exceptionMessage); - } else { - $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException', $exceptionMessage); - } + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); + $this->expectExceptionMessage($exceptionMessage); $this->resolver->resolve(['option' => $actualType]); } @@ -578,12 +548,10 @@ class OptionsResolverTest extends TestCase $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() { + $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->setAllowedTypes('foo', ['string', 'bool']); @@ -621,30 +589,24 @@ class OptionsResolverTest extends TestCase $this->assertEquals($data, $result); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testResolveFailsIfNotInstanceOfClass() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 'bar'); $this->resolver->setAllowedTypes('foo', '\stdClass'); $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - */ public function testAddAllowedTypesFailsIfUnknownOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); $this->resolver->addAllowedTypes('foo', 'string'); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfAddAllowedTypesFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->addAllowedTypes('bar', 'string'); }); @@ -654,11 +616,9 @@ class OptionsResolverTest extends TestCase $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testResolveFailsIfInvalidAddedType() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 42); $this->resolver->addAllowedTypes('foo', 'string'); @@ -673,11 +633,9 @@ class OptionsResolverTest extends TestCase $this->assertNotEmpty($this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testResolveFailsIfInvalidAddedTypeMultiple() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 42); $this->resolver->addAllowedTypes('foo', ['string', 'bool']); @@ -714,19 +672,15 @@ class OptionsResolverTest extends TestCase $this->assertNotEmpty($this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - */ public function testSetAllowedValuesFailsIfUnknownOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); $this->resolver->setAllowedValues('foo', 'bar'); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfSetAllowedValuesFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->setAllowedValues('bar', 'baz'); }); @@ -736,35 +690,29 @@ class OptionsResolverTest extends TestCase $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() { + $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->setAllowedValues('foo', 'bar'); $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() { + $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->setAllowedValues('foo', 'bar'); $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testResolveFailsIfInvalidValueStrict() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 42); $this->resolver->setAllowedValues('foo', '42'); @@ -787,12 +735,10 @@ class OptionsResolverTest extends TestCase $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() { + $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->setAllowedValues('foo', ['bar', false, null]); @@ -838,11 +784,9 @@ class OptionsResolverTest extends TestCase $this->assertSame('bar', $passedValue); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testResolveFailsIfAllClosuresReturnFalse() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 42); $this->resolver->setAllowedValues('foo', [ function () { return false; }, @@ -865,19 +809,15 @@ class OptionsResolverTest extends TestCase $this->assertEquals(['foo' => 'bar'], $this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - */ public function testAddAllowedValuesFailsIfUnknownOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); $this->resolver->addAllowedValues('foo', 'bar'); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfAddAllowedValuesFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->addAllowedValues('bar', 'baz'); }); @@ -887,11 +827,9 @@ class OptionsResolverTest extends TestCase $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testResolveFailsIfInvalidAddedValue() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 42); $this->resolver->addAllowedValues('foo', 'bar'); @@ -914,11 +852,9 @@ class OptionsResolverTest extends TestCase $this->assertEquals(['foo' => null], $this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testResolveFailsIfInvalidAddedValueMultiple() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 42); $this->resolver->addAllowedValues('foo', ['bar', 'baz']); @@ -951,11 +887,9 @@ class OptionsResolverTest extends TestCase $this->assertEquals(['foo' => 'baz'], $this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testResolveFailsIfAllAddedClosuresReturnFalse() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 42); $this->resolver->setAllowedValues('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()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException - */ public function testSetNormalizerFailsIfUnknownOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException'); $this->resolver->setNormalizer('foo', function () {}); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfSetNormalizerFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->setNormalizer('foo', function () {}); }); @@ -1043,11 +973,9 @@ class OptionsResolverTest extends TestCase $this->assertEquals(['foo' => 'normalized[baz]'], $resolved); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testValidateTypeBeforeNormalization() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 'bar'); $this->resolver->setAllowedTypes('foo', 'int'); @@ -1059,11 +987,9 @@ class OptionsResolverTest extends TestCase $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ public function testValidateValueBeforeNormalization() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException'); $this->resolver->setDefault('foo', 'bar'); $this->resolver->setAllowedValues('foo', 'baz'); @@ -1113,11 +1039,9 @@ class OptionsResolverTest extends TestCase ], $this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException - */ public function testFailIfCyclicDependencyBetweenNormalizers() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\OptionDefinitionException'); $this->resolver->setDefault('norm1', 'bar'); $this->resolver->setDefault('norm2', 'baz'); @@ -1132,11 +1056,9 @@ class OptionsResolverTest extends TestCase $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException - */ public function testFailIfCyclicDependencyBetweenNormalizerAndLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\OptionDefinitionException'); $this->resolver->setDefault('lazy', function (Options $options) { $options['norm']; }); @@ -1254,11 +1176,9 @@ class OptionsResolverTest extends TestCase ], $this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfSetDefaultsFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->setDefaults(['two' => '2']); }); @@ -1335,11 +1255,9 @@ class OptionsResolverTest extends TestCase $this->assertSame(['foo' => 'bar'], $this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfRemoveFromLazyOption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->remove('bar'); }); @@ -1411,11 +1329,9 @@ class OptionsResolverTest extends TestCase $this->assertSame(['foo' => 'bar'], $this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testFailIfClearFromLazyption() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', function (Options $options) { $options->clear(); }); @@ -1470,50 +1386,40 @@ class OptionsResolverTest extends TestCase $this->resolver->resolve(['default2' => 42, 'required' => 'value']); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testArrayAccessGetFailsOutsideResolve() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('default', 0); $this->resolver['default']; } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testArrayAccessExistsFailsOutsideResolve() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('default', 0); isset($this->resolver['default']); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testArrayAccessSetNotSupported() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver['default'] = 0; } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException - */ public function testArrayAccessUnsetNotSupported() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('default', 0); 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() { + $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('lazy', function (Options $options) { @@ -1523,12 +1429,10 @@ class OptionsResolverTest extends TestCase $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() { + $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->setDefault('lazy', function (Options $options) { @@ -1538,11 +1442,9 @@ class OptionsResolverTest extends TestCase $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException - */ public function testFailIfCyclicDependency() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\OptionDefinitionException'); $this->resolver->setDefault('lazy1', function (Options $options) { $options['lazy2']; }); @@ -1572,11 +1474,10 @@ class OptionsResolverTest extends TestCase * 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 * clear what is counted. - * - * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException */ public function testCountFailsOutsideResolve() { + $this->expectException('Symfony\Component\OptionsResolver\Exception\AccessException'); $this->resolver->setDefault('foo', 0); $this->resolver->setRequired('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() { + $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->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() { + $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->setAllowedTypes('foo', 'int[][]'); $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() { + $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->setAllowedTypes('foo', 'int[][]'); $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() { + $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->setAllowedTypes('foo', 'string[][][]'); $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() { + $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->setAllowedTypes('foo', 'string[][][]'); $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() { + $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->setAllowedTypes('foo', 'string[]'); $this->resolver->resolve([