GetoptTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Console_Getop
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /**
  27. * Zend_Console_Getopt
  28. */
  29. require_once 'Zend/Console/Getopt.php';
  30. /**
  31. * PHPUnit test case
  32. */
  33. require_once 'PHPUnit/Framework/TestCase.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Console_Getopt
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Console_Getopt
  41. */
  42. class Zend_Console_GetoptTest extends PHPUnit_Framework_TestCase
  43. {
  44. public function setUp()
  45. {
  46. if(ini_get('register_argc_argv') == false) {
  47. $this->markTestSkipped("Cannot Test Zend_Console_Getopt without 'register_argc_argv' ini option true.");
  48. }
  49. $_SERVER['argv'] = array('getopttest');
  50. }
  51. public function testGetoptShortOptionsGnuMode()
  52. {
  53. $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg'));
  54. $this->assertEquals(true, $opts->a);
  55. $this->assertNull(@$opts->b);
  56. $this->assertEquals($opts->p, 'p_arg');
  57. }
  58. public function testGetoptLongOptionsZendMode()
  59. {
  60. $opts = new Zend_Console_Getopt(array(
  61. 'apple|a' => 'Apple option',
  62. 'banana|b' => 'Banana option',
  63. 'pear|p=s' => 'Pear option'
  64. ),
  65. array('-a', '-p', 'p_arg'));
  66. $this->assertTrue($opts->apple);
  67. $this->assertNull(@$opts->banana);
  68. $this->assertEquals($opts->pear, 'p_arg');
  69. }
  70. public function testGetoptZendModeEqualsParam()
  71. {
  72. $opts = new Zend_Console_Getopt(array(
  73. 'apple|a' => 'Apple option',
  74. 'banana|b' => 'Banana option',
  75. 'pear|p=s' => 'Pear option'
  76. ),
  77. array('--pear=pear.phpunit.de'));
  78. $this->assertEquals($opts->pear, 'pear.phpunit.de');
  79. }
  80. public function testGetoptToString()
  81. {
  82. $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg'));
  83. $this->assertEquals($opts->__toString(), 'a=true p=p_arg');
  84. }
  85. public function testGetoptDumpString()
  86. {
  87. $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg'));
  88. $this->assertEquals($opts->toString(), 'a=true p=p_arg');
  89. }
  90. public function testGetoptDumpArray()
  91. {
  92. $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg'));
  93. $this->assertEquals(implode(',', $opts->toArray()), 'a,p,p_arg');
  94. }
  95. public function testGetoptDumpJson()
  96. {
  97. $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg'));
  98. $this->assertEquals($opts->toJson(),
  99. '{"options":[{"option":{"flag":"a","parameter":true}},{"option":{"flag":"p","parameter":"p_arg"}}]}');
  100. }
  101. public function testGetoptDumpXml()
  102. {
  103. $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg'));
  104. $this->assertEquals($opts->toXml(),
  105. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<options><option flag=\"a\"/><option flag=\"p\" parameter=\"p_arg\"/></options>\n");
  106. }
  107. public function testGetoptExceptionForMissingFlag()
  108. {
  109. try {
  110. $opts = new Zend_Console_Getopt(array('|a'=>'Apple option'));
  111. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  112. } catch (Zend_Exception $e) {
  113. $this->assertType('Zend_Console_Getopt_Exception', $e,
  114. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  115. $this->assertEquals($e->getMessage(),
  116. 'Blank flag not allowed in rule "|a".');
  117. }
  118. }
  119. public function testGetoptExceptionForDuplicateFlag()
  120. {
  121. try {
  122. $opts = new Zend_Console_Getopt(
  123. array('apple|apple'=>'apple-option'));
  124. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  125. } catch (Zend_Exception $e) {
  126. $this->assertType('Zend_Console_Getopt_Exception', $e,
  127. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  128. $this->assertEquals($e->getMessage(),
  129. 'Option "--apple" is being defined more than once.');
  130. }
  131. try {
  132. $opts = new Zend_Console_Getopt(
  133. array('a'=>'Apple option', 'apple|a'=>'Apple option'));
  134. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  135. } catch (Zend_Exception $e) {
  136. $this->assertType('Zend_Console_Getopt_Exception', $e,
  137. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  138. $this->assertEquals($e->getMessage(),
  139. 'Option "-a" is being defined more than once.');
  140. }
  141. }
  142. public function testGetoptAddRules()
  143. {
  144. $opts = new Zend_Console_Getopt(
  145. array(
  146. 'apple|a' => 'Apple option',
  147. 'banana|b' => 'Banana option'
  148. ),
  149. array('--pear', 'pear_param'));
  150. try {
  151. $opts->parse();
  152. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  153. } catch (Zend_Exception $e) {
  154. $this->assertType('Zend_Console_Getopt_Exception', $e,
  155. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  156. $this->assertEquals($e->getMessage(), 'Option "pear" is not recognized.');
  157. }
  158. $opts->addRules(array('pear|p=s' => 'Pear option'));
  159. $this->assertEquals($opts->pear, 'pear_param');
  160. }
  161. public function testGetoptExceptionMissingParameter()
  162. {
  163. $opts = new Zend_Console_Getopt(
  164. array(
  165. 'apple|a=s' => 'Apple with required parameter',
  166. 'banana|b' => 'Banana'
  167. ),
  168. array('--apple'));
  169. try {
  170. $opts->parse();
  171. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  172. } catch (Zend_Exception $e) {
  173. $this->assertType('Zend_Console_Getopt_Exception', $e,
  174. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  175. $this->assertEquals($e->getMessage(), 'Option "apple" requires a parameter.');
  176. }
  177. }
  178. public function testGetoptOptionalParameter()
  179. {
  180. $opts = new Zend_Console_Getopt(
  181. array(
  182. 'apple|a-s' => 'Apple with optional parameter',
  183. 'banana|b' => 'Banana'
  184. ),
  185. array('--apple', '--banana'));
  186. $this->assertTrue($opts->apple);
  187. $this->assertTrue($opts->banana);
  188. }
  189. public function testGetoptIgnoreCaseGnuMode()
  190. {
  191. $opts = new Zend_Console_Getopt('aB', array('-A', '-b'),
  192. array(Zend_Console_Getopt::CONFIG_IGNORECASE => true));
  193. $this->assertEquals(true, $opts->a);
  194. $this->assertEquals(true, $opts->B);
  195. }
  196. public function testGetoptIgnoreCaseZendMode()
  197. {
  198. $opts = new Zend_Console_Getopt(
  199. array(
  200. 'apple|a' => 'Apple-option',
  201. 'Banana|B' => 'Banana-option'
  202. ),
  203. array('--Apple', '--bAnaNa'),
  204. array(Zend_Console_Getopt::CONFIG_IGNORECASE => true));
  205. $this->assertEquals(true, $opts->apple);
  206. $this->assertEquals(true, $opts->BANANA);
  207. }
  208. public function testGetoptIsSet()
  209. {
  210. $opts = new Zend_Console_Getopt('ab', array('-a'));
  211. $this->assertTrue(isset($opts->a));
  212. $this->assertFalse(isset($opts->b));
  213. }
  214. public function testGetoptIsSetAlias()
  215. {
  216. $opts = new Zend_Console_Getopt('ab', array('-a'));
  217. $opts->setAliases(array('a' => 'apple', 'b' => 'banana'));
  218. $this->assertTrue(isset($opts->apple));
  219. $this->assertFalse(isset($opts->banana));
  220. }
  221. public function testGetoptIsSetInvalid()
  222. {
  223. $opts = new Zend_Console_Getopt('ab', array('-a'));
  224. $opts->setAliases(array('a' => 'apple', 'b' => 'banana'));
  225. $this->assertFalse(isset($opts->cumquat));
  226. }
  227. public function testGetoptSet()
  228. {
  229. $opts = new Zend_Console_Getopt('ab', array('-a'));
  230. $this->assertFalse(isset($opts->b));
  231. $opts->b = true;
  232. $this->assertTrue(isset($opts->b));
  233. }
  234. public function testGetoptSetBeforeParse()
  235. {
  236. $opts = new Zend_Console_Getopt('ab', array('-a'));
  237. $opts->b = true;
  238. $this->assertTrue(isset($opts->b));
  239. }
  240. public function testGetoptUnSet()
  241. {
  242. $opts = new Zend_Console_Getopt('ab', array('-a'));
  243. $this->assertTrue(isset($opts->a));
  244. unset($opts->a);
  245. $this->assertFalse(isset($opts->a));
  246. }
  247. public function testGetoptUnSetBeforeParse()
  248. {
  249. $opts = new Zend_Console_Getopt('ab', array('-a'));
  250. unset($opts->a);
  251. $this->assertFalse(isset($opts->a));
  252. }
  253. /**
  254. * @group ZF-5948
  255. */
  256. public function testGetoptAddSetNonArrayArguments()
  257. {
  258. $opts = new Zend_Console_GetOpt('abp:', array('-foo'));
  259. try {
  260. $opts->setArguments('-a');
  261. $this->fail('Expected to catch a Zend_Console_Getopt_Exception');
  262. } catch(Zend_Exception $e) {
  263. $this->assertType('Zend_Console_Getopt_Exception', $e,
  264. 'Expected Zend_Console_Getopt_Exception, got '. get_class($e));
  265. $this->assertEquals("Parameter #1 to setArguments should be an array",
  266. $e->getMessage());
  267. }
  268. try {
  269. $opts->addArguments('-b');
  270. $this->fail('Expected to catch a Zend_Console_Getopt_Exception');
  271. } catch(Zend_Exception $e) {
  272. $this->assertType('Zend_Console_Getopt_Exception', $e,
  273. 'Expected Zend_Console_Getopt_Exception, got '. get_class($e));
  274. $this->assertEquals("Parameter #1 to addArguments should be an array",
  275. $e->getMessage());
  276. }
  277. }
  278. public function testGetoptAddArguments()
  279. {
  280. $opts = new Zend_Console_Getopt('abp:', array('-a'));
  281. $this->assertNull(@$opts->p);
  282. $opts->addArguments(array('-p', 'p_arg'));
  283. $this->assertEquals($opts->p, 'p_arg');
  284. }
  285. public function testGetoptRemainingArgs()
  286. {
  287. $opts = new Zend_Console_Getopt('abp:', array('-a', '--', 'file1', 'file2'));
  288. $this->assertEquals(implode(',', $opts->getRemainingArgs()), 'file1,file2');
  289. $opts = new Zend_Console_Getopt('abp:', array('-a', 'file1', 'file2'));
  290. $this->assertEquals(implode(',', $opts->getRemainingArgs()), 'file1,file2');
  291. }
  292. public function testGetoptDashDashFalse()
  293. {
  294. try {
  295. $opts = new Zend_Console_Getopt('abp:', array('-a', '--', '--fakeflag'),
  296. array(Zend_Console_Getopt::CONFIG_DASHDASH => false));
  297. $opts->parse();
  298. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  299. } catch (Zend_Exception $e) {
  300. $this->assertType('Zend_Console_Getopt_Exception', $e,
  301. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  302. $this->assertEquals($e->getMessage(), 'Option "fakeflag" is not recognized.');
  303. }
  304. }
  305. public function testGetoptGetOptions()
  306. {
  307. $opts = new Zend_Console_Getopt('abp:', array('-a', '-p', 'p_arg'));
  308. $this->assertEquals(implode(',', $opts->getOptions()), 'a,p');
  309. }
  310. public function testGetoptGetUsageMessage()
  311. {
  312. $opts = new Zend_Console_Getopt('abp:', array('-x'));
  313. $message = preg_replace('/Usage: .* \[ options \]/',
  314. 'Usage: <progname> [ options ]',
  315. $opts->getUsageMessage());
  316. $message = preg_replace('/ /', '_', $message);
  317. $this->assertEquals($message,
  318. "Usage:_<progname>_[_options_]\n-a___________________\n-b___________________\n-p_<string>__________\n");
  319. }
  320. public function testGetoptUsageMessageFromException()
  321. {
  322. try {
  323. $opts = new Zend_Console_Getopt(array(
  324. 'apple|a-s' => 'apple',
  325. 'banana1|banana2|banana3|banana4' => 'banana',
  326. 'pear=s' => 'pear'),
  327. array('-x'));
  328. $opts->parse();
  329. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  330. } catch (Zend_Exception $e) {
  331. $this->assertType('Zend_Console_Getopt_Exception', $e,
  332. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  333. $message = preg_replace('/Usage: .* \[ options \]/',
  334. 'Usage: <progname> [ options ]',
  335. $e->getUsageMessage());
  336. $message = preg_replace('/ /', '_', $message);
  337. $this->assertEquals($message,
  338. "Usage:_<progname>_[_options_]\n--apple|-a_[_<string>_]_________________apple\n--banana1|--banana2|--banana3|--banana4_banana\n--pear_<string>_________________________pear\n");
  339. }
  340. }
  341. public function testGetoptSetAliases()
  342. {
  343. $opts = new Zend_Console_Getopt('abp:', array('--apple'));
  344. $opts->setAliases(array('a' => 'apple'));
  345. $this->assertTrue($opts->a);
  346. }
  347. public function testGetoptSetAliasesIgnoreCase()
  348. {
  349. $opts = new Zend_Console_Getopt('abp:', array('--apple'),
  350. array(Zend_Console_Getopt::CONFIG_IGNORECASE => true));
  351. $opts->setAliases(array('a' => 'APPLE'));
  352. $this->assertTrue($opts->apple);
  353. }
  354. public function testGetoptSetAliasesWithNamingConflict()
  355. {
  356. $opts = new Zend_Console_Getopt('abp:', array('--apple'));
  357. $opts->setAliases(array('a' => 'apple'));
  358. try {
  359. $opts->setAliases(array('b' => 'apple'));
  360. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  361. } catch (Zend_Exception $e) {
  362. $this->assertType('Zend_Console_Getopt_Exception', $e,
  363. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  364. $this->assertEquals($e->getMessage(), 'Option "--apple" is being defined more than once.');
  365. }
  366. }
  367. public function testGetoptSetAliasesInvalid()
  368. {
  369. $opts = new Zend_Console_Getopt('abp:', array('--apple'));
  370. $opts->setAliases(array('c' => 'cumquat'));
  371. $opts->setArguments(array('-c'));
  372. try {
  373. $opts->parse();
  374. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  375. } catch (Zend_Exception $e) {
  376. $this->assertType('Zend_Console_Getopt_Exception', $e,
  377. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  378. $this->assertEquals('Option "c" is not recognized.', $e->getMessage());
  379. }
  380. }
  381. public function testGetoptSetHelp()
  382. {
  383. $opts = new Zend_Console_Getopt('abp:', array('-a'));
  384. $opts->setHelp(array(
  385. 'a' => 'apple',
  386. 'b' => 'banana',
  387. 'p' => 'pear'));
  388. $message = preg_replace('/Usage: .* \[ options \]/',
  389. 'Usage: <progname> [ options ]',
  390. $opts->getUsageMessage());
  391. $message = preg_replace('/ /', '_', $message);
  392. $this->assertEquals($message,
  393. "Usage:_<progname>_[_options_]\n-a___________________apple\n-b___________________banana\n-p_<string>__________pear\n");
  394. }
  395. public function testGetoptSetHelpInvalid()
  396. {
  397. $opts = new Zend_Console_Getopt('abp:', array('-a'));
  398. $opts->setHelp(array(
  399. 'a' => 'apple',
  400. 'b' => 'banana',
  401. 'p' => 'pear',
  402. 'c' => 'cumquat'));
  403. $message = preg_replace('/Usage: .* \[ options \]/',
  404. 'Usage: <progname> [ options ]',
  405. $opts->getUsageMessage());
  406. $message = preg_replace('/ /', '_', $message);
  407. $this->assertEquals($message,
  408. "Usage:_<progname>_[_options_]\n-a___________________apple\n-b___________________banana\n-p_<string>__________pear\n");
  409. }
  410. public function testGetoptCheckParameterType()
  411. {
  412. $opts = new Zend_Console_Getopt(array(
  413. 'apple|a=i' => 'apple with integer',
  414. 'banana|b=w' => 'banana with word',
  415. 'pear|p=s' => 'pear with string',
  416. 'orange|o-i' => 'orange with optional integer',
  417. 'lemon|l-w' => 'lemon with optional word',
  418. 'kumquat|k-s' => 'kumquat with optional string'));
  419. $opts->setArguments(array('-a', 327));
  420. $opts->parse();
  421. $this->assertEquals(327, $opts->a);
  422. $opts->setArguments(array('-a', 'noninteger'));
  423. try {
  424. $opts->parse();
  425. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  426. } catch (Zend_Exception $e) {
  427. $this->assertType('Zend_Console_Getopt_Exception', $e,
  428. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  429. $this->assertEquals($e->getMessage(), 'Option "apple" requires an integer parameter, but was given "noninteger".');
  430. }
  431. $opts->setArguments(array('-b', 'word'));
  432. $this->assertEquals('word', $opts->b);
  433. $opts->setArguments(array('-b', 'two words'));
  434. try {
  435. $opts->parse();
  436. $this->fail('Expected to catch Zend_Console_Getopt_Exception');
  437. } catch (Zend_Exception $e) {
  438. $this->assertType('Zend_Console_Getopt_Exception', $e,
  439. 'Expected Zend_Console_Getopt_Exception, got '.get_class($e));
  440. $this->assertEquals($e->getMessage(), 'Option "banana" requires a single-word parameter, but was given "two words".');
  441. }
  442. $opts->setArguments(array('-p', 'string'));
  443. $this->assertEquals('string', $opts->p);
  444. $opts->setArguments(array('-o', 327));
  445. $this->assertEquals(327, $opts->o);
  446. $opts->setArguments(array('-o'));
  447. $this->assertTrue($opts->o);
  448. $opts->setArguments(array('-l', 'word'));
  449. $this->assertEquals('word', $opts->l);
  450. $opts->setArguments(array('-k', 'string'));
  451. $this->assertEquals('string', $opts->k);
  452. }
  453. /**
  454. * @group ZF-2295
  455. */
  456. public function testRegisterArgcArgvOffThrowsException()
  457. {
  458. $argv = $_SERVER['argv'];
  459. unset($_SERVER['argv']);
  460. try {
  461. $opts = new Zend_Console_GetOpt('abp:');
  462. $this->fail();
  463. } catch(Zend_Console_GetOpt_Exception $e) {
  464. $this->assertContains('$_SERVER["argv"]', $e->getMessage());
  465. }
  466. $_SERVER['argv'] = $argv;
  467. }
  468. /**
  469. * Test to ensure that dashed long names will parse correctly
  470. *
  471. * @group ZF-4763
  472. */
  473. public function testDashWithinLongOptionGetsParsed()
  474. {
  475. $opts = new Zend_Console_Getopt(
  476. array( // rules
  477. 'man-bear|m-s' => 'ManBear with dash',
  478. 'man-bear-pig|b=s' => 'ManBearPid with dash',
  479. ),
  480. array( // arguments
  481. '--man-bear-pig=mbp',
  482. '--man-bear',
  483. 'foobar'
  484. )
  485. );
  486. $opts->parse();
  487. $this->assertEquals('foobar', $opts->getOption('man-bear'));
  488. $this->assertEquals('mbp', $opts->getOption('man-bear-pig'));
  489. }
  490. /**
  491. * @group ZF-2064
  492. */
  493. public function testAddRulesDoesNotThrowWarnings()
  494. {
  495. // Fails if warning is thrown: Should not happen!
  496. $opts = new Zend_Console_Getopt('abp:');
  497. $opts->addRules(
  498. array(
  499. 'verbose|v' => 'Print verbose output'
  500. )
  501. );
  502. }
  503. /**
  504. * @group ZF-5345
  505. */
  506. public function testUsingDashWithoutOptionNameAsLastArgumentIsRecognizedAsRemainingArgument()
  507. {
  508. $opts = new Zend_Console_Getopt("abp:", array("-"));
  509. $opts->parse();
  510. $this->assertEquals(1, count($opts->getRemainingArgs()));
  511. $this->assertEquals(array("-"), $opts->getRemainingArgs());
  512. }
  513. /**
  514. * @group ZF-5345
  515. */
  516. public function testUsingDashWithoutOptionNotAsLastArgumentThrowsException()
  517. {
  518. $opts = new Zend_Console_Getopt("abp:", array("-", "file1"));
  519. try {
  520. $opts->parse();
  521. $this->fail();
  522. } catch(Exception $e) {
  523. $this->assertTrue($e instanceof Zend_Console_Getopt_Exception);
  524. }
  525. }
  526. /**
  527. * @group ZF-5624
  528. */
  529. public function testEqualsCharacterInLongOptionsValue()
  530. {
  531. $fooValue = 'some text containing an = sign which breaks';
  532. $opts = new Zend_Console_Getopt(
  533. array('foo=s' => 'Option One (string)'),
  534. array('--foo='.$fooValue)
  535. );
  536. $this->assertEquals($fooValue, $opts->foo);
  537. }
  538. }