Best Atoum code snippet using in.testRead
InputExtTest.php
Source:InputExtTest.php
1<?php2/**3 * efxphp (http://emilmalinov.com/efxphp)4 *5 * @copyright Copyright (c) 2015 Emil Malinov6 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.07 * @link http://github.com/emilkm/efxphp8 * @package efxphp9 */10namespace emilkm\tests\efxphp\Amf;11use emilkm\tests\util\InvokeMethodTrait;12use emilkm\efxphp\Amf\Constants;13use emilkm\efxphp\Amf\InputExt;14use stdClass;15/**16 * @author Emil Malinov17 * @package efxphp18 * @subpackage tests19 */20class InputExtTest extends \PHPUnit_Framework_TestCase21{22 use InvokeMethodTrait;23 protected $in;24 protected $request;25 protected function setUp()26 {27 $this->in = new InputExt();28 }29 /**30 *31 */32 public function testreadAmf0Number()33 {34 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/number.amf0'));35 $this->in->setData($data);36 $obj = $this->in->readObject();37 $this->assertEquals(31.57, $obj->value);38 }39 /**40 *41 */42 public function testreadAmf0Boolean()43 {44 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/boolean.amf0'));45 $this->in->setData($data);46 $obj = $this->in->readObject();47 $this->assertEquals(true, $obj->value);48 }49 /**50 *51 */52 public function testreadAmf0DateToEfxphpDate()53 {54 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date.amf0'));55 $this->in->setData($data);56 $this->in->setUseRlandDateType(true);57 $obj = $this->in->readObject();58 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Date', $obj->value);59 $this->assertEquals(1422995025, $obj->value->timestamp);60 $this->assertEquals(123, $obj->value->milli);61 }62 /**63 *64 */65 public function testreadAmf0DateToPhpDateTime()66 {67 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date.amf0'));68 $this->in->setData($data);69 $this->in->setUseRlandDateType(false);70 $obj = $this->in->readObject();71 $this->assertInstanceOf('DateTime', $obj->value);72 $this->assertEquals(1422995025, $obj->value->getTimestamp());73 $this->assertEquals(123, floor($obj->value->format('u') / 1000));74 }75 /**76 *77 */78 public function testreadAmf0String()79 {80 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string.amf0'));81 $this->in->setData($data);82 $obj = $this->in->readObject();83 $this->assertEquals('abc', $obj->value);84 }85 /**86 *87 */88 public function testreadAmf0StringBlank()89 {90 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string-blank.amf0'));91 $this->in->setData($data);92 $obj = $this->in->readObject();93 $this->assertEquals('', $obj->value);94 }95 /**96 *97 */98 public function testreadAmf0StringUnicode()99 {100 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string-unicode.amf0'));101 $this->in->setData($data);102 $obj = $this->in->readObject();103 $this->assertEquals('виÑоÑа', $obj->value);104 }105 /**106 *107 */108 public function testreadAmf0Null()109 {110 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/null.amf0'));111 $this->in->setData($data);112 $obj = $this->in->readObject();113 $this->assertEquals(null, $obj->value);114 }115 /**116 *117 */118 public function testreadAmf0ArrayEmpty()119 {120 $exp = array();121 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-empty.amf0'));122 $this->in->setData($data);123 $obj = $this->in->readObject();124 $this->assertEquals($exp, $obj);125 }126 /**127 * Undefined entries in the sparse regions between indices are serialized as undefined.128 * Undefined entries in the sparse regions between indices are skipped when deserialized.129 */130 public function testreadAmf0ArrayDense()131 {132 $exp = array();133 $exp[0] = 'a';134 $exp[1] = 'b';135 $exp[2] = 'c';136 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-dense.amf0'));137 $this->in->setData($data);138 $obj = $this->in->readObject();139 $this->assertEquals($exp, $obj);140 }141 /**142 * Undefined entries in the sparse regions between indices are serialized as undefined.143 * Undefined entries in the sparse regions between indices are skipped when deserialized.144 */145 public function testreadAmf0ArraySparse()146 {147 $exp = array();148 $exp[0] = 'a';149 $exp[2] = 'b';150 $exp[4] = 'c';151 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-sparse.amf0'));152 $this->in->setData($data);153 $obj = $this->in->readObject();154 $this->assertEquals($exp, $obj);155 }156 /**157 *158 */159 public function testreadAmf0ArrayString()160 {161 $exp = new stdClass();162 $exp->a = 1;163 $exp->b = 2;164 $exp->c = 3;165 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-string.amf0'));166 $this->in->setData($data);167 $obj = $this->in->readObject();168 $this->assertEquals($exp, $obj);169 }170 /**171 *172 */173 public function testreadAmf0ArrayMixed()174 {175 $exp = array();176 $exp[0] = 'a';177 $exp['b'] = 2;178 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-mixed.amf0'));179 $this->in->setData($data);180 $obj = $this->in->readObject();181 $this->assertEquals($exp, $obj);182 }183 /**184 *185 */186 public function testreadAmf0ArrayNegative()187 {188 $exp = array();189 $exp[-1] = 'a';190 $exp[0] = 'b';191 $exp[1] = 'c';192 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-negative.amf0'));193 $this->in->setData($data);194 $obj = $this->in->readObject();195 $this->assertEquals($exp, $obj);196 }197 /**198 *199 */200 public function testreadAmf0ArrayNested()201 {202 $exp = new stdClass();203 $exp->items = array();204 $exp->items[0] = 'a';205 $exp->items[1] = 'b';206 $exp->items[2] = 'c';207 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-nested.amf0'));208 $this->in->setData($data);209 $obj = $this->in->readObject();210 $this->assertEquals($exp, $obj);211 }212 /**213 *214 */215 public function testreadAmf0ObjectAnonymous()216 {217 $exp = new stdClass();218 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-anonymous.amf0'));219 $this->in->setData($data);220 $obj = $this->in->readObject();221 $this->assertEquals($exp, $obj);222 }223 /**224 *225 */226 public function testreadAmf0ObjectTypedToStdClass()227 {228 $exp = new stdClass();229 $remoteClassField = Constants::REMOTE_CLASS_FIELD;230 $exp->$remoteClassField = 'SomeClass';231 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-someclass.amf0'));232 $this->in->setData($data);233 $obj = $this->in->readObject();234 $this->assertEquals($exp, $obj);235 }236 /**237 *238 */239 public function testreadAmf0ObjectTypedFromNamespace()240 {241 $exp = new \emilkm\tests\asset\value\VoExplicitTypeNotSet();242 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-explicit-from-namespace.amf0'));243 $this->in->setData($data);244 $obj = $this->in->readObject();245 $this->assertEquals($exp, $obj);246 }247 /**248 *249 */250 public function testreadAmf0ObjectTypedFromField()251 {252 $exp = new \emilkm\tests\asset\value\VoExplicitTypeNotBlank();253 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-explicit-from-field.amf0'));254 $this->in->setData($data);255 $obj = $this->in->readObject();256 $this->assertEquals($exp, $obj);257 }258 /**259 *260 */261 /*public function testreadAmf0XmlToEfxphpXml()262 {263 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xml.amf0'));264 $this->in->setData($data);265 $this->in->setUseRlandXmlType(true);266 $obj = $this->in->readObject();267 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value);268 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value->data);269 }*/270 /**271 *272 */273 /*public function testreadAmf0XmlToSimpleXMLElement()274 {275 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmlelement.amf0'));276 $this->in->setData($data);277 $this->in->setUseRlandXmlType(false);278 $obj = $this->in->readObject();279 $this->assertInstanceOf('SimpleXMLElement', $obj->value);280 $xmlstring = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value->asXML()));281 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring);282 }*/283 /**284 *285 */286 /*public function testreadAmf0XmlDocumentFromEfxphpXmlDocument()287 {288 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmldocument.amf0'));289 $this->in->setData($data);290 $this->in->setUseRlandXmlType(true);291 $obj = $this->in->readObject();292 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value);293 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value->data);294 }*/295 /**296 *297 */298 /*public function testreadAmf0XmlDocumentFromDOMElement()299 {300 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/domelement.amf0'));301 $this->in->setData($data);302 $this->in->setUseRlandXmlType(false);303 $obj = $this->in->readObject();304 $this->assertInstanceOf('SimpleXMLElement', $obj->value);305 $xmlstring = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value->asXML()));306 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring);307 }*/308 //##########################################################################309 // AMF3310 //##########################################################################311 /**312 * TODO:313 */314 public function testreadAmf3Undefined()315 {316 }317 /**318 *319 */320 public function testreadAmf3Null()321 {322 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/null.amf3'));323 $this->in->setData($data);324 $obj = $this->in->readObject();325 $this->assertEquals(null, $obj->value);326 }327 /**328 *329 */330 public function testreadAmf3BooleanTrue()331 {332 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/boolean-true.amf3'));333 $this->in->setData($data);334 $obj = $this->in->readObject();335 $this->assertEquals(true, $obj->value);336 }337 /**338 *339 */340 public function testreadAmf3BooleanFalse()341 {342 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/boolean-false.amf3'));343 $this->in->setData($data);344 $obj = $this->in->readObject();345 $this->assertEquals(false, $obj->value);346 }347 /**348 *349 */350 public function testreadAmf3Integer()351 {352 $exp = new stdClass();353 $exp->value = 123;354 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/integer.amf3'));355 $this->in->setData($data);356 $obj = $this->in->readObject();357 $this->assertEquals(123, $obj->value);358 }359 /**360 *361 */362 public function testreadAmf3Double()363 {364 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/double.amf3'));365 $this->in->setData($data);366 $obj = $this->in->readObject();367 $this->assertEquals(31.57, $obj->value);368 }369 /**370 *371 */372 public function testreadeAmf3String()373 {374 $exp = new stdClass();375 $exp->value = 'abc';376 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string.amf3'));377 $this->in->setData($data);378 $obj = $this->in->readObject();379 $this->assertEquals('abc', $obj->value);380 }381 /**382 *383 */384 public function testreadAmf3StringBlank()385 {386 $exp = new stdClass();387 $exp->value = '';388 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string-blank.amf3'));389 $this->in->setData($data);390 $obj = $this->in->readObject();391 $this->assertEquals($exp, $obj);392 }393 /**394 *395 */396 public function testreadAmf3StringUnicode()397 {398 $exp = new stdClass();399 $exp->value = 'виÑоÑа';400 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string-unicode.amf3'));401 $this->in->setData($data);402 $obj = $this->in->readObject();403 $this->assertEquals($exp, $obj);404 }405 /**406 *407 */408 public function testreadAmf3DateToEfxphpDate()409 {410 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date.amf3'));411 $this->in->setData($data);412 $obj = $this->in->readObject();413 $this->in->setUseRlandDateType(true);414 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Date', $obj->value);415 $this->assertEquals(1422995025, $obj->value->timestamp);416 $this->assertEquals(123, $obj->value->milli);417 }418 /**419 *420 */421 public function testreadAmf3DateToPhpDateTime()422 {423 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date.amf3'));424 $this->in->setData($data);425 $this->in->setUseRlandDateType(false);426 $obj = $this->in->readObject();427 $this->assertInstanceOf('DateTime', $obj->value);428 $this->assertEquals(1422995025, $obj->value->getTimestamp());429 $this->assertEquals(123, floor($obj->value->format('u') / 1000));430 }431 /**432 *433 */434 public function testreadAmf3DateAndReferenceToEfxphpDate()435 {436 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date-and-reference.amf3'));437 $this->in->setData($data);438 $obj = $this->in->readObject();439 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Date', $obj->value1);440 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Date', $obj->value2);441 $this->assertEquals(1422995025, $obj->value1->timestamp);442 $this->assertEquals(123, $obj->value1->milli);443 $this->assertEquals(1422995025, $obj->value2->timestamp);444 $this->assertEquals(123, $obj->value2->milli);445 }446 /**447 *448 */449 public function testreadAmf3DateAndReferenceToPhpDateTime()450 {451 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date-and-reference.amf3'));452 $this->in->setData($data);453 $this->in->setUseRlandDateType(false);454 $obj = $this->in->readObject();455 $this->assertInstanceOf('DateTime', $obj->value1);456 $this->assertInstanceOf('DateTime', $obj->value2);457 $this->assertEquals(1422995025, $obj->value1->getTimestamp());458 $this->assertEquals(123, floor($obj->value1->format('u') / 1000));459 $this->assertEquals(1422995025, $obj->value2->getTimestamp());460 $this->assertEquals(123, floor($obj->value2->format('u') / 1000));461 }462 /**463 *464 */465 public function testreadAmf3ArrayEmpty()466 {467 $exp = array();468 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-empty.amf3'));469 $this->in->setData($data);470 $obj = $this->in->readObject();471 $this->assertEquals($exp, $obj);472 }473 /**474 *475 */476 public function testreadAmf3ArrayDense()477 {478 $exp = array();479 $exp[0] = 'a';480 $exp[1] = 'b';481 $exp[2] = 'c';482 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-dense.amf3'));483 $this->in->setData($data);484 $obj = $this->in->readObject();485 $this->assertEquals($exp, $obj);486 }487 /**488 *489 */490 public function testreadAmf3ArraySparseAsObject()491 {492 $exp = new stdClass();493 $exp->{'0'} = 'a';494 $exp->{'2'} = 'b';495 $exp->{'4'} = 'c';496 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-sparse-as-object.amf3'));497 $this->in->setData($data);498 $obj = $this->in->readObject();499 $this->assertEquals($exp, $obj);500 }501 /**502 *503 */504 public function testreadAmf3ArraySparseAsAssoc()505 {506 $exp = array();507 $exp['0'] = 'a';508 $exp['2'] = 'b';509 $exp['4'] = 'c';510 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-sparse-as-assoc.amf3'));511 $this->in->setData($data);512 $obj = $this->in->readObject();513 $this->assertEquals($exp, $obj);514 }515 /**516 *517 */518 public function testreadAmf3ArrayStringAsObject()519 {520 $exp = new stdClass();521 $exp->a = 1;522 $exp->b = 2;523 $exp->c = 3;524 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-string-as-object.amf3'));525 $this->in->setData($data);526 $obj = $this->in->readObject();527 $this->assertEquals($exp, $obj);528 }529 /**530 *531 */532 public function testreadAmf3ArrayStringAsAssoc()533 {534 $exp = array();535 $exp['a'] = 1;536 $exp['b'] = 2;537 $exp['c'] = 3;538 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-string-as-assoc.amf3'));539 $this->in->setData($data);540 $obj = $this->in->readObject();541 $this->assertEquals($exp, $obj);542 }543 /**544 *545 */546 public function testreadAmf3ArrayMixedAsObject()547 {548 $exp = new stdClass();549 $exp->{'b'} = 2;550 $exp->{'0'} = 'a';551 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-mixed-as-object.amf3'));552 $this->in->setData($data);553 $obj = $this->in->readObject();554 $this->assertEquals($exp, $obj);555 }556 /**557 *558 */559 public function testreadAmf3ArrayMixedAsAssoc()560 {561 $exp = array();562 $exp['b'] = 2;563 $exp[0] = 'a';564 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-mixed-as-assoc.amf3'));565 $this->in->setData($data);566 $obj = $this->in->readObject();567 $this->assertEquals($exp, $obj);568 }569 /**570 *571 */572 public function testreadAmf3ArrayNegativeAsObject()573 {574 $exp = new stdClass();575 $exp->{'-1'} = 'a';576 $exp->{'0'} = 'b';577 $exp->{'1'} = 'c';578 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-negative-as-object.amf3'));579 $this->in->setData($data);580 $obj = $this->in->readObject();581 $this->assertEquals($exp, $obj);582 }583 /**584 *585 */586 public function testreadAmf3ArrayNegativeAsAssoc()587 {588 $exp = array();589 $exp['-1'] = 'a';590 $exp['0'] = 'b';591 $exp['1'] = 'c';592 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-negative-as-assoc.amf3'));593 $this->in->setData($data);594 $obj = $this->in->readObject();595 $this->assertEquals($exp, $obj);596 }597 /**598 *599 */600 public function testreadAmf3ArrayNestedAsObject()601 {602 $exp = new stdClass();603 $exp->{'items'} = array();604 $exp->{'items'}[0] = 'a';605 $exp->{'items'}[1] = 'b';606 $exp->{'items'}[2] = 'c';607 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-nested-as-object.amf3'));608 $this->in->setData($data);609 $obj = $this->in->readObject();610 //$this->assertEquals($exp, $obj); //TODO: assertion fails in preg_match611 }612 /**613 *614 */615 public function testreadAmf3ArrayNestedAsAssoc()616 {617 $exp = array();618 $exp['items'] = array();619 $exp['items'][0] = 'a';620 $exp['items'][1] = 'b';621 $exp['items'][2] = 'c';622 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-nested-as-assoc.amf3'));623 $this->in->setData($data);624 $obj = $this->in->readObject();625 $this->assertEquals($exp, $obj);626 }627 /**628 *629 */630 public function testreadAmf3ObjectAnonymous()631 {632 $exp = new stdClass();633 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-anonymous.amf3'));634 $this->in->setData($data);635 $obj = $this->in->readObject();636 $this->assertEquals($exp, $obj);637 }638 /**639 *640 */641 public function testreadAmf3ObjectTypedToStdClass()642 {643 $exp = new stdClass();644 $remoteClassField = Constants::REMOTE_CLASS_FIELD;645 $exp->$remoteClassField = 'SomeClass';646 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-someclass.amf3'));647 $this->in->setData($data);648 $obj = $this->in->readObject();649 $this->assertEquals($exp, $obj);650 }651 /**652 *653 */654 public function testreadAmf3ObjectTypedFromNamespace()655 {656 $exp = new \emilkm\tests\asset\value\VoExplicitTypeNotSet();657 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-explicit-from-namespace.amf3'));658 $this->in->setData($data);659 $obj = $this->in->readObject();660 $this->assertEquals($exp, $obj);661 }662 /**663 *664 */665 public function testreadAmf3ObjectFromTypedFromField()666 {667 $exp = new \emilkm\tests\asset\value\VoExplicitTypeNotBlank();668 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-explicit-from-field.amf3'));669 $this->in->setData($data);670 $obj = $this->in->readObject();671 $this->assertEquals($exp, $obj);672 }673 /**674 *675 */676 public function testreadAmf3ObjectTypedFromFieldAndTraitsReference()677 {678 $remoteClassField = Constants::REMOTE_CLASS_FIELD;679 $v1 = new stdClass();680 $v1->$remoteClassField = 'LightClass';681 $v1->id = 1;682 $v1->name = 'a';683 $v2 = new stdClass();684 $v2->$remoteClassField = 'LightClass';685 $v2->id = 2;686 $v2->name = 'b';687 $exp = new stdClass();688 $exp->value = array($v1, $v2);689 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-lightclass-and-traits-reference.amf3'));690 $this->in->setData($data);691 $obj = $this->in->readObject();692 $this->assertEquals($exp, $obj);693 }694 /**695 *696 */697 public function testreadAmf3ObjectFromFieldAndTraitsReferenceMissingProperty()698 {699 $remoteClassField = Constants::REMOTE_CLASS_FIELD;700 $v1 = new stdClass();701 $v1->$remoteClassField = 'LightClass';702 $v1->id = 1;703 $v1->name = 'a';704 $v2 = new stdClass();705 $v2->$remoteClassField = 'LightClass';706 $v2->id = 2;707 //$v2->name = 'b'; //v2 is missing one of its properties708 $exp = new stdClass();709 $exp->value = array($v1, $v2);710 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-lightclass-and-traits-reference-missing-property.amf3'));711 $this->in->setData($data);712 $obj = $this->in->readObject();713 $this->assertEquals($exp, $obj);714 }715 /**716 *717 */718 public function testreadAmf3ByteArray()719 {720 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/bytearray.amf3'));721 $this->in->setData($data);722 $obj = $this->in->readObject();723 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\ByteArray', $obj->value);724 $this->assertEquals('1a2b3c', $obj->value->data);725 }726 /**727 *728 */729 public function testreadAmf3ByteArrayAndReference()730 {731 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/bytearray-and-reference.amf3'));732 $this->in->setData($data);733 $obj = $this->in->readObject();734 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\ByteArray', $obj->value1);735 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\ByteArray', $obj->value2);736 $this->assertEquals('1a2b3c', $obj->value1->data);737 $this->assertEquals('1a2b3c', $obj->value2->data);738 }739 /**740 *741 */742 /*public function testreadAmf3XmlToEfxphpXml()743 {744 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xml.amf3'));745 $this->in->setData($data);746 $this->in->setUseRlandXmlType(true);747 $obj = $this->in->readObject();748 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value);749 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value->data);750 }*/751 /**752 *753 */754 /*public function testreadAmf3XmlToSimpleXMLElement()755 {756 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmlelement.amf3'));757 $this->in->setData($data);758 $this->in->setUseRlandXmlType(false);759 $obj = $this->in->readObject();760 $this->assertInstanceOf('SimpleXMLElement', $obj->value);761 $xmlstring = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value->asXML()));762 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring);763 }*/764 /**765 *766 */767 /*public function testreadAmf3XmlToEfxphpXmlAndReference()768 {769 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xml-and-reference.amf3'));770 $this->in->setData($data);771 $this->in->setUseRlandXmlType(true);772 $obj = $this->in->readObject();773 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value1);774 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value2);775 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value1->data);776 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value2->data);777 }*/778 /**779 *780 */781 /*public function testreadAmf3XmlToSimpleXMLElementAndReference()782 {783 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmlelement-and-reference.amf3'));784 $this->in->setData($data);785 $this->in->setUseRlandXmlType(false);786 $obj = $this->in->readObject();787 $this->assertInstanceOf('SimpleXMLElement', $obj->value1);788 $this->assertInstanceOf('SimpleXMLElement', $obj->value2);789 $xmlstring1 = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value1->asXML()));790 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring1);791 $xmlstring2 = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value2->asXML()));792 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring2);793 }*/794 /**795 *796 */797 /*public function testreadAmf3XmlDocumentToEfxphpXmlDocument()798 {799 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmldocument.amf3'));800 $this->in->setData($data);801 $this->in->setUseRlandXmlDocumentType(true);802 $obj = $this->in->readObject();803 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\XmlDocument', $obj->value);804 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value->data);805 }*/806 /**807 *808 */809 /*public function testreadAmf3XmlDocumentToDOMElement()810 {811 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/domelement.amf3'));812 $this->in->setData($data);813 $this->in->setUseRlandXmlDocumentType(false);814 $obj = $this->in->readObject();815 $this->assertInstanceOf('DOMElement', $obj->value);816 $xmlstring = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value->ownerDocument->saveXML($obj->value)));817 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $xmlstring);818 }*/819 /**820 *821 */822 /*public function testreadAmf3XmlDocumentToEfxphpXmlDocumentAndReference()823 {824 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmldocument-and-reference.amf3'));825 $this->in->setData($data);826 $this->in->setUseRlandXmlDocumentType(true);827 $obj = $this->in->readObject();828 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\XmlDocument', $obj->value1);829 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\XmlDocument', $obj->value2);830 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value1->data);831 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value2->data);832 }*/833 /**834 *835 */836 /*public function testreadAmf3XmlDocumentToDOMElementAndReference()837 {838 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/domelement-and-reference.amf3'));839 $this->in->setData($data);840 $this->in->setUseRlandXmlDocumentType(false);841 $obj = $this->in->readObject();842 $this->assertInstanceOf('DOMElement', $obj->value1);843 $this->assertInstanceOf('DOMElement', $obj->value2);844 $xmlstring1 = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value1->ownerDocument->saveXML($obj->value1)));845 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $xmlstring1);846 $xmlstring2 = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value2->ownerDocument->saveXML($obj->value2)));847 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $xmlstring2);848 }*/849 /**850 *851 */852 public function testreadAmf3VectorInt()853 {854 $exp = array(1, 2, 3);855 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-int.amf3'));856 $this->in->setData($data);857 $obj = $this->in->readObject();858 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);859 $this->assertEquals(Constants::AMF3_VECTOR_INT, $obj->value->type);860 $this->assertEquals(false, $obj->value->fixed);861 $this->assertEquals($exp, $obj->value->data);862 }863 /**864 *865 */866 public function testreadAmf3VectorIntNegative()867 {868 $exp = array(-3, -2, -1);869 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-int-negative.amf3'));870 $this->in->setData($data);871 $obj = $this->in->readObject();872 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);873 $this->assertEquals(Constants::AMF3_VECTOR_INT, $obj->value->type);874 $this->assertEquals(false, $obj->value->fixed);875 $this->assertEquals($exp, $obj->value->data);876 }877 /**878 *879 */880 public function testreadAmf3VectorUint()881 {882 $exp = array(2147483647, 2147483648, 4294967295);883 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-uint.amf3'));884 $this->in->setData($data);885 $obj = $this->in->readObject();886 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);887 $this->assertEquals(Constants::AMF3_VECTOR_UINT, $obj->value->type);888 $this->assertEquals(false, $obj->value->fixed);889 $this->assertEquals($exp, $obj->value->data);890 }891 /**892 *893 */894 public function testreadAmf3VectorDouble()895 {896 $exp = array(-31.57, 0, 31.57);897 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-double.amf3'));898 $this->in->setData($data);899 $obj = $this->in->readObject();900 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);901 $this->assertEquals(Constants::AMF3_VECTOR_DOUBLE, $obj->value->type);902 $this->assertEquals(false, $obj->value->fixed);903 $this->assertEquals($exp, $obj->value->data);904 }905 /**906 *907 */908 public function testreadAmf3VectorObject()909 {910 $v1 = new stdClass();911 $v1->value = 1;912 $v2 = new stdClass();913 $v2->value = 2;914 $v3 = new stdClass();915 $v3->value = 3;916 $exp = array($v1, $v2, $v3);917 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-object.amf3'));918 $this->in->setData($data);919 $obj = $this->in->readObject();920 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);921 $this->assertEquals(Constants::AMF3_VECTOR_OBJECT, $obj->value->type);922 $this->assertEquals(false, $obj->value->fixed);923 $this->assertEquals($exp, $obj->value->data);924 }925 /**926 *927 */928 public function testreadAmf3VectorObjectAndReference()929 {930 $v1 = new stdClass();931 $v1->value = 1;932 $v2 = new stdClass();933 $v2->value = 2;934 $v3 = new stdClass();935 $v3->value = 3;936 $exp = new stdClass();937 $exp = array($v1, $v2, $v3);938 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-object-and-reference.amf3'));939 $this->in->setData($data);940 $obj = $this->in->readObject();941 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value1);942 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value2);943 $this->assertEquals(Constants::AMF3_VECTOR_OBJECT, $obj->value1->type);944 $this->assertEquals(Constants::AMF3_VECTOR_OBJECT, $obj->value2->type);945 $this->assertEquals(false, $obj->value1->fixed);946 $this->assertEquals(false, $obj->value2->fixed);947 $this->assertEquals($exp, $obj->value1->data);948 $this->assertEquals($exp, $obj->value2->data);949 }950 /**951 *952 */953 public function testreadAmf3ComplexObjectGraph()954 {955 $exp = new stdClass();956 $arr = array();957 $a = new stdClass();958 $a->name = 'a';959 $a->parent = null;960 $a->children = array();961 $arr[] = $a;962 $a1 = new stdClass();963 $a1->name = 'a1';964 $a1->parent = $a;965 $a1->children = null;966 $a->children[] = $a1;967 $b = new stdClass();968 $b->name = 'b';969 $b->parent = null;970 $b->children = array();971 $arr[] = $b;972 $b1 = new stdClass();973 $b1->name = 'b1';974 $b1->parent = $b;975 $b1->children = array();976 $b->children[] = $b1;977 $bb1 = new stdClass();978 $bb1->name = 'bb1';979 $bb1->parent = $b1;980 $bb1->children = array();981 $b1->children[] = $bb1;982 $exp->value = $arr;983 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/complex-object-graph.amf3'));984 $this->in->setData($data);985 $obj = $this->in->readObject();986 $this->assertEquals($exp, $obj);987 }988}...
InputTest.php
Source:InputTest.php
1<?php2/**3 * efxphp (http://emilmalinov.com/efxphp)4 *5 * @copyright Copyright (c) 2015 Emil Malinov6 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.07 * @link http://github.com/emilkm/efxphp8 * @package efxphp9 */10namespace emilkm\tests\efxphp\Amf;11use emilkm\tests\util\InvokeMethodTrait;12use emilkm\efxphp\Amf\Constants;13use emilkm\efxphp\Amf\Input;14use stdClass;15/**16 * @author Emil Malinov17 * @package efxphp18 * @subpackage tests19 */20class InputTest extends \PHPUnit_Framework_TestCase21{22 use InvokeMethodTrait;23 protected $in;24 protected $request;25 protected function setUp()26 {27 $this->in = new Input();28 }29 /**30 *31 */32 public function testreadAmf0Number()33 {34 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/number.amf0'));35 $this->in->setData($data);36 $obj = $this->in->readObject();37 $this->assertEquals(31.57, $obj->value);38 }39 /**40 *41 */42 public function testreadAmf0Boolean()43 {44 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/boolean.amf0'));45 $this->in->setData($data);46 $obj = $this->in->readObject();47 $this->assertEquals(true, $obj->value);48 }49 /**50 *51 */52 public function testreadAmf0DateToEfxphpDate()53 {54 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date.amf0'));55 $this->in->setData($data);56 $this->in->setUseRlandDateType(true);57 $obj = $this->in->readObject();58 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Date', $obj->value);59 $this->assertEquals(1422995025, $obj->value->timestamp);60 $this->assertEquals(123, $obj->value->milli);61 }62 /**63 *64 */65 public function testreadAmf0DateToPhpDateTime()66 {67 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date.amf0'));68 $this->in->setData($data);69 $this->in->setUseRlandDateType(false);70 $obj = $this->in->readObject();71 $this->assertInstanceOf('DateTime', $obj->value);72 $this->assertEquals(1422995025, $obj->value->getTimestamp());73 $this->assertEquals(123, floor($obj->value->format('u') / 1000));74 }75 /**76 *77 */78 public function testreadAmf0String()79 {80 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string.amf0'));81 $this->in->setData($data);82 $obj = $this->in->readObject();83 $this->assertEquals('abc', $obj->value);84 }85 /**86 *87 */88 public function testreadAmf0StringBlank()89 {90 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string-blank.amf0'));91 $this->in->setData($data);92 $obj = $this->in->readObject();93 $this->assertEquals('', $obj->value);94 }95 /**96 *97 */98 public function testreadAmf0StringUnicode()99 {100 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string-unicode.amf0'));101 $this->in->setData($data);102 $obj = $this->in->readObject();103 $this->assertEquals('виÑоÑа', $obj->value);104 }105 /**106 *107 */108 public function testreadAmf0Null()109 {110 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/null.amf0'));111 $this->in->setData($data);112 $obj = $this->in->readObject();113 $this->assertEquals(null, $obj->value);114 }115 /**116 *117 */118 public function testreadAmf0ArrayEmpty()119 {120 $exp = array();121 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-empty.amf0'));122 $this->in->setData($data);123 $obj = $this->in->readObject();124 $this->assertEquals($exp, $obj);125 }126 /**127 * Undefined entries in the sparse regions between indices are serialized as undefined.128 * Undefined entries in the sparse regions between indices are skipped when deserialized.129 */130 public function testreadAmf0ArrayDense()131 {132 $exp = array();133 $exp[0] = 'a';134 $exp[1] = 'b';135 $exp[2] = 'c';136 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-dense.amf0'));137 $this->in->setData($data);138 $obj = $this->in->readObject();139 $this->assertEquals($exp, $obj);140 }141 /**142 * Undefined entries in the sparse regions between indices are serialized as undefined.143 * Undefined entries in the sparse regions between indices are skipped when deserialized.144 */145 public function testreadAmf0ArraySparse()146 {147 $exp = array();148 $exp[0] = 'a';149 $exp[2] = 'b';150 $exp[4] = 'c';151 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-sparse.amf0'));152 $this->in->setData($data);153 $obj = $this->in->readObject();154 $this->assertEquals($exp, $obj);155 }156 /**157 *158 */159 public function testreadAmf0ArrayString()160 {161 $exp = new stdClass();162 $exp->a = 1;163 $exp->b = 2;164 $exp->c = 3;165 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-string.amf0'));166 $this->in->setData($data);167 $obj = $this->in->readObject();168 $this->assertEquals($exp, $obj);169 }170 /**171 *172 */173 public function testreadAmf0ArrayMixed()174 {175 $exp = array();176 $exp[0] = 'a';177 $exp['b'] = 2;178 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-mixed.amf0'));179 $this->in->setData($data);180 $obj = $this->in->readObject();181 $this->assertEquals($exp, $obj);182 }183 /**184 *185 */186 public function testreadAmf0ArrayNegative()187 {188 $exp = array();189 $exp[-1] = 'a';190 $exp[0] = 'b';191 $exp[1] = 'c';192 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-negative.amf0'));193 $this->in->setData($data);194 $obj = $this->in->readObject();195 $this->assertEquals($exp, $obj);196 }197 /**198 *199 */200 public function testreadAmf0ArrayNested()201 {202 $exp = new stdClass();203 $exp->items = array();204 $exp->items[0] = 'a';205 $exp->items[1] = 'b';206 $exp->items[2] = 'c';207 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-nested.amf0'));208 $this->in->setData($data);209 $obj = $this->in->readObject();210 $this->assertEquals($exp, $obj);211 }212 /**213 *214 */215 public function testreadAmf0ObjectAnonymous()216 {217 $exp = new stdClass();218 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-anonymous.amf0'));219 $this->in->setData($data);220 $obj = $this->in->readObject();221 $this->assertEquals($exp, $obj);222 }223 /**224 *225 */226 public function testreadAmf0ObjectTypedToStdClass()227 {228 $exp = new stdClass();229 $remoteClassField = Constants::REMOTE_CLASS_FIELD;230 $exp->$remoteClassField = 'SomeClass';231 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-someclass.amf0'));232 $this->in->setData($data);233 $obj = $this->in->readObject();234 $this->assertEquals($exp, $obj);235 }236 /**237 *238 */239 public function testreadAmf0ObjectTypedFromNamespace()240 {241 $exp = new \emilkm\tests\asset\value\VoExplicitTypeNotSet();242 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-explicit-from-namespace.amf0'));243 $this->in->setData($data);244 $obj = $this->in->readObject();245 $this->assertEquals($exp, $obj);246 }247 /**248 *249 */250 public function testreadAmf0ObjectTypedFromField()251 {252 $exp = new \emilkm\tests\asset\value\VoExplicitTypeNotBlank();253 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-explicit-from-field.amf0'));254 $this->in->setData($data);255 $obj = $this->in->readObject();256 $this->assertEquals($exp, $obj);257 }258 /**259 *260 */261 public function testreadAmf0XmlToEfxphpXml()262 {263 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xml.amf0'));264 $this->in->setData($data);265 $this->in->setUseRlandXmlType(true);266 $obj = $this->in->readObject();267 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value);268 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value->data);269 }270 /**271 *272 */273 public function testreadAmf0XmlToSimpleXMLElement()274 {275 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmlelement.amf0'));276 $this->in->setData($data);277 $this->in->setUseRlandXmlType(false);278 $obj = $this->in->readObject();279 $this->assertInstanceOf('SimpleXMLElement', $obj->value);280 $xmlstring = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value->asXML()));281 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring);282 }283 /**284 *285 */286 public function testreadAmf0XmlDocumentFromEfxphpXmlDocument()287 {288 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmldocument.amf0'));289 $this->in->setData($data);290 $this->in->setUseRlandXmlType(true);291 $obj = $this->in->readObject();292 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value);293 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value->data);294 }295 /**296 *297 */298 public function testreadAmf0XmlDocumentFromDOMElement()299 {300 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/domelement.amf0'));301 $this->in->setData($data);302 $this->in->setUseRlandXmlType(false);303 $obj = $this->in->readObject();304 $this->assertInstanceOf('SimpleXMLElement', $obj->value);305 $xmlstring = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value->asXML()));306 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring);307 }308 //##########################################################################309 // AMF3310 //##########################################################################311 /**312 * TODO:313 */314 public function testreadAmf3Undefined()315 {316 }317 /**318 *319 */320 public function testreadAmf3Null()321 {322 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/null.amf3'));323 $this->in->setData($data);324 $obj = $this->in->readObject();325 $this->assertEquals(null, $obj->value);326 }327 /**328 *329 */330 public function testreadAmf3BooleanTrue()331 {332 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/boolean-true.amf3'));333 $this->in->setData($data);334 $obj = $this->in->readObject();335 $this->assertEquals(true, $obj->value);336 }337 /**338 *339 */340 public function testreadAmf3BooleanFalse()341 {342 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/boolean-false.amf3'));343 $this->in->setData($data);344 $obj = $this->in->readObject();345 $this->assertEquals(false, $obj->value);346 }347 /**348 *349 */350 public function testreadAmf3Integer()351 {352 $exp = new stdClass();353 $exp->value = 123;354 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/integer.amf3'));355 $this->in->setData($data);356 $obj = $this->in->readObject();357 $this->assertEquals(123, $obj->value);358 }359 /**360 *361 */362 public function testreadAmf3Double()363 {364 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/double.amf3'));365 $this->in->setData($data);366 $obj = $this->in->readObject();367 $this->assertEquals(31.57, $obj->value);368 }369 /**370 *371 */372 public function testreadeAmf3String()373 {374 $exp = new stdClass();375 $exp->value = 'abc';376 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string.amf3'));377 $this->in->setData($data);378 $obj = $this->in->readObject();379 $this->assertEquals('abc', $obj->value);380 }381 /**382 *383 */384 public function testreadAmf3StringBlank()385 {386 $exp = new stdClass();387 $exp->value = '';388 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string-blank.amf3'));389 $this->in->setData($data);390 $obj = $this->in->readObject();391 $this->assertEquals($exp, $obj);392 }393 /**394 *395 */396 public function testreadAmf3StringUnicode()397 {398 $exp = new stdClass();399 $exp->value = 'виÑоÑа';400 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/string-unicode.amf3'));401 $this->in->setData($data);402 $obj = $this->in->readObject();403 $this->assertEquals($exp, $obj);404 }405 /**406 *407 */408 public function testreadAmf3DateToEfxphpDate()409 {410 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date.amf3'));411 $this->in->setData($data);412 $obj = $this->in->readObject();413 $this->in->setUseRlandDateType(true);414 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Date', $obj->value);415 $this->assertEquals(1422995025, $obj->value->timestamp);416 $this->assertEquals(123, $obj->value->milli);417 }418 /**419 *420 */421 public function testreadAmf3DateToPhpDateTime()422 {423 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date.amf3'));424 $this->in->setData($data);425 $this->in->setUseRlandDateType(false);426 $obj = $this->in->readObject();427 $this->assertInstanceOf('DateTime', $obj->value);428 $this->assertEquals(1422995025, $obj->value->getTimestamp());429 $this->assertEquals(123, floor($obj->value->format('u') / 1000));430 }431 /**432 *433 */434 public function testreadAmf3DateAndReferenceToEfxphpDate()435 {436 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date-and-reference.amf3'));437 $this->in->setData($data);438 $obj = $this->in->readObject();439 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Date', $obj->value1);440 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Date', $obj->value2);441 $this->assertEquals(1422995025, $obj->value1->timestamp);442 $this->assertEquals(123, $obj->value1->milli);443 $this->assertEquals(1422995025, $obj->value2->timestamp);444 $this->assertEquals(123, $obj->value2->milli);445 }446 /**447 *448 */449 public function testreadAmf3DateAndReferenceToPhpDateTime()450 {451 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/date-and-reference.amf3'));452 $this->in->setData($data);453 $this->in->setUseRlandDateType(false);454 $obj = $this->in->readObject();455 $this->assertInstanceOf('DateTime', $obj->value1);456 $this->assertInstanceOf('DateTime', $obj->value2);457 $this->assertEquals(1422995025, $obj->value1->getTimestamp());458 $this->assertEquals(123, floor($obj->value1->format('u') / 1000));459 $this->assertEquals(1422995025, $obj->value2->getTimestamp());460 $this->assertEquals(123, floor($obj->value2->format('u') / 1000));461 }462 /**463 *464 */465 public function testreadAmf3ArrayEmpty()466 {467 $exp = array();468 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-empty.amf3'));469 $this->in->setData($data);470 $obj = $this->in->readObject();471 $this->assertEquals($exp, $obj);472 }473 /**474 *475 */476 public function testreadAmf3ArrayDense()477 {478 $exp = array();479 $exp[0] = 'a';480 $exp[1] = 'b';481 $exp[2] = 'c';482 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-dense.amf3'));483 $this->in->setData($data);484 $obj = $this->in->readObject();485 $this->assertEquals($exp, $obj);486 }487 /**488 *489 */490 public function testreadAmf3ArraySparseAsObject()491 {492 $exp = new stdClass();493 $exp->{'0'} = 'a';494 $exp->{'2'} = 'b';495 $exp->{'4'} = 'c';496 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-sparse-as-object.amf3'));497 $this->in->setData($data);498 $obj = $this->in->readObject();499 $this->assertEquals($exp, $obj);500 }501 /**502 *503 */504 public function testreadAmf3ArraySparseAsAssoc()505 {506 $exp = array();507 $exp['0'] = 'a';508 $exp['2'] = 'b';509 $exp['4'] = 'c';510 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-sparse-as-assoc.amf3'));511 $this->in->setData($data);512 $obj = $this->in->readObject();513 $this->assertEquals($exp, $obj);514 }515 /**516 *517 */518 public function testreadAmf3ArrayStringAsObject()519 {520 $exp = new stdClass();521 $exp->a = 1;522 $exp->b = 2;523 $exp->c = 3;524 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-string-as-object.amf3'));525 $this->in->setData($data);526 $obj = $this->in->readObject();527 $this->assertEquals($exp, $obj);528 }529 /**530 *531 */532 public function testreadAmf3ArrayStringAsAssoc()533 {534 $exp = array();535 $exp['a'] = 1;536 $exp['b'] = 2;537 $exp['c'] = 3;538 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-string-as-assoc.amf3'));539 $this->in->setData($data);540 $obj = $this->in->readObject();541 $this->assertEquals($exp, $obj);542 }543 /**544 *545 */546 public function testreadAmf3ArrayMixedAsObject()547 {548 $exp = new stdClass();549 $exp->{'b'} = 2;550 $exp->{'0'} = 'a';551 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-mixed-as-object.amf3'));552 $this->in->setData($data);553 $obj = $this->in->readObject();554 $this->assertEquals($exp, $obj);555 }556 /**557 *558 */559 public function testreadAmf3ArrayMixedAsAssoc()560 {561 $exp = array();562 $exp['b'] = 2;563 $exp[0] = 'a';564 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-mixed-as-assoc.amf3'));565 $this->in->setData($data);566 $obj = $this->in->readObject();567 $this->assertEquals($exp, $obj);568 }569 /**570 *571 */572 public function testreadAmf3ArrayNegativeAsObject()573 {574 $exp = new stdClass();575 $exp->{'-1'} = 'a';576 $exp->{'0'} = 'b';577 $exp->{'1'} = 'c';578 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-negative-as-object.amf3'));579 $this->in->setData($data);580 $obj = $this->in->readObject();581 $this->assertEquals($exp, $obj);582 }583 /**584 *585 */586 public function testreadAmf3ArrayNegativeAsAssoc()587 {588 $exp = array();589 $exp['-1'] = 'a';590 $exp['0'] = 'b';591 $exp['1'] = 'c';592 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-negative-as-assoc.amf3'));593 $this->in->setData($data);594 $obj = $this->in->readObject();595 $this->assertEquals($exp, $obj);596 }597 /**598 *599 */600 public function testreadAmf3ArrayNestedAsObject()601 {602 $exp = new stdClass();603 $exp->{'items'} = array();604 $exp->{'items'}[0] = 'a';605 $exp->{'items'}[1] = 'b';606 $exp->{'items'}[2] = 'c';607 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-nested-as-object.amf3'));608 $this->in->setData($data);609 $obj = $this->in->readObject();610 $this->assertEquals($exp, $obj);611 }612 /**613 *614 */615 public function testreadAmf3ArrayNestedAsAssoc()616 {617 $exp = array();618 $exp['items'] = array();619 $exp['items'][0] = 'a';620 $exp['items'][1] = 'b';621 $exp['items'][2] = 'c';622 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/array-nested-as-assoc.amf3'));623 $this->in->setData($data);624 $obj = $this->in->readObject();625 $this->assertEquals($exp, $obj);626 }627 /**628 *629 */630 public function testreadAmf3ObjectAnonymous()631 {632 $exp = new stdClass();633 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-anonymous.amf3'));634 $this->in->setData($data);635 $obj = $this->in->readObject();636 $this->assertEquals($exp, $obj);637 }638 /**639 *640 */641 public function testreadAmf3ObjectTypedToStdClass()642 {643 $exp = new stdClass();644 $remoteClassField = Constants::REMOTE_CLASS_FIELD;645 $exp->$remoteClassField = 'SomeClass';646 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-someclass.amf3'));647 $this->in->setData($data);648 $obj = $this->in->readObject();649 $this->assertEquals($exp, $obj);650 }651 /**652 *653 */654 public function testreadAmf3ObjectTypedFromNamespace()655 {656 $exp = new \emilkm\tests\asset\value\VoExplicitTypeNotSet();657 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-explicit-from-namespace.amf3'));658 $this->in->setData($data);659 $obj = $this->in->readObject();660 $this->assertEquals($exp, $obj);661 }662 /**663 *664 */665 public function testreadAmf3ObjectTypedFromField()666 {667 $exp = new \emilkm\tests\asset\value\VoExplicitTypeNotBlank();668 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-explicit-from-field.amf3'));669 $this->in->setData($data);670 $obj = $this->in->readObject();671 $this->assertEquals($exp, $obj);672 }673 /**674 *675 */676 public function testreadAmf3TypedFromFieldAndTraitsReference()677 {678 $remoteClassField = Constants::REMOTE_CLASS_FIELD;679 $v1 = new stdClass();680 $v1->$remoteClassField = 'LightClass';681 $v1->id = 1;682 $v1->name = 'a';683 $v2 = new stdClass();684 $v2->$remoteClassField = 'LightClass';685 $v2->id = 2;686 $v2->name = 'b';687 $exp = new stdClass();688 $exp->value = array($v1, $v2);689 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-lightclass-and-traits-reference.amf3'));690 $this->in->setData($data);691 $obj = $this->in->readObject();692 $this->assertEquals($exp, $obj);693 }694 /**695 *696 */697 public function testreadAmf3ObjectTypedFromFieldAndTraitsReferenceMissingProperty()698 {699 $remoteClassField = Constants::REMOTE_CLASS_FIELD;700 $v1 = new stdClass();701 $v1->$remoteClassField = 'LightClass';702 $v1->id = 1;703 $v1->name = 'a';704 $v2 = new stdClass();705 $v2->$remoteClassField = 'LightClass';706 $v2->id = 2;707 //$v2->name = 'b'; //v2 is missing one of its properties708 $exp = new stdClass();709 $exp->value = array($v1, $v2);710 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/object-typed-lightclass-and-traits-reference-missing-property.amf3'));711 $this->in->setData($data);712 $obj = $this->in->readObject();713 $this->assertEquals($exp, $obj);714 }715 /**716 *717 */718 public function testreadAmf3ByteArray()719 {720 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/bytearray.amf3'));721 $this->in->setData($data);722 $obj = $this->in->readObject();723 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\ByteArray', $obj->value);724 $this->assertEquals('1a2b3c', $obj->value->data);725 }726 /**727 *728 */729 public function testreadAmf3ByteArrayAndReference()730 {731 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/bytearray-and-reference.amf3'));732 $this->in->setData($data);733 $obj = $this->in->readObject();734 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\ByteArray', $obj->value1);735 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\ByteArray', $obj->value2);736 $this->assertEquals('1a2b3c', $obj->value1->data);737 $this->assertEquals('1a2b3c', $obj->value2->data);738 }739 /**740 *741 */742 public function testreadAmf3XmlToEfxphpXml()743 {744 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xml.amf3'));745 $this->in->setData($data);746 $this->in->setUseRlandXmlType(true);747 $obj = $this->in->readObject();748 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value);749 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value->data);750 }751 /**752 *753 */754 public function testreadAmf3XmlToSimpleXMLElement()755 {756 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmlelement.amf3'));757 $this->in->setData($data);758 $this->in->setUseRlandXmlType(false);759 $obj = $this->in->readObject();760 $this->assertInstanceOf('SimpleXMLElement', $obj->value);761 $xmlstring = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value->asXML()));762 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring);763 }764 /**765 *766 */767 public function testreadAmf3XmlToEfxphpXmlAndReference()768 {769 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xml-and-reference.amf3'));770 $this->in->setData($data);771 $this->in->setUseRlandXmlType(true);772 $obj = $this->in->readObject();773 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value1);774 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Xml', $obj->value2);775 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value1->data);776 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value2->data);777 }778 /**779 *780 */781 public function testreadAmf3XmlToSimpleXMLElementAndReference()782 {783 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmlelement-and-reference.amf3'));784 $this->in->setData($data);785 $this->in->setUseRlandXmlType(false);786 $obj = $this->in->readObject();787 $this->assertInstanceOf('SimpleXMLElement', $obj->value1);788 $this->assertInstanceOf('SimpleXMLElement', $obj->value2);789 $xmlstring1 = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value1->asXML()));790 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring1);791 $xmlstring2 = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value2->asXML()));792 $this->assertEquals('<?xml version="1.0"?><x><string>abc</string><number>123</number></x>', $xmlstring2);793 }794 /**795 *796 */797 public function testreadAmf3XmlDocumentToEfxphpXmlDocument()798 {799 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmldocument.amf3'));800 $this->in->setData($data);801 $this->in->setUseRlandXmlDocumentType(true);802 $obj = $this->in->readObject();803 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\XmlDocument', $obj->value);804 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value->data);805 }806 /**807 *808 */809 public function testreadAmf3XmlDocumentToDOMElement()810 {811 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/domelement.amf3'));812 $this->in->setData($data);813 $this->in->setUseRlandXmlDocumentType(false);814 $obj = $this->in->readObject();815 $this->assertInstanceOf('DOMElement', $obj->value);816 $xmlstring = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value->ownerDocument->saveXML($obj->value)));817 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $xmlstring);818 }819 /**820 *821 */822 public function testreadAmf3XmlDocumentToEfxphpXmlDocumentAndReference()823 {824 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/xmldocument-and-reference.amf3'));825 $this->in->setData($data);826 $this->in->setUseRlandXmlDocumentType(true);827 $obj = $this->in->readObject();828 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\XmlDocument', $obj->value1);829 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\XmlDocument', $obj->value2);830 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value1->data);831 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $obj->value2->data);832 }833 /**834 *835 */836 public function testreadAmf3XmlDocumentToDOMElementAndReference()837 {838 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/domelement-and-reference.amf3'));839 $this->in->setData($data);840 $this->in->setUseRlandXmlDocumentType(false);841 $obj = $this->in->readObject();842 $this->assertInstanceOf('DOMElement', $obj->value1);843 $this->assertInstanceOf('DOMElement', $obj->value2);844 $xmlstring1 = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value1->ownerDocument->saveXML($obj->value1)));845 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $xmlstring1);846 $xmlstring2 = preg_replace('/\>(\n|\r|\r\n| |\t)*\</', '><', trim($obj->value2->ownerDocument->saveXML($obj->value2)));847 $this->assertEquals('<x><string>abc</string><number>123</number></x>', $xmlstring2);848 }849 /**850 *851 */852 public function testreadAmf3VectorInt()853 {854 $exp = array(1, 2, 3);855 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-int.amf3'));856 $this->in->setData($data);857 $obj = $this->in->readObject();858 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);859 $this->assertEquals(Constants::AMF3_VECTOR_INT, $obj->value->type);860 $this->assertEquals(false, $obj->value->fixed);861 $this->assertEquals($exp, $obj->value->data);862 }863 /**864 *865 */866 public function testreadAmf3VectorIntNegative()867 {868 $exp = array(-3, -2, -1);869 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-int-negative.amf3'));870 $this->in->setData($data);871 $obj = $this->in->readObject();872 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);873 $this->assertEquals(Constants::AMF3_VECTOR_INT, $obj->value->type);874 $this->assertEquals(false, $obj->value->fixed);875 $this->assertEquals($exp, $obj->value->data);876 }877 /**878 *879 */880 public function testreadAmf3VectorUint()881 {882 $exp = array(2147483647, 2147483648, 4294967295);883 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-uint.amf3'));884 $this->in->setData($data);885 $obj = $this->in->readObject();886 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);887 $this->assertEquals(Constants::AMF3_VECTOR_UINT, $obj->value->type);888 $this->assertEquals(false, $obj->value->fixed);889 $this->assertEquals($exp, $obj->value->data);890 }891 /**892 *893 */894 public function testreadAmf3VectorDouble()895 {896 $exp = array(-31.57, 0, 31.57);897 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-double.amf3'));898 $this->in->setData($data);899 $obj = $this->in->readObject();900 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);901 $this->assertEquals(Constants::AMF3_VECTOR_DOUBLE, $obj->value->type);902 $this->assertEquals(false, $obj->value->fixed);903 $this->assertEquals($exp, $obj->value->data);904 }905 /**906 *907 */908 public function testreadAmf3VectorObject()909 {910 $v1 = new stdClass();911 $v1->value = 1;912 $v2 = new stdClass();913 $v2->value = 2;914 $v3 = new stdClass();915 $v3->value = 3;916 $exp = array($v1, $v2, $v3);917 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-object.amf3'));918 $this->in->setData($data);919 $obj = $this->in->readObject();920 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value);921 $this->assertEquals(Constants::AMF3_VECTOR_OBJECT, $obj->value->type);922 $this->assertEquals(false, $obj->value->fixed);923 $this->assertEquals($exp, $obj->value->data);924 }925 /**926 *927 */928 public function testreadAmf3VectorObjectAndReference()929 {930 $v1 = new stdClass();931 $v1->value = 1;932 $v2 = new stdClass();933 $v2->value = 2;934 $v3 = new stdClass();935 $v3->value = 3;936 $exp = new stdClass();937 $exp = array($v1, $v2, $v3);938 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/vector-object-and-reference.amf3'));939 $this->in->setData($data);940 $obj = $this->in->readObject();941 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value1);942 $this->assertInstanceOf('emilkm\efxphp\Amf\Types\Vector', $obj->value2);943 $this->assertEquals(Constants::AMF3_VECTOR_OBJECT, $obj->value1->type);944 $this->assertEquals(Constants::AMF3_VECTOR_OBJECT, $obj->value2->type);945 $this->assertEquals(false, $obj->value1->fixed);946 $this->assertEquals(false, $obj->value2->fixed);947 $this->assertEquals($exp, $obj->value1->data);948 $this->assertEquals($exp, $obj->value2->data);949 }950 /**951 *952 */953 public function testreadAmf3ComplexObjectGraph()954 {955 $exp = new stdClass();956 $arr = array();957 $a = new stdClass();958 $a->name = 'a';959 $a->parent = null;960 $a->children = array();961 $arr[] = $a;962 $a1 = new stdClass();963 $a1->name = 'a1';964 $a1->parent = $a;965 $a1->children = null;966 $a->children[] = $a1;967 $b = new stdClass();968 $b->name = 'b';969 $b->parent = null;970 $b->children = array();971 $arr[] = $b;972 $b1 = new stdClass();973 $b1->name = 'b1';974 $b1->parent = $b;975 $b1->children = array();976 $b->children[] = $b1;977 $bb1 = new stdClass();978 $bb1->name = 'bb1';979 $bb1->parent = $b1;980 $bb1->children = array();981 $b1->children[] = $bb1;982 $exp->value = $arr;983 $data = unserialize(file_get_contents(__DIR__ . '/../../asset/value/complex-object-graph.amf3'));984 $this->in->setData($data);985 $obj = $this->in->readObject();986 $this->assertEquals($exp, $obj);987 }988}...
AbstractInputTest.php
Source:AbstractInputTest.php
1<?php2/**3 * efxphp (http://emilmalinov.com/efxphp)4 *5 * @copyright Copyright (c) 2015 Emil Malinov6 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.07 * @link http://github.com/emilkm/efxphp8 * @package efxphp9 */10namespace emilkm\tests\efxphp\Amf;11use emilkm\tests\util\AccessPropertyTrait;12use emilkm\efxphp\Amf\Constants;13/**14 * @author Emil Malinov15 * @package efxphp16 * @subpackage tests17 */18class AbstractInputTest extends \PHPUnit_Framework_TestCase19{20 use AccessPropertyTrait;21 protected $in;22 protected $request;23 protected function setUp()24 {25 $this->in = new BaseInput();26 $this->request = file_get_contents(__DIR__ . '/../../asset/request/pingCommandMessageWithPacketHeaders.amf');27 }28 /**29 *30 */31 public function testavmPlusDefaultIsFalse()32 {33 $this->assertEquals(false, $this->getPropertyValue($this->in, 'avmPlus'));34 }35 /**36 *37 */38 public function testuseRlandDateTypeDefaultIsTrue()39 {40 $this->assertEquals(true, $this->getPropertyValue($this->in, 'useRlandDateType'));41 }42 /**43 *44 */45 public function testsetUseRlandDateTypeToFalse()46 {47 $this->in->setUseRlandDateType(false);48 $this->assertEquals(false, $this->getPropertyValue($this->in, 'useRlandDateType'));49 }50 /**51 *52 */53 public function testuseRlandXmlTypeDefaultIsTrue()54 {55 $this->assertEquals(true, $this->getPropertyValue($this->in, 'useRlandXmlType'));56 }57 /**58 *59 */60 public function testsetUseRlandXmlTypeToFalse()61 {62 $this->in->setUseRlandXmlType(false);63 $this->assertEquals(false, $this->getPropertyValue($this->in, 'useRlandXmlType'));64 }65 /**66 *67 */68 public function testuseRlandXmlDocumentDefaultTypeIsTrue()69 {70 $this->assertEquals(true, $this->getPropertyValue($this->in, 'useRlandXmlDocumentType'));71 }72 /**73 *74 */75 public function testsetUseRlandXmlDocumentTypeToFalse()76 {77 $this->in->setUseRlandXmlDocumentType(false);78 $this->assertEquals(false, $this->getPropertyValue($this->in, 'useRlandXmlDocumentType'));79 }80 /**81 *82 */83 public function testsetDataSetsData()84 {85 $data = 'abc';86 $this->in->setData($data);87 $this->assertEquals($data, $this->getPropertyValue($this->in, 'data'));88 }89 /**90 *91 */92 public function testsetDataSetsLength()93 {94 $data = 'abc';95 $this->in->setData($data);96 $this->assertEquals(3, $this->getPropertyValue($this->in, 'length'));97 }98 /**99 *100 */101 public function testsetDataSetsPosition()102 {103 $data = 'abc';104 $this->in->setData($data);105 $this->assertEquals(0, $this->getPropertyValue($this->in, 'pos'));106 }107 /**108 * Read the avmPlus switch109 */110 public function testreadBytes()111 {112 $this->in->setData($this->request);113 $this->in->skipBytes(6);114 $value = $this->in->readBytes(6);115 $this->assertEquals('string', $value);116 $this->in->setData($this->request);117 $this->in->skipBytes(25);118 $value = $this->in->readBytes(6);119 $this->assertEquals('number', $value);120 }121 /**122 * Read the avmPlus switch123 */124 public function testreadByte()125 {126 $this->in->setData($this->request);127 $this->in->skipBytes(58);128 $value = $this->in->readByte();129 $this->assertEquals(Constants::AMF0_AMF3, $value);130 $this->in->setData($this->request);131 $this->in->skipBytes(82);132 $value = $this->in->readByte();133 $this->assertEquals(Constants::AMF0_AMF3, $value);134 }135 /**136 * Read the AMF packet headers mustUnderstand flags137 */138 public function testreadBoolean()139 {140 $this->in->setData($this->request);141 $this->in->skipBytes(12);142 $value = $this->in->readBoolean();143 $this->assertEquals(false, $value);144 $this->in->setData($this->request);145 $this->in->skipBytes(31);146 $value = $this->in->readBoolean();147 $this->assertEquals(true, $value);148 }149 /**150 * Read the AMF packet version151 */152 public function testreadShort()153 {154 $this->in->setData($this->request);155 $value = $this->in->readShort();156 $this->assertEquals(3, $value);157 }158 /**159 * Read the array length160 */161 public function testreadInt()162 {163 $this->in->setData($this->request);164 $this->in->skipBytes(177);165 $value = $this->in->readInt();166 $this->assertEquals(1, $value);167 }168 /**169 * Read number header value170 */171 public function testreadDouble()172 {173 $this->in->setData($this->request);174 $this->in->skipBytes(37);175 $value = $this->in->readDouble();176 $this->assertEquals(123, $value);177 }178 /**179 * Read the AMF packet headers names180 */181 public function testreadUtf()182 {183 $this->in->setData($this->request);184 $this->in->skipBytes(4);185 $value = $this->in->readUtf();186 $this->assertEquals('string', $value);187 $this->in->setData($this->request);188 $this->in->skipBytes(23);189 $value = $this->in->readUtf();190 $this->assertEquals('number', $value);191 }192}...
testRead
Using AI Code Generation
1$test = new TestClass();2echo $test->testRead();3$test = new TestClass();4echo $test->testRead();5Fatal error: Uncaught exception 'Exception' with message 'File is already open' in C:\xampp\htdocs\test\1.php:5 Stack trace: #0 C:\xampp\htdocs\test\1.php(5): TestClass->testRead() #1 {main} thrown in C:\xampp\htdocs\test\1.php on line 56class TestClass{7 private $file = "test.txt";8 private $handle;9 public function testRead(){10 if($this->handle = fopen($this->file, "r")){11 if(flock($this->handle, LOCK_EX)){12 $content = fread($this->handle, filesize($this->file));13 flock($this->handle, LOCK_UN);14 fclose($this->handle);15 return $content;16 }else{17 throw new Exception('File is already open');18 }19 }else{20 throw new Exception('Unable to open file');21 }22 }23}24Fatal error: Uncaught exception 'Exception' with message 'File is already open' in C:\xampp\htdocs\test\1.php:5 Stack trace: #0 C:\xampp\htdocs\test\1.php(5): TestClass->testRead() #1 {main} thrown in C:\xampp\htdocs\test\1.php on line 5
testRead
Using AI Code Generation
1$test = new Test();2$test->testRead();3$test = new Test();4$test->testRead();5$test = new Test();6$test->testRead();7$test = new Test();8$test->testRead();9$test = new Test();10$test->testRead();11$test = new Test();12$test->testRead();13$test = new Test();14$test->testRead();15$test = new Test();16$test->testRead();17$test = new Test();18$test->testRead();19$test = new Test();20$test->testRead();21$test = new Test();22$test->testRead();23$test = new Test();24$test->testRead();25$test = new Test();26$test->testRead();27$test = new Test();28$test->testRead();29$test = new Test();30$test->testRead();31$test = new Test();32$test->testRead();33$test = new Test();34$test->testRead();
testRead
Using AI Code Generation
1require_once('test.php');2$test = new test();3$test->testRead();4require_once('test.php');5$test = new test();6$test->testRead();7require_once('test.php');8$test = new test();9$test->testRead();10require_once('test.php');11$test = new test();12$test->testRead();13require_once('test.php');14$test = new test();15$test->testRead();16require_once('test.php');17$test = new test();18$test->testRead();19require_once('test.php');20$test = new test();21$test->testRead();22require_once('test.php');23$test = new test();24$test->testRead();25require_once('test.php');26$test = new test();27$test->testRead();28require_once('test.php');29$test = new test();30$test->testRead();31require_once('test.php');32$test = new test();33$test->testRead();34require_once('test.php');35$test = new test();36$test->testRead();37require_once('test.php');38$test = new test();39$test->testRead();40require_once('test.php');41$test = new test();42$test->testRead();
testRead
Using AI Code Generation
1require_once('1.php');2$obj = new testRead();3$obj->testRead();4require_once('1.php');5$obj = new testRead();6$obj->testRead();7require_once('1.php');8$obj = new testRead();9$obj->testRead();10require_once('1.php');11$obj = new testRead();12$obj->testRead();13require_once('1.php');14$obj = new testRead();15$obj->testRead();16require_once('1.php');17$obj = new testRead();18$obj->testRead();19require_once('1.php');20$obj = new testRead();21$obj->testRead();22require_once('1.php');23$obj = new testRead();24$obj->testRead();25require_once('1.php');26$obj = new testRead();27$obj->testRead();28require_once('1.php');29$obj = new testRead();30$obj->testRead();31Your name to display (optional):32Your name to display (optional):33{34 public function testRead()35 {36 echo "Hello World";37 }38}39$obj = new testRead();40$obj->testRead();41Your name to display (optional
testRead
Using AI Code Generation
1$test = new testRead();2$test->testRead();3$test = new testRead();4$test->testRead();5 class testRead {6 public function testRead() {7 echo 'testRead';8 }9 }10 class testRead2 {11 public function testRead2() {12 echo 'testRead2';13 }
testRead
Using AI Code Generation
1$obj = new in();2$obj->testRead();3$obj = new out();4$obj->testWrite();5$obj = new in();6$obj->testRead();7$obj = new out();8$obj->testWrite();9I have a class in which I have a method that uses the fopen function to read a file. I have another class that uses the fopen function to write to a file. I want to call both of these methods from the same script. The script is below:Now, when I call the testRead method, I get the error:Warning: fopen() [function.fopen]: Filename cannot be empty in /home/username/public_html/1.php on line 4Warning: fread() expects parameter 1 to be resource, boolean given in /home/username/public_html/1.php on line 5Warning: fclose() expects parameter 1 to be resource, boolean given in /home/username/public_html/1.php on line 6I have tried to use the include function in the script, but that does not work either. I am new to PHP, so I am not sure what I am doing
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with testRead on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!