public function testAddMergeExtensions() { $animal1 = new Cat(); $animal2 = new Cat(); $callback = function () { }; $extensions = new ExtensionFieldMap(Animal::CLASS); $extension = new ExtensionField(Animal::CLASS, 'animal', 100, $callback, $callback, $callback); $animal1->setDeclawed(true); $extensions->add($extension, $animal1); $this->assertSame($animal1, $extensions->offsetGet($extension)); $animal2->setDeclawed(false); $extensions->add($extension, $animal2); $this->assertTrue($animal2->getDeclawed()); $this->assertSame($animal2, $extensions->offsetGet($extension)); }
public function testReadExtensionAnimalMessage() { Extension\Extension::registerAllExtensions($this->config->getExtensionRegistry()); $binary = $this->getProtoContent('extension-animal-cat.bin'); $animal = Extension\Animal::fromStream($binary, $this->config); $this->assertInstanceOf(Extension\Animal::CLASS, $animal); $this->assertInstanceOf(Collection::CLASS, $animal->extensions()); $this->assertEquals(Extension\Animal\Type::CAT(), $animal->getType()); $extensions = $animal->extensions(); $cat = $extensions->get(Extension\Cat::animal()); $this->assertInstanceOf(Extension\Cat::CLASS, $cat); $this->assertTrue($cat->getDeclawed()); }