getMockBuilder('DOMNodeList')->disableOriginalConstructor()->getMock(); $nodeListMock ->expects($this->atLeastOnce()) ->method('item') ->with(0) ->will($this->returnValue((object)[ 'nodeValue' => $nodeValue ])); $nodeMock = $this->getMockBuilder('DOMElement')->disableOriginalConstructor()->getMock(); $nodeMock ->expects($this->atLeastOnce()) ->method('getAttribute') ->will($this->returnValueMap([ [ CellValueFormatter::XML_ATTRIBUTE_TYPE, $cellType ], [ CellValueFormatter::XML_ATTRIBUTE_STYLE_ID, 123 ], ])); $nodeMock ->expects($this->atLeastOnce()) ->method('getElementsByTagName') ->with(CellValueFormatter::XML_NODE_VALUE) ->will($this->returnValue($nodeListMock)); $styleHelperMock = $this->getMockBuilder(__NAMESPACE__ . '\StyleHelper')->disableOriginalConstructor()->getMock(); $styleHelperMock ->expects($this->once()) ->method('shouldFormatNumericValueAsDate') ->with(123) ->will($this->returnValue(true)); $instance = new CellValueFormatter(null, $styleHelperMock); $result = $instance->extractAndFormatNodeValue($nodeMock); if ($expectedDateAsString === null) { $this->assertNull($result); } else { $this->assertInstanceOf('DateTime', $result); $this->assertSame($expectedDateAsString, $result->format('Y-m-d H:i:s')); } } }