map_field_test.php 20 KB

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