undefined_test.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. <?php
  2. require_once('test_util.php');
  3. use Google\Protobuf\Internal\RepeatedField;
  4. use Google\Protobuf\Internal\GPBType;
  5. use Foo\TestMessage;
  6. use Foo\TestMessage\Sub;
  7. class UndefinedTest extends PHPUnit_Framework_TestCase
  8. {
  9. /**
  10. * @expectedException PHPUnit_Framework_Error
  11. */
  12. public function testInt32AppendStringFail()
  13. {
  14. $arr = new RepeatedField(GPBType::INT32);
  15. $arr[] = 'abc';
  16. }
  17. /**
  18. * @expectedException PHPUnit_Framework_Error
  19. */
  20. public function testInt32SetStringFail()
  21. {
  22. $arr = new RepeatedField(GPBType::INT32);
  23. $arr[] = 0;
  24. $arr[0] = 'abc';
  25. }
  26. /**
  27. * @expectedException PHPUnit_Framework_Error
  28. */
  29. public function testInt32AppendMessageFail()
  30. {
  31. $arr = new RepeatedField(GPBType::INT32);
  32. $arr[] = new Sub();
  33. }
  34. /**
  35. * @expectedException PHPUnit_Framework_Error
  36. */
  37. public function testInt32SetMessageFail()
  38. {
  39. $arr = new RepeatedField(GPBType::INT32);
  40. $arr[] = 0;
  41. $arr[0] = new Sub();
  42. }
  43. /**
  44. * @expectedException PHPUnit_Framework_Error
  45. */
  46. public function testUint32AppendStringFail()
  47. {
  48. $arr = new RepeatedField(GPBType::UINT32);
  49. $arr[] = 'abc';
  50. }
  51. /**
  52. * @expectedException PHPUnit_Framework_Error
  53. */
  54. public function testUint32SetStringFail()
  55. {
  56. $arr = new RepeatedField(GPBType::UINT32);
  57. $arr[] = 0;
  58. $arr[0] = 'abc';
  59. }
  60. /**
  61. * @expectedException PHPUnit_Framework_Error
  62. */
  63. public function testUint32AppendMessageFail()
  64. {
  65. $arr = new RepeatedField(GPBType::UINT32);
  66. $arr[] = new Sub();
  67. }
  68. /**
  69. * @expectedException PHPUnit_Framework_Error
  70. */
  71. public function testUint32SetMessageFail()
  72. {
  73. $arr = new RepeatedField(GPBType::UINT32);
  74. $arr[] = 0;
  75. $arr[0] = new Sub();
  76. }
  77. /**
  78. * @expectedException PHPUnit_Framework_Error
  79. */
  80. public function testInt64AppendStringFail()
  81. {
  82. $arr = new RepeatedField(GPBType::INT64);
  83. $arr[] = 'abc';
  84. }
  85. /**
  86. * @expectedException PHPUnit_Framework_Error
  87. */
  88. public function testInt64SetStringFail()
  89. {
  90. $arr = new RepeatedField(GPBType::INT64);
  91. $arr[] = 0;
  92. $arr[0] = 'abc';
  93. }
  94. /**
  95. * @expectedException PHPUnit_Framework_Error
  96. */
  97. public function testInt64AppendMessageFail()
  98. {
  99. $arr = new RepeatedField(GPBType::INT64);
  100. $arr[] = new Sub();
  101. }
  102. /**
  103. * @expectedException PHPUnit_Framework_Error
  104. */
  105. public function testInt64SetMessageFail()
  106. {
  107. $arr = new RepeatedField(GPBType::INT64);
  108. $arr[] = 0;
  109. $arr[0] = new Sub();
  110. }
  111. /**
  112. * @expectedException PHPUnit_Framework_Error
  113. */
  114. public function testUint64AppendStringFail()
  115. {
  116. $arr = new RepeatedField(GPBType::UINT64);
  117. $arr[] = 'abc';
  118. }
  119. /**
  120. * @expectedException PHPUnit_Framework_Error
  121. */
  122. public function testUint64SetStringFail()
  123. {
  124. $arr = new RepeatedField(GPBType::UINT64);
  125. $arr[] = 0;
  126. $arr[0] = 'abc';
  127. }
  128. /**
  129. * @expectedException PHPUnit_Framework_Error
  130. */
  131. public function testUint64AppendMessageFail()
  132. {
  133. $arr = new RepeatedField(GPBType::UINT64);
  134. $arr[] = new Sub();
  135. }
  136. /**
  137. * @expectedException PHPUnit_Framework_Error
  138. */
  139. public function testUint64SetMessageFail()
  140. {
  141. $arr = new RepeatedField(GPBType::UINT64);
  142. $arr[] = 0;
  143. $arr[0] = new Sub();
  144. }
  145. /**
  146. * @expectedException PHPUnit_Framework_Error
  147. */
  148. public function testFloatAppendStringFail()
  149. {
  150. $arr = new RepeatedField(GPBType::FLOAT);
  151. $arr[] = 'abc';
  152. }
  153. /**
  154. * @expectedException PHPUnit_Framework_Error
  155. */
  156. public function testFloatSetStringFail()
  157. {
  158. $arr = new RepeatedField(GPBType::FLOAT);
  159. $arr[] = 0.0;
  160. $arr[0] = 'abc';
  161. }
  162. /**
  163. * @expectedException PHPUnit_Framework_Error
  164. */
  165. public function testFloatAppendMessageFail()
  166. {
  167. $arr = new RepeatedField(GPBType::FLOAT);
  168. $arr[] = new Sub();
  169. }
  170. /**
  171. * @expectedException PHPUnit_Framework_Error
  172. */
  173. public function testFloatSetMessageFail()
  174. {
  175. $arr = new RepeatedField(GPBType::FLOAT);
  176. $arr[] = 0.0;
  177. $arr[0] = new Sub();
  178. }
  179. /**
  180. * @expectedException PHPUnit_Framework_Error
  181. */
  182. public function testDoubleAppendStringFail()
  183. {
  184. $arr = new RepeatedField(GPBType::DOUBLE);
  185. $arr[] = 'abc';
  186. }
  187. /**
  188. * @expectedException PHPUnit_Framework_Error
  189. */
  190. public function testDoubleSetStringFail()
  191. {
  192. $arr = new RepeatedField(GPBType::DOUBLE);
  193. $arr[] = 0.0;
  194. $arr[0] = 'abc';
  195. }
  196. /**
  197. * @expectedException PHPUnit_Framework_Error
  198. */
  199. public function testDoubleAppendMessageFail()
  200. {
  201. $arr = new RepeatedField(GPBType::DOUBLE);
  202. $arr[] = new Sub();
  203. }
  204. /**
  205. * @expectedException PHPUnit_Framework_Error
  206. */
  207. public function testDoubleSetMessageFail()
  208. {
  209. $arr = new RepeatedField(GPBType::DOUBLE);
  210. $arr[] = 0.0;
  211. $arr[0] = new Sub();
  212. }
  213. /**
  214. * @expectedException PHPUnit_Framework_Error
  215. */
  216. public function testBoolAppendMessageFail()
  217. {
  218. $arr = new RepeatedField(GPBType::BOOL);
  219. $arr[] = new Sub();
  220. }
  221. /**
  222. * @expectedException PHPUnit_Framework_Error
  223. */
  224. public function testBoolSetMessageFail()
  225. {
  226. $arr = new RepeatedField(GPBType::BOOL);
  227. $arr[] = true;
  228. $arr[0] = new Sub();
  229. }
  230. /**
  231. * @expectedException PHPUnit_Framework_Error
  232. */
  233. public function testStringAppendMessageFail()
  234. {
  235. $arr = new RepeatedField(GPBType::STRING);
  236. $arr[] = new Sub();
  237. }
  238. /**
  239. * @expectedException PHPUnit_Framework_Error
  240. */
  241. public function testStringSetMessageFail()
  242. {
  243. $arr = new RepeatedField(GPBType::STRING);
  244. $arr[] = 'abc';
  245. $arr[0] = new Sub();
  246. }
  247. /**
  248. * @expectedException PHPUnit_Framework_Error
  249. */
  250. public function testStringAppendInvalidUTF8Fail()
  251. {
  252. $arr = new RepeatedField(GPBType::STRING);
  253. $hex = hex2bin("ff");
  254. $arr[] = $hex;
  255. }
  256. /**
  257. * @expectedException PHPUnit_Framework_Error
  258. */
  259. public function testStringSetInvalidUTF8Fail()
  260. {
  261. $arr = new RepeatedField(GPBType::STRING);
  262. $arr[] = 'abc';
  263. $hex = hex2bin("ff");
  264. $arr[0] = $hex;
  265. }
  266. /**
  267. * @expectedException PHPUnit_Framework_Error
  268. */
  269. public function testMessageAppendIntFail()
  270. {
  271. $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
  272. $arr[] = 1;
  273. }
  274. /**
  275. * @expectedException PHPUnit_Framework_Error
  276. */
  277. public function testMessageSetIntFail()
  278. {
  279. $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
  280. $arr[] = new Sub;
  281. $arr[0] = 'abc';
  282. }
  283. /**
  284. * @expectedException PHPUnit_Framework_Error
  285. */
  286. public function testMessageAppendStringFail()
  287. {
  288. $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
  289. $arr[] = 'abc';
  290. }
  291. /**
  292. * @expectedException PHPUnit_Framework_Error
  293. */
  294. public function testMessageSetStringFail()
  295. {
  296. $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
  297. $arr[] = new Sub;
  298. $arr[0] = 'abc';
  299. }
  300. /**
  301. * @expectedException PHPUnit_Framework_Error
  302. */
  303. public function testMessageAppendOtherMessageFail()
  304. {
  305. $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
  306. $arr[] = new TestMessage;
  307. }
  308. /**
  309. * @expectedException PHPUnit_Framework_Error
  310. */
  311. public function testMessageAppendNullFail()
  312. {
  313. $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
  314. $null = null;
  315. $arr[] = $null;
  316. }
  317. /**
  318. * @expectedException PHPUnit_Framework_Error
  319. */
  320. public function testMessageSetNullFail()
  321. {
  322. $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
  323. $arr[] = new Sub();
  324. $null = null;
  325. $arr[0] = $null;
  326. }
  327. /**
  328. * @expectedException PHPUnit_Framework_Error
  329. */
  330. public function testRemoveMiddleFail()
  331. {
  332. $arr = new RepeatedField(GPBType::INT32);
  333. $arr[] = 0;
  334. $arr[] = 1;
  335. $arr[] = 2;
  336. $this->assertSame(3, count($arr));
  337. unset($arr[1]);
  338. }
  339. /**
  340. * @expectedException PHPUnit_Framework_Error
  341. */
  342. public function testRemoveEmptyFail()
  343. {
  344. $arr = new RepeatedField(GPBType::INT32);
  345. unset($arr[0]);
  346. }
  347. /**
  348. * @expectedException PHPUnit_Framework_Error
  349. */
  350. public function testMessageOffsetFail()
  351. {
  352. $arr = new RepeatedField(GPBType::INT32);
  353. $arr[] = 0;
  354. $arr[new Sub()] = 0;
  355. }
  356. /**
  357. * @expectedException PHPUnit_Framework_Error
  358. */
  359. public function testStringOffsetFail()
  360. {
  361. $arr = new RepeatedField(GPBType::INT32);
  362. $arr[] = 0;
  363. $arr['abc'] = 0;
  364. }
  365. /**
  366. * @expectedException PHPUnit_Framework_Error
  367. */
  368. public function testSetNonExistedOffsetFail()
  369. {
  370. $arr = new RepeatedField(GPBType::INT32);
  371. $arr[0] = 0;
  372. }
  373. /**
  374. * @expectedException PHPUnit_Framework_Error
  375. */
  376. public function testInt32FieldInvalidTypeFail()
  377. {
  378. $m = new TestMessage();
  379. $m->setOptionalInt32(new TestMessage());
  380. }
  381. /**
  382. * @expectedException PHPUnit_Framework_Error
  383. */
  384. public function testInt32FieldInvalidStringFail()
  385. {
  386. $m = new TestMessage();
  387. $m->setOptionalInt32('abc');
  388. }
  389. /**
  390. * @expectedException PHPUnit_Framework_Error
  391. */
  392. public function testUint32FieldInvalidTypeFail()
  393. {
  394. $m = new TestMessage();
  395. $m->setOptionalUint32(new TestMessage());
  396. }
  397. /**
  398. * @expectedException PHPUnit_Framework_Error
  399. */
  400. public function testUint32FieldInvalidStringFail()
  401. {
  402. $m = new TestMessage();
  403. $m->setOptionalUint32('abc');
  404. }
  405. /**
  406. * @expectedException PHPUnit_Framework_Error
  407. */
  408. public function testInt64FieldInvalidTypeFail()
  409. {
  410. $m = new TestMessage();
  411. $m->setOptionalInt64(new TestMessage());
  412. }
  413. /**
  414. * @expectedException PHPUnit_Framework_Error
  415. */
  416. public function testInt64FieldInvalidStringFail()
  417. {
  418. $m = new TestMessage();
  419. $m->setOptionalInt64('abc');
  420. }
  421. /**
  422. * @expectedException PHPUnit_Framework_Error
  423. */
  424. public function testUint64FieldInvalidTypeFail()
  425. {
  426. $m = new TestMessage();
  427. $m->setOptionalUint64(new TestMessage());
  428. }
  429. /**
  430. * @expectedException PHPUnit_Framework_Error
  431. */
  432. public function testUint64FieldInvalidStringFail()
  433. {
  434. $m = new TestMessage();
  435. $m->setOptionalUint64('abc');
  436. }
  437. /**
  438. * @expectedException PHPUnit_Framework_Error
  439. */
  440. public function testFloatFieldInvalidTypeFail()
  441. {
  442. $m = new TestMessage();
  443. $m->setOptionalFloat(new TestMessage());
  444. }
  445. /**
  446. * @expectedException PHPUnit_Framework_Error
  447. */
  448. public function testFloatFieldInvalidStringFail()
  449. {
  450. $m = new TestMessage();
  451. $m->setOptionalFloat('abc');
  452. }
  453. /**
  454. * @expectedException PHPUnit_Framework_Error
  455. */
  456. public function testDoubleFieldInvalidTypeFail()
  457. {
  458. $m = new TestMessage();
  459. $m->setOptionalDouble(new TestMessage());
  460. }
  461. /**
  462. * @expectedException PHPUnit_Framework_Error
  463. */
  464. public function testDoubleFieldInvalidStringFail()
  465. {
  466. $m = new TestMessage();
  467. $m->setOptionalDouble('abc');
  468. }
  469. /**
  470. * @expectedException PHPUnit_Framework_Error
  471. */
  472. public function testBoolFieldInvalidStringFail()
  473. {
  474. $m = new TestMessage();
  475. $m->setOptionalBool(new TestMessage());
  476. }
  477. /**
  478. * @expectedException PHPUnit_Framework_Error
  479. */
  480. public function testStringFieldInvalidUTF8Fail()
  481. {
  482. $m = new TestMessage();
  483. $hex = hex2bin("ff");
  484. $m->setOptionalString($hex);
  485. }
  486. /**
  487. * @expectedException PHPUnit_Framework_Error
  488. */
  489. public function testMessageFieldWrongTypeFail()
  490. {
  491. $m = new TestMessage();
  492. $a = 1;
  493. $m->setOptionalMessage($a);
  494. }
  495. /**
  496. * @expectedException PHPUnit_Framework_Error
  497. */
  498. public function testMessageFieldWrongClassFail()
  499. {
  500. $m = new TestMessage();
  501. $m->setOptionalMessage(new TestMessage());
  502. }
  503. /**
  504. * @expectedException PHPUnit_Framework_Error
  505. */
  506. public function testRepeatedFieldWrongTypeFail()
  507. {
  508. $m = new TestMessage();
  509. $a = 1;
  510. $m->setRepeatedInt32($a);
  511. }
  512. /**
  513. * @expectedException PHPUnit_Framework_Error
  514. */
  515. public function testRepeatedFieldWrongObjectFail()
  516. {
  517. $m = new TestMessage();
  518. $m->setRepeatedInt32($m);
  519. }
  520. /**
  521. * @expectedException PHPUnit_Framework_Error
  522. */
  523. public function testRepeatedFieldWrongRepeatedTypeFail()
  524. {
  525. $m = new TestMessage();
  526. $repeated_int32 = new RepeatedField(GPBType::UINT32);
  527. $m->setRepeatedInt32($repeated_int32);
  528. }
  529. /**
  530. * @expectedException PHPUnit_Framework_Error
  531. */
  532. public function testRepeatedFieldWrongRepeatedMessageClassFail()
  533. {
  534. $m = new TestMessage();
  535. $repeated_message = new RepeatedField(GPBType::MESSAGE,
  536. TestMessage::class);
  537. $m->setRepeatedMessage($repeated_message);
  538. }
  539. /**
  540. * @expectedException PHPUnit_Framework_Error
  541. */
  542. public function testMapFieldWrongTypeFail()
  543. {
  544. $m = new TestMessage();
  545. $a = 1;
  546. $m->setMapInt32Int32($a);
  547. }
  548. /**
  549. * @expectedException PHPUnit_Framework_Error
  550. */
  551. public function testMapFieldWrongObjectFail()
  552. {
  553. $m = new TestMessage();
  554. $m->setMapInt32Int32($m);
  555. }
  556. /**
  557. * @expectedException PHPUnit_Framework_Error
  558. */
  559. public function testMapFieldWrongRepeatedTypeFail()
  560. {
  561. $m = new TestMessage();
  562. $map_uint32_uint32 = new MapField(GPBType::UINT32, GPBType::UINT32);
  563. $m->setMapInt32Int32($map_uint32_uint32);
  564. }
  565. /**
  566. * @expectedException PHPUnit_Framework_Error
  567. */
  568. public function testMapFieldWrongRepeatedMessageClassFail()
  569. {
  570. $m = new TestMessage();
  571. $map_int32_message = new MapField(GPBType::INT32,
  572. GPBType::MESSAGE,
  573. TestMessage::class);
  574. $m->setMapInt32Message($map_int32_message);
  575. }
  576. /**
  577. * @expectedException PHPUnit_Framework_Error
  578. */
  579. public function testMessageMergeFromInvalidTypeFail()
  580. {
  581. $m = new TestMessage();
  582. $n = new Sub();
  583. $m->mergeFrom($n);
  584. }
  585. /**
  586. * @expectedException PHPUnit_Framework_Error
  587. */
  588. public function testInt32SetStringKeyFail()
  589. {
  590. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  591. $arr['abc'] = 0;
  592. }
  593. /**
  594. * @expectedException PHPUnit_Framework_Error
  595. */
  596. public function testInt32SetStringValueFail()
  597. {
  598. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  599. $arr[0] = 'abc';
  600. }
  601. /**
  602. * @expectedException PHPUnit_Framework_Error
  603. */
  604. public function testInt32SetMessageKeyFail()
  605. {
  606. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  607. $arr[new Sub()] = 0;
  608. }
  609. /**
  610. * @expectedException PHPUnit_Framework_Error
  611. */
  612. public function testInt32SetMessageValueFail()
  613. {
  614. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  615. $arr[0] = new Sub();
  616. }
  617. /**
  618. * @expectedException PHPUnit_Framework_Error
  619. */
  620. public function testUint32SetStringKeyFail()
  621. {
  622. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  623. $arr['abc'] = 0;
  624. }
  625. /**
  626. * @expectedException PHPUnit_Framework_Error
  627. */
  628. public function testUint32SetStringValueFail()
  629. {
  630. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  631. $arr[0] = 'abc';
  632. }
  633. /**
  634. * @expectedException PHPUnit_Framework_Error
  635. */
  636. public function testUint32SetMessageKeyFail()
  637. {
  638. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  639. $arr[new Sub()] = 0;
  640. }
  641. /**
  642. * @expectedException PHPUnit_Framework_Error
  643. */
  644. public function testUint32SetMessageValueFail()
  645. {
  646. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  647. $arr[0] = new Sub();
  648. }
  649. /**
  650. * @expectedException PHPUnit_Framework_Error
  651. */
  652. public function testInt64SetStringKeyFail()
  653. {
  654. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  655. $arr['abc'] = 0;
  656. }
  657. /**
  658. * @expectedException PHPUnit_Framework_Error
  659. */
  660. public function testInt64SetStringValueFail()
  661. {
  662. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  663. $arr[0] = 'abc';
  664. }
  665. /**
  666. * @expectedException PHPUnit_Framework_Error
  667. */
  668. public function testInt64SetMessageKeyFail()
  669. {
  670. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  671. $arr[new Sub()] = 0;
  672. }
  673. /**
  674. * @expectedException PHPUnit_Framework_Error
  675. */
  676. public function testInt64SetMessageValueFail()
  677. {
  678. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  679. $arr[0] = new Sub();
  680. }
  681. /**
  682. * @expectedException PHPUnit_Framework_Error
  683. */
  684. public function testUint64SetStringKeyFail()
  685. {
  686. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  687. $arr['abc'] = 0;
  688. }
  689. /**
  690. * @expectedException PHPUnit_Framework_Error
  691. */
  692. public function testUint64SetStringValueFail()
  693. {
  694. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  695. $arr[0] = 'abc';
  696. }
  697. /**
  698. * @expectedException PHPUnit_Framework_Error
  699. */
  700. public function testUint64SetMessageKeyFail()
  701. {
  702. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  703. $arr[new Sub()] = 0;
  704. }
  705. /**
  706. * @expectedException PHPUnit_Framework_Error
  707. */
  708. public function testUint64SetMessageValueFail()
  709. {
  710. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  711. $arr[0] = new Sub();
  712. }
  713. /**
  714. * @expectedException PHPUnit_Framework_Error
  715. */
  716. public function testDoubleSetStringValueFail()
  717. {
  718. $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
  719. $arr[0] = 'abc';
  720. }
  721. /**
  722. * @expectedException PHPUnit_Framework_Error
  723. */
  724. public function testDoubleSetMessageValueFail()
  725. {
  726. $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
  727. $arr[0] = new Sub();
  728. }
  729. /**
  730. * @expectedException PHPUnit_Framework_Error
  731. */
  732. public function testBoolSetMessageKeyFail()
  733. {
  734. $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
  735. $arr[new Sub()] = true;
  736. }
  737. /**
  738. * @expectedException PHPUnit_Framework_Error
  739. */
  740. public function testBoolSetMessageValueFail()
  741. {
  742. $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
  743. $arr[true] = new Sub();
  744. }
  745. /**
  746. * @expectedException PHPUnit_Framework_Error
  747. */
  748. public function testStringSetInvalidUTF8KeyFail()
  749. {
  750. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  751. $arr[hex2bin("ff")] = 'abc';
  752. }
  753. /**
  754. * @expectedException PHPUnit_Framework_Error
  755. */
  756. public function testStringSetInvalidUTF8ValueFail()
  757. {
  758. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  759. $arr['abc'] = hex2bin("ff");
  760. }
  761. /**
  762. * @expectedException PHPUnit_Framework_Error
  763. */
  764. public function testStringSetMessageKeyFail()
  765. {
  766. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  767. $arr[new Sub()] = 'abc';
  768. }
  769. /**
  770. * @expectedException PHPUnit_Framework_Error
  771. */
  772. public function testStringSetMessageValueFail()
  773. {
  774. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  775. $arr['abc'] = new Sub();
  776. }
  777. /**
  778. * @expectedException PHPUnit_Framework_Error
  779. */
  780. public function testMessageSetIntValueFail()
  781. {
  782. $arr =
  783. new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
  784. $arr[0] = 0;
  785. }
  786. /**
  787. * @expectedException PHPUnit_Framework_Error
  788. */
  789. public function testMessageSetStringValueFail()
  790. {
  791. $arr =
  792. new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
  793. $arr[0] = 'abc';
  794. }
  795. /**
  796. * @expectedException PHPUnit_Framework_Error
  797. */
  798. public function testMessageSetOtherMessageValueFail()
  799. {
  800. $arr =
  801. new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
  802. $arr[0] = new Sub();
  803. }
  804. /**
  805. * @expectedException PHPUnit_Framework_Error
  806. */
  807. public function testMessageSetNullFail()
  808. {
  809. $arr =
  810. new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
  811. $null = NULL;
  812. $arr[0] = $null;
  813. }
  814. }