public function testApi() { $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true)); $this->parameterResolver->expects($this->once())->method('resolveSerializerGroups')->will($this->returnValue($serializerGroups = ['group'])); $this->parameterResolver->expects($this->once())->method('resolveSerializerNull')->will($this->returnValue($serializerNull = true)); $event = $this->createViewEventMock(); $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock())); $view->expects($this->exactly(2))->method('getSerializationContext')->will($this->returnValue($serializationContext = $this->createSerializationContextMock())); $serializationContext->expects($this->once())->method('addGroups')->with($this->identicalTo($serializerGroups)); $serializationContext->expects($this->once())->method('setSerializeNull')->with($this->identicalTo($serializerNull)); $this->subscriber->onApi($event); }
public function testApiWithoutSerializerGroups() { $this->parameterResolver->expects($this->once())->method('resolveApi')->will($this->returnValue(true)); $this->parameterResolver->expects($this->once())->method('resolveSerializerGroups')->will($this->returnValue([])); $this->parameterResolver->expects($this->once())->method('resolveSerializerNull')->will($this->returnValue($null = true)); $event = $this->createViewEventMock(); $event->expects($this->once())->method('getView')->will($this->returnValue($view = $this->createViewMock())); $event->expects($this->once())->method('getResource')->will($this->returnValue($resource = $this->createResourceMock())); $resource->expects($this->once())->method('getName')->will($this->returnValue($name = 'name')); $view->expects($this->exactly(2))->method('getContext')->will($this->returnValue($context = new Context())); $this->subscriber->onApi($event); $this->assertSame([GroupsExclusionStrategy::DEFAULT_GROUP, 'lug.' . $name], $context->getGroups()); $this->assertSame($null, $context->getSerializeNull()); }