map_field_test.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. <?php
  2. require_once('test_util.php');
  3. use Google\Protobuf\Internal\GPBType;
  4. use Google\Protobuf\Internal\MapField;
  5. use Foo\TestMessage;
  6. use Foo\TestMessage_Sub;
  7. class MapFieldTest extends PHPUnit_Framework_TestCase {
  8. #########################################################
  9. # Test int32 field.
  10. #########################################################
  11. public function testInt32() {
  12. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  13. // Test integer argument.
  14. $arr[MAX_INT32] = MAX_INT32;
  15. $this->assertSame(MAX_INT32, $arr[MAX_INT32]);
  16. $arr[MIN_INT32] = MIN_INT32;
  17. $this->assertSame(MIN_INT32, $arr[MIN_INT32]);
  18. $this->assertEquals(2, count($arr));
  19. $this->assertTrue(isset($arr[MAX_INT32]));
  20. $this->assertTrue(isset($arr[MIN_INT32]));
  21. unset($arr[MAX_INT32]);
  22. unset($arr[MIN_INT32]);
  23. $this->assertEquals(0, count($arr));
  24. // Test float argument.
  25. $arr[1.9] = 1.9;
  26. $arr[2.1] = 2.1;
  27. $this->assertSame(1, $arr[1]);
  28. $this->assertSame(2, $arr[2]);
  29. $arr[MAX_INT32_FLOAT] = MAX_INT32_FLOAT;
  30. $this->assertSame(MAX_INT32, $arr[MAX_INT32]);
  31. $arr[MIN_INT32_FLOAT] = MIN_INT32_FLOAT;
  32. $this->assertSame(MIN_INT32, $arr[MIN_INT32]);
  33. $this->assertEquals(4, count($arr));
  34. unset($arr[1.9]);
  35. unset($arr[2.9]);
  36. unset($arr[MAX_INT32_FLOAT]);
  37. unset($arr[MIN_INT32_FLOAT]);
  38. $this->assertEquals(0, count($arr));
  39. // Test string argument.
  40. $arr['2'] = '2';
  41. $this->assertSame(2, $arr[2]);
  42. $arr['3.1'] = '3.1';
  43. $this->assertSame(3, $arr[3]);
  44. $arr[MAX_INT32_STRING] = MAX_INT32_STRING;
  45. $this->assertSame(MAX_INT32, $arr[MAX_INT32]);
  46. $this->assertEquals(3, count($arr));
  47. unset($arr['2']);
  48. unset($arr['3.1']);
  49. unset($arr[MAX_INT32_STRING]);
  50. $this->assertEquals(0, count($arr));
  51. }
  52. /**
  53. * @expectedException PHPUnit_Framework_Error
  54. */
  55. public function testInt32SetStringKeyFail()
  56. {
  57. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  58. $arr ['abc']= 0;
  59. }
  60. /**
  61. * @expectedException PHPUnit_Framework_Error
  62. */
  63. public function testInt32SetStringValueFail()
  64. {
  65. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  66. $arr [0]= 'abc';
  67. }
  68. /**
  69. * @expectedException PHPUnit_Framework_Error
  70. */
  71. public function testInt32SetMessageKeyFail()
  72. {
  73. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  74. $arr [new TestMessage_Sub()]= 0;
  75. }
  76. /**
  77. * @expectedException PHPUnit_Framework_Error
  78. */
  79. public function testInt32SetMessageValueFail()
  80. {
  81. $arr = new MapField(GPBType::INT32, GPBType::INT32);
  82. $arr [0]= new TestMessage_Sub();
  83. }
  84. #########################################################
  85. # Test uint32 field.
  86. #########################################################
  87. public function testUint32() {
  88. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  89. // Test integer argument.
  90. $arr[MAX_UINT32] = MAX_UINT32;
  91. $this->assertSame(-1, $arr[-1]);
  92. $this->assertEquals(1, count($arr));
  93. unset($arr[MAX_UINT32]);
  94. $this->assertEquals(0, count($arr));
  95. $arr[-1] = -1;
  96. $this->assertSame(-1, $arr[-1]);
  97. $arr[MIN_UINT32] = MIN_UINT32;
  98. $this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
  99. $this->assertEquals(2, count($arr));
  100. unset($arr[-1]);
  101. unset($arr[MIN_UINT32]);
  102. $this->assertEquals(0, count($arr));
  103. // Test float argument.
  104. $arr[MAX_UINT32_FLOAT] = MAX_UINT32_FLOAT;
  105. $this->assertSame(-1, $arr[-1]);
  106. $this->assertEquals(1, count($arr));
  107. unset($arr[MAX_UINT32_FLOAT]);
  108. $this->assertEquals(0, count($arr));
  109. $arr[3.1] = 3.1;
  110. $this->assertSame(3, $arr[3]);
  111. $arr[-1.0] = -1.0;
  112. $this->assertSame(-1, $arr[-1]);
  113. $arr[MIN_UINT32_FLOAT] = MIN_UINT32_FLOAT;
  114. $this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
  115. $this->assertEquals(3, count($arr));
  116. unset($arr[3.1]);
  117. unset($arr[-1.0]);
  118. unset($arr[MIN_UINT32_FLOAT]);
  119. $this->assertEquals(0, count($arr));
  120. // Test string argument.
  121. $arr[MAX_UINT32_STRING] = MAX_UINT32_STRING;
  122. $this->assertSame(-1, $arr[-1]);
  123. $this->assertEquals(1, count($arr));
  124. unset($arr[MAX_UINT32_STRING]);
  125. $this->assertEquals(0, count($arr));
  126. $arr['7'] = '7';
  127. $this->assertSame(7, $arr[7]);
  128. $arr['3.1'] = '3.1';
  129. $this->assertSame(3, $arr[3]);
  130. $arr['-1.0'] = '-1.0';
  131. $this->assertSame(-1, $arr[-1]);
  132. $arr[MIN_UINT32_STRING] = MIN_UINT32_STRING;
  133. $this->assertSame(MIN_UINT32, $arr[MIN_UINT32]);
  134. $this->assertEquals(4, count($arr));
  135. unset($arr['7']);
  136. unset($arr['3.1']);
  137. unset($arr['-1.0']);
  138. unset($arr[MIN_UINT32_STRING]);
  139. $this->assertEquals(0, count($arr));
  140. }
  141. /**
  142. * @expectedException PHPUnit_Framework_Error
  143. */
  144. public function testUint32SetStringKeyFail()
  145. {
  146. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  147. $arr ['abc']= 0;
  148. }
  149. /**
  150. * @expectedException PHPUnit_Framework_Error
  151. */
  152. public function testUint32SetStringValueFail()
  153. {
  154. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  155. $arr [0]= 'abc';
  156. }
  157. /**
  158. * @expectedException PHPUnit_Framework_Error
  159. */
  160. public function testUint32SetMessageKeyFail()
  161. {
  162. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  163. $arr [new TestMessage_Sub()]= 0;
  164. }
  165. /**
  166. * @expectedException PHPUnit_Framework_Error
  167. */
  168. public function testUint32SetMessageValueFail()
  169. {
  170. $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
  171. $arr [0]= new TestMessage_Sub();
  172. }
  173. #########################################################
  174. # Test int64 field.
  175. #########################################################
  176. public function testInt64() {
  177. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  178. // Test integer argument.
  179. $arr[MAX_INT64] = MAX_INT64;
  180. $arr[MIN_INT64] = MIN_INT64;
  181. if (PHP_INT_SIZE == 4) {
  182. $this->assertSame(MAX_INT64_STRING, $arr[MAX_INT64_STRING]);
  183. $this->assertSame(MIN_INT64_STRING, $arr[MIN_INT64_STRING]);
  184. } else {
  185. $this->assertSame(MAX_INT64, $arr[MAX_INT64]);
  186. $this->assertSame(MIN_INT64, $arr[MIN_INT64]);
  187. }
  188. $this->assertEquals(2, count($arr));
  189. unset($arr[MAX_INT64]);
  190. unset($arr[MIN_INT64]);
  191. $this->assertEquals(0, count($arr));
  192. // Test float argument.
  193. $arr[1.1] = 1.1;
  194. if (PHP_INT_SIZE == 4) {
  195. $this->assertSame('1', $arr['1']);
  196. } else {
  197. $this->assertSame(1, $arr[1]);
  198. }
  199. $this->assertEquals(1, count($arr));
  200. unset($arr[1.1]);
  201. $this->assertEquals(0, count($arr));
  202. // Test string argument.
  203. $arr['2'] = '2';
  204. $arr['3.1'] = '3.1';
  205. $arr[MAX_INT64_STRING] = MAX_INT64_STRING;
  206. $arr[MIN_INT64_STRING] = MIN_INT64_STRING;
  207. if (PHP_INT_SIZE == 4) {
  208. $this->assertSame('2', $arr['2']);
  209. $this->assertSame('3', $arr['3']);
  210. $this->assertSame(MAX_INT64_STRING, $arr[MAX_INT64_STRING]);
  211. $this->assertSame(MIN_INT64_STRING, $arr[MIN_INT64_STRING]);
  212. } else {
  213. $this->assertSame(2, $arr[2]);
  214. $this->assertSame(3, $arr[3]);
  215. $this->assertSame(MAX_INT64, $arr[MAX_INT64]);
  216. $this->assertSame(MIN_INT64, $arr[MIN_INT64]);
  217. }
  218. $this->assertEquals(4, count($arr));
  219. unset($arr['2']);
  220. unset($arr['3.1']);
  221. unset($arr[MAX_INT64_STRING]);
  222. unset($arr[MIN_INT64_STRING]);
  223. $this->assertEquals(0, count($arr));
  224. }
  225. /**
  226. * @expectedException PHPUnit_Framework_Error
  227. */
  228. public function testInt64SetStringKeyFail()
  229. {
  230. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  231. $arr ['abc']= 0;
  232. }
  233. /**
  234. * @expectedException PHPUnit_Framework_Error
  235. */
  236. public function testInt64SetStringValueFail()
  237. {
  238. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  239. $arr [0]= 'abc';
  240. }
  241. /**
  242. * @expectedException PHPUnit_Framework_Error
  243. */
  244. public function testInt64SetMessageKeyFail()
  245. {
  246. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  247. $arr [new TestMessage_Sub()]= 0;
  248. }
  249. /**
  250. * @expectedException PHPUnit_Framework_Error
  251. */
  252. public function testInt64SetMessageValueFail()
  253. {
  254. $arr = new MapField(GPBType::INT64, GPBType::INT64);
  255. $arr [0]= new TestMessage_Sub();
  256. }
  257. #########################################################
  258. # Test uint64 field.
  259. #########################################################
  260. public function testUint64() {
  261. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  262. // Test integer argument.
  263. $arr[MAX_UINT64] = MAX_UINT64;
  264. if (PHP_INT_SIZE == 4) {
  265. $this->assertSame(MAX_UINT64_STRING, $arr[MAX_UINT64_STRING]);
  266. } else {
  267. $this->assertSame(MAX_UINT64, $arr[MAX_UINT64]);
  268. }
  269. $this->assertEquals(1, count($arr));
  270. unset($arr[MAX_UINT64]);
  271. $this->assertEquals(0, count($arr));
  272. // Test float argument.
  273. $arr[1.1] = 1.1;
  274. if (PHP_INT_SIZE == 4) {
  275. $this->assertSame('1', $arr['1']);
  276. } else {
  277. $this->assertSame(1, $arr[1]);
  278. }
  279. $this->assertEquals(1, count($arr));
  280. unset($arr[1.1]);
  281. $this->assertEquals(0, count($arr));
  282. // Test string argument.
  283. $arr['2'] = '2';
  284. $arr['3.1'] = '3.1';
  285. $arr[MAX_UINT64_STRING] = MAX_UINT64_STRING;
  286. if (PHP_INT_SIZE == 4) {
  287. $this->assertSame('2', $arr['2']);
  288. $this->assertSame('3', $arr['3']);
  289. $this->assertSame(MAX_UINT64_STRING, $arr[MAX_UINT64_STRING]);
  290. } else {
  291. $this->assertSame(2, $arr[2]);
  292. $this->assertSame(3, $arr[3]);
  293. $this->assertSame(MAX_UINT64, $arr[MAX_UINT64]);
  294. }
  295. $this->assertEquals(3, count($arr));
  296. unset($arr['2']);
  297. unset($arr['3.1']);
  298. unset($arr[MAX_UINT64_STRING]);
  299. $this->assertEquals(0, count($arr));
  300. }
  301. /**
  302. * @expectedException PHPUnit_Framework_Error
  303. */
  304. public function testUint64SetStringKeyFail()
  305. {
  306. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  307. $arr ['abc']= 0;
  308. }
  309. /**
  310. * @expectedException PHPUnit_Framework_Error
  311. */
  312. public function testUint64SetStringValueFail()
  313. {
  314. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  315. $arr [0]= 'abc';
  316. }
  317. /**
  318. * @expectedException PHPUnit_Framework_Error
  319. */
  320. public function testUint64SetMessageKeyFail()
  321. {
  322. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  323. $arr [new TestMessage_Sub()]= 0;
  324. }
  325. /**
  326. * @expectedException PHPUnit_Framework_Error
  327. */
  328. public function testUint64SetMessageValueFail()
  329. {
  330. $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
  331. $arr [0]= new TestMessage_Sub();
  332. }
  333. #########################################################
  334. # Test float field.
  335. #########################################################
  336. public function testFloat() {
  337. $arr = new MapField(GPBType::INT32, GPBType::FLOAT);
  338. // Test set.
  339. $arr[0] = 1;
  340. $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF);
  341. $arr[1] = 1.1;
  342. $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF);
  343. $arr[2] = '2';
  344. $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF);
  345. $arr[3] = '3.1';
  346. $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF);
  347. $this->assertEquals(4, count($arr));
  348. }
  349. /**
  350. * @expectedException PHPUnit_Framework_Error
  351. */
  352. public function testFloatSetStringValueFail()
  353. {
  354. $arr = new MapField(GPBType::INT64, GPBType::FLOAT);
  355. $arr [0]= 'abc';
  356. }
  357. /**
  358. * @expectedException PHPUnit_Framework_Error
  359. */
  360. public function testFloatSetMessageValueFail()
  361. {
  362. $arr = new MapField(GPBType::INT64, GPBType::FLOAT);
  363. $arr [0]= new TestMessage_Sub();
  364. }
  365. #########################################################
  366. # Test double field.
  367. #########################################################
  368. public function testDouble() {
  369. $arr = new MapField(GPBType::INT32, GPBType::DOUBLE);
  370. // Test set.
  371. $arr[0] = 1;
  372. $this->assertEquals(1.0, $arr[0], '', MAX_FLOAT_DIFF);
  373. $arr[1] = 1.1;
  374. $this->assertEquals(1.1, $arr[1], '', MAX_FLOAT_DIFF);
  375. $arr[2] = '2';
  376. $this->assertEquals(2.0, $arr[2], '', MAX_FLOAT_DIFF);
  377. $arr[3] = '3.1';
  378. $this->assertEquals(3.1, $arr[3], '', MAX_FLOAT_DIFF);
  379. $this->assertEquals(4, count($arr));
  380. }
  381. /**
  382. * @expectedException PHPUnit_Framework_Error
  383. */
  384. public function testDoubleSetStringValueFail()
  385. {
  386. $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
  387. $arr [0]= 'abc';
  388. }
  389. /**
  390. * @expectedException PHPUnit_Framework_Error
  391. */
  392. public function testDoubleSetMessageValueFail()
  393. {
  394. $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
  395. $arr [0]= new TestMessage_Sub();
  396. }
  397. #########################################################
  398. # Test bool field.
  399. #########################################################
  400. public function testBool() {
  401. $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
  402. // Test boolean.
  403. $arr[True] = True;
  404. $this->assertSame(True, $arr[True]);
  405. $this->assertEquals(1, count($arr));
  406. unset($arr[True]);
  407. $this->assertEquals(0, count($arr));
  408. $arr[False] = False;
  409. $this->assertSame(False, $arr[False]);
  410. $this->assertEquals(1, count($arr));
  411. unset($arr[False]);
  412. $this->assertEquals(0, count($arr));
  413. // Test integer.
  414. $arr[-1] = -1;
  415. $this->assertSame(True, $arr[True]);
  416. $this->assertEquals(1, count($arr));
  417. unset($arr[-1]);
  418. $this->assertEquals(0, count($arr));
  419. $arr[0] = 0;
  420. $this->assertSame(False, $arr[False]);
  421. $this->assertEquals(1, count($arr));
  422. unset($arr[0]);
  423. $this->assertEquals(0, count($arr));
  424. // Test float.
  425. $arr[1.1] = 1.1;
  426. $this->assertSame(True, $arr[True]);
  427. $this->assertEquals(1, count($arr));
  428. unset($arr[1.1]);
  429. $this->assertEquals(0, count($arr));
  430. $arr[0.0] = 0.0;
  431. $this->assertSame(False, $arr[False]);
  432. $this->assertEquals(1, count($arr));
  433. unset($arr[0.0]);
  434. $this->assertEquals(0, count($arr));
  435. // Test string.
  436. $arr['a'] = 'a';
  437. $this->assertSame(True, $arr[True]);
  438. $this->assertEquals(1, count($arr));
  439. unset($arr['a']);
  440. $this->assertEquals(0, count($arr));
  441. $arr[''] = '';
  442. $this->assertSame(False, $arr[False]);
  443. $this->assertEquals(1, count($arr));
  444. unset($arr['']);
  445. $this->assertEquals(0, count($arr));
  446. }
  447. /**
  448. * @expectedException PHPUnit_Framework_Error
  449. */
  450. public function testBoolSetMessageKeyFail()
  451. {
  452. $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
  453. $arr [new TestMessage_Sub()]= true;
  454. }
  455. /**
  456. * @expectedException PHPUnit_Framework_Error
  457. */
  458. public function testBoolSetMessageValueFail()
  459. {
  460. $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
  461. $arr [true]= new TestMessage_Sub();
  462. }
  463. #########################################################
  464. # Test string field.
  465. #########################################################
  466. public function testString() {
  467. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  468. // Test set.
  469. $arr['abc'] = 'abc';
  470. $this->assertSame('abc', $arr['abc']);
  471. $this->assertEquals(1, count($arr));
  472. unset($arr['abc']);
  473. $this->assertEquals(0, count($arr));
  474. $arr[1] = 1;
  475. $this->assertSame('1', $arr['1']);
  476. $this->assertEquals(1, count($arr));
  477. unset($arr[1]);
  478. $this->assertEquals(0, count($arr));
  479. $arr[1.1] = 1.1;
  480. $this->assertSame('1.1', $arr['1.1']);
  481. $this->assertEquals(1, count($arr));
  482. unset($arr[1.1]);
  483. $this->assertEquals(0, count($arr));
  484. $arr[True] = True;
  485. $this->assertSame('1', $arr['1']);
  486. $this->assertEquals(1, count($arr));
  487. unset($arr[True]);
  488. $this->assertEquals(0, count($arr));
  489. }
  490. /**
  491. * @expectedException PHPUnit_Framework_Error
  492. */
  493. public function testStringSetInvalidUTF8KeyFail()
  494. {
  495. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  496. $arr[hex2bin("ff")]= 'abc';
  497. }
  498. /**
  499. * @expectedException PHPUnit_Framework_Error
  500. */
  501. public function testStringSetInvalidUTF8ValueFail()
  502. {
  503. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  504. $arr ['abc']= hex2bin("ff");
  505. }
  506. /**
  507. * @expectedException PHPUnit_Framework_Error
  508. */
  509. public function testStringSetMessageKeyFail()
  510. {
  511. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  512. $arr [new TestMessage_Sub()]= 'abc';
  513. }
  514. /**
  515. * @expectedException PHPUnit_Framework_Error
  516. */
  517. public function testStringSetMessageValueFail()
  518. {
  519. $arr = new MapField(GPBType::STRING, GPBType::STRING);
  520. $arr ['abc']= new TestMessage_Sub();
  521. }
  522. #########################################################
  523. # Test message field.
  524. #########################################################
  525. public function testMessage() {
  526. $arr = new MapField(GPBType::INT32,
  527. GPBType::MESSAGE, TestMessage_Sub::class);
  528. // Test append.
  529. $sub_m = new TestMessage_Sub();
  530. $sub_m->setA(1);
  531. $arr[0] = $sub_m;
  532. $this->assertSame(1, $arr[0]->getA());
  533. $null = NULL;
  534. $arr[1] = $null;
  535. $this->assertNull($arr[1]);
  536. $this->assertEquals(2, count($arr));
  537. }
  538. /**
  539. * @expectedException PHPUnit_Framework_Error
  540. */
  541. public function testMessageSetIntValueFail()
  542. {
  543. $arr =
  544. new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
  545. $arr[0] = 0;
  546. }
  547. /**
  548. * @expectedException PHPUnit_Framework_Error
  549. */
  550. public function testMessageSetStringValueFail()
  551. {
  552. $arr =
  553. new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
  554. $arr[0] = 'abc';
  555. }
  556. /**
  557. * @expectedException PHPUnit_Framework_Error
  558. */
  559. public function testMessageSetOtherMessageValueFail()
  560. {
  561. $arr =
  562. new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
  563. $arr[0] = new TestMessage_Sub();
  564. }
  565. #########################################################
  566. # Test memory leak
  567. #########################################################
  568. // TODO(teboring): Add it back.
  569. // public function testCycleLeak()
  570. // {
  571. // $arr = new MapField(GPBType::INT32,
  572. // GPBType::MESSAGE, TestMessage::class);
  573. // $arr [0]= new TestMessage;
  574. // $arr[0]->SetMapRecursive($arr);
  575. // // Clean up memory before test.
  576. // gc_collect_cycles();
  577. // $start = memory_get_usage();
  578. // unset($arr);
  579. // // Explicitly trigger garbage collection.
  580. // gc_collect_cycles();
  581. // $end = memory_get_usage();
  582. // $this->assertLessThan($start, $end);
  583. // }
  584. }