undefined_test.php 21 KB
Newer Older
1 2 3 4 5 6 7
<?php

require_once('test_util.php');

use Google\Protobuf\Internal\RepeatedField;
use Google\Protobuf\Internal\GPBType;
use Foo\TestMessage;
8
use Foo\TestMessage\Sub;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

class UndefinedTest extends PHPUnit_Framework_TestCase
{

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32AppendStringFail()
    {
        $arr = new RepeatedField(GPBType::INT32);
        $arr[] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32SetStringFail()
    {
        $arr = new RepeatedField(GPBType::INT32);
        $arr[] = 0;
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32AppendMessageFail()
    {
        $arr = new RepeatedField(GPBType::INT32);
38
        $arr[] = new Sub();
39 40 41 42 43 44 45 46 47
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32SetMessageFail()
    {
        $arr = new RepeatedField(GPBType::INT32);
        $arr[] = 0;
48
        $arr[0] = new Sub();
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32AppendStringFail()
    {
        $arr = new RepeatedField(GPBType::UINT32);
        $arr[] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32SetStringFail()
    {
        $arr = new RepeatedField(GPBType::UINT32);
        $arr[] = 0;
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32AppendMessageFail()
    {
        $arr = new RepeatedField(GPBType::UINT32);
76
        $arr[] = new Sub();
77 78 79 80 81 82 83 84 85
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32SetMessageFail()
    {
        $arr = new RepeatedField(GPBType::UINT32);
        $arr[] = 0;
86
        $arr[0] = new Sub();
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64AppendStringFail()
    {
        $arr = new RepeatedField(GPBType::INT64);
        $arr[] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64SetStringFail()
    {
        $arr = new RepeatedField(GPBType::INT64);
        $arr[] = 0;
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64AppendMessageFail()
    {
        $arr = new RepeatedField(GPBType::INT64);
114
        $arr[] = new Sub();
115 116 117 118 119 120 121 122 123
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64SetMessageFail()
    {
        $arr = new RepeatedField(GPBType::INT64);
        $arr[] = 0;
124
        $arr[0] = new Sub();
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64AppendStringFail()
    {
        $arr = new RepeatedField(GPBType::UINT64);
        $arr[] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64SetStringFail()
    {
        $arr = new RepeatedField(GPBType::UINT64);
        $arr[] = 0;
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64AppendMessageFail()
    {
        $arr = new RepeatedField(GPBType::UINT64);
152
        $arr[] = new Sub();
153 154 155 156 157 158 159 160 161
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64SetMessageFail()
    {
        $arr = new RepeatedField(GPBType::UINT64);
        $arr[] = 0;
162
        $arr[0] = new Sub();
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testFloatAppendStringFail()
    {
        $arr = new RepeatedField(GPBType::FLOAT);
        $arr[] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testFloatSetStringFail()
    {
        $arr = new RepeatedField(GPBType::FLOAT);
        $arr[] = 0.0;
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testFloatAppendMessageFail()
    {
        $arr = new RepeatedField(GPBType::FLOAT);
190
        $arr[] = new Sub();
191 192 193 194 195 196 197 198 199
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testFloatSetMessageFail()
    {
        $arr = new RepeatedField(GPBType::FLOAT);
        $arr[] = 0.0;
200
        $arr[0] = new Sub();
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testDoubleAppendStringFail()
    {
        $arr = new RepeatedField(GPBType::DOUBLE);
        $arr[] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testDoubleSetStringFail()
    {
        $arr = new RepeatedField(GPBType::DOUBLE);
        $arr[] = 0.0;
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testDoubleAppendMessageFail()
    {
        $arr = new RepeatedField(GPBType::DOUBLE);
228
        $arr[] = new Sub();
229 230 231 232 233 234 235 236 237
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testDoubleSetMessageFail()
    {
        $arr = new RepeatedField(GPBType::DOUBLE);
        $arr[] = 0.0;
238
        $arr[0] = new Sub();
239 240 241 242 243 244 245 246
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testBoolAppendMessageFail()
    {
        $arr = new RepeatedField(GPBType::BOOL);
247
        $arr[] = new Sub();
248 249 250 251 252 253 254 255 256
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testBoolSetMessageFail()
    {
        $arr = new RepeatedField(GPBType::BOOL);
        $arr[] = true;
257
        $arr[0] = new Sub();
258 259 260 261 262 263 264 265
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringAppendMessageFail()
    {
        $arr = new RepeatedField(GPBType::STRING);
266
        $arr[] = new Sub();
267 268 269 270 271 272 273 274 275
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringSetMessageFail()
    {
        $arr = new RepeatedField(GPBType::STRING);
        $arr[] = 'abc';
276
        $arr[0] = new Sub();
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringAppendInvalidUTF8Fail()
    {
        $arr = new RepeatedField(GPBType::STRING);
        $hex = hex2bin("ff");
        $arr[] = $hex;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringSetInvalidUTF8Fail()
    {
        $arr = new RepeatedField(GPBType::STRING);
        $arr[] = 'abc';
        $hex = hex2bin("ff");
        $arr[0] = $hex;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageAppendIntFail()
    {
305
        $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
306 307 308 309 310 311 312 313
        $arr[] = 1;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageSetIntFail()
    {
314 315
        $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
        $arr[] = new Sub;
316 317 318 319 320 321 322 323
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageAppendStringFail()
    {
324
        $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
325 326 327 328 329 330 331 332
        $arr[] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageSetStringFail()
    {
333 334
        $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
        $arr[] = new Sub;
335 336 337 338 339 340 341 342
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageAppendOtherMessageFail()
    {
343
        $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
344 345 346 347 348 349 350 351
        $arr[] = new TestMessage;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageAppendNullFail()
    {
352
        $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
353 354 355 356 357 358 359 360 361
        $null = null;
        $arr[] = $null;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageSetNullFail()
    {
362 363
        $arr = new RepeatedField(GPBType::MESSAGE, Sub::class);
        $arr[] = new Sub();
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
        $null = null;
        $arr[0] = $null;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testRemoveMiddleFail()
    {
        $arr = new RepeatedField(GPBType::INT32);

        $arr[] = 0;
        $arr[] = 1;
        $arr[] = 2;
        $this->assertSame(3, count($arr));

        unset($arr[1]);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testRemoveEmptyFail()
    {
        $arr = new RepeatedField(GPBType::INT32);

        unset($arr[0]);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageOffsetFail()
    {
        $arr = new RepeatedField(GPBType::INT32);
        $arr[] = 0;
400
        $arr[new Sub()] = 0;
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringOffsetFail()
    {
        $arr = new RepeatedField(GPBType::INT32);
        $arr[] = 0;
        $arr['abc'] = 0;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testSetNonExistedOffsetFail()
    {
        $arr = new RepeatedField(GPBType::INT32);
        $arr[0] = 0;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32FieldInvalidTypeFail()
    {
        $m = new TestMessage();
        $m->setOptionalInt32(new TestMessage());
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32FieldInvalidStringFail()
    {
        $m = new TestMessage();
        $m->setOptionalInt32('abc');
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32FieldInvalidTypeFail()
    {
        $m = new TestMessage();
        $m->setOptionalUint32(new TestMessage());
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32FieldInvalidStringFail()
    {
        $m = new TestMessage();
        $m->setOptionalUint32('abc');
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64FieldInvalidTypeFail()
    {
        $m = new TestMessage();
        $m->setOptionalInt64(new TestMessage());
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64FieldInvalidStringFail()
    {
        $m = new TestMessage();
        $m->setOptionalInt64('abc');
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64FieldInvalidTypeFail()
    {
        $m = new TestMessage();
        $m->setOptionalUint64(new TestMessage());
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64FieldInvalidStringFail()
    {
        $m = new TestMessage();
        $m->setOptionalUint64('abc');
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testFloatFieldInvalidTypeFail()
    {
        $m = new TestMessage();
        $m->setOptionalFloat(new TestMessage());
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testFloatFieldInvalidStringFail()
    {
        $m = new TestMessage();
        $m->setOptionalFloat('abc');
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testDoubleFieldInvalidTypeFail()
    {
        $m = new TestMessage();
        $m->setOptionalDouble(new TestMessage());
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testDoubleFieldInvalidStringFail()
    {
        $m = new TestMessage();
        $m->setOptionalDouble('abc');
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testBoolFieldInvalidStringFail()
    {
        $m = new TestMessage();
        $m->setOptionalBool(new TestMessage());
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringFieldInvalidUTF8Fail()
    {
        $m = new TestMessage();
        $hex = hex2bin("ff");
        $m->setOptionalString($hex);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageFieldWrongTypeFail()
    {
        $m = new TestMessage();
        $a = 1;
        $m->setOptionalMessage($a);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageFieldWrongClassFail()
    {
        $m = new TestMessage();
        $m->setOptionalMessage(new TestMessage());
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testRepeatedFieldWrongTypeFail()
    {
        $m = new TestMessage();
        $a = 1;
        $m->setRepeatedInt32($a);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testRepeatedFieldWrongObjectFail()
    {
        $m = new TestMessage();
        $m->setRepeatedInt32($m);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testRepeatedFieldWrongRepeatedTypeFail()
    {
        $m = new TestMessage();

        $repeated_int32 = new RepeatedField(GPBType::UINT32);
        $m->setRepeatedInt32($repeated_int32);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testRepeatedFieldWrongRepeatedMessageClassFail()
    {
        $m = new TestMessage();

        $repeated_message = new RepeatedField(GPBType::MESSAGE,
                                              TestMessage::class);
        $m->setRepeatedMessage($repeated_message);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMapFieldWrongTypeFail()
    {
        $m = new TestMessage();
        $a = 1;
        $m->setMapInt32Int32($a);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMapFieldWrongObjectFail()
    {
        $m = new TestMessage();
        $m->setMapInt32Int32($m);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMapFieldWrongRepeatedTypeFail()
    {
        $m = new TestMessage();

        $map_uint32_uint32 = new MapField(GPBType::UINT32, GPBType::UINT32);
        $m->setMapInt32Int32($map_uint32_uint32);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMapFieldWrongRepeatedMessageClassFail()
    {
        $m = new TestMessage();

        $map_int32_message = new MapField(GPBType::INT32,
                                          GPBType::MESSAGE,
                                          TestMessage::class);
        $m->setMapInt32Message($map_int32_message);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageMergeFromInvalidTypeFail()
    {
        $m = new TestMessage();
659
        $n = new Sub();
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
        $m->mergeFrom($n);
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32SetStringKeyFail()
    {
        $arr = new MapField(GPBType::INT32, GPBType::INT32);
        $arr['abc'] = 0;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32SetStringValueFail()
    {
        $arr = new MapField(GPBType::INT32, GPBType::INT32);
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32SetMessageKeyFail()
    {
        $arr = new MapField(GPBType::INT32, GPBType::INT32);
687
        $arr[new Sub()] = 0;
688 689 690 691 692 693 694 695
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt32SetMessageValueFail()
    {
        $arr = new MapField(GPBType::INT32, GPBType::INT32);
696
        $arr[0] = new Sub();
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32SetStringKeyFail()
    {
        $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
        $arr['abc'] = 0;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32SetStringValueFail()
    {
        $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32SetMessageKeyFail()
    {
        $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
723
        $arr[new Sub()] = 0;
724 725 726 727 728 729 730 731
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint32SetMessageValueFail()
    {
        $arr = new MapField(GPBType::UINT32, GPBType::UINT32);
732
        $arr[0] = new Sub();
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64SetStringKeyFail()
    {
        $arr = new MapField(GPBType::INT64, GPBType::INT64);
        $arr['abc'] = 0;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64SetStringValueFail()
    {
        $arr = new MapField(GPBType::INT64, GPBType::INT64);
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64SetMessageKeyFail()
    {
        $arr = new MapField(GPBType::INT64, GPBType::INT64);
759
        $arr[new Sub()] = 0;
760 761 762 763 764 765 766 767
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testInt64SetMessageValueFail()
    {
        $arr = new MapField(GPBType::INT64, GPBType::INT64);
768
        $arr[0] = new Sub();
769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64SetStringKeyFail()
    {
        $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
        $arr['abc'] = 0;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64SetStringValueFail()
    {
        $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64SetMessageKeyFail()
    {
        $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
795
        $arr[new Sub()] = 0;
796 797 798 799 800 801 802 803
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testUint64SetMessageValueFail()
    {
        $arr = new MapField(GPBType::UINT64, GPBType::UINT64);
804
        $arr[0] = new Sub();
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testDoubleSetStringValueFail()
    {
        $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
        $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testDoubleSetMessageValueFail()
    {
        $arr = new MapField(GPBType::INT64, GPBType::DOUBLE);
822
        $arr[0] = new Sub();
823 824 825 826 827 828 829 830
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testBoolSetMessageKeyFail()
    {
        $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
831
        $arr[new Sub()] = true;
832 833 834 835 836 837 838 839
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testBoolSetMessageValueFail()
    {
        $arr = new MapField(GPBType::BOOL, GPBType::BOOL);
840
        $arr[true] = new Sub();
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringSetInvalidUTF8KeyFail()
    {
        $arr = new MapField(GPBType::STRING, GPBType::STRING);
        $arr[hex2bin("ff")] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringSetInvalidUTF8ValueFail()
    {
        $arr = new MapField(GPBType::STRING, GPBType::STRING);
        $arr['abc'] = hex2bin("ff");
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringSetMessageKeyFail()
    {
        $arr = new MapField(GPBType::STRING, GPBType::STRING);
867
        $arr[new Sub()] = 'abc';
868 869 870 871 872 873 874 875
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testStringSetMessageValueFail()
    {
        $arr = new MapField(GPBType::STRING, GPBType::STRING);
876
        $arr['abc'] = new Sub();
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageSetIntValueFail()
    {
       $arr =
           new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
       $arr[0] = 0;
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageSetStringValueFail()
    {
       $arr =
           new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
       $arr[0] = 'abc';
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
    public function testMessageSetOtherMessageValueFail()
    {
       $arr =
           new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
906
       $arr[0] = new Sub();
907 908 909 910 911
    }

    /**
     * @expectedException PHPUnit_Framework_Error
     */
912
    public function testMessageSetNullFailMap()
913 914 915 916 917 918 919 920
    {
       $arr =
           new MapField(GPBType::INT32, GPBType::MESSAGE, TestMessage::class);
       $null = NULL;
       $arr[0] = $null;
    }

}