php - Mock Objects: implement interface or extend class? -


I'm writing in a library, I want to write unit tests. I know that in fact for one unit test, only one object can be tested at a time.

My question is directly related to the creation of counterfeit goods. I am writing an XML library to convert PHP arrays into well-formed XML, and I have to include properties by creating a container object Have decided to resolve. I have no possibility of writing an interface for the other class except to create a fake version of it.

Is it better to just type an interface to duplicate an item, especially when the interface is found only? Or what is the solution to increase the base class and to define data members or override the gates to return specific values?

Thank you.

Recommendation per Sense exception, there is an object structure:

EXMLWriter: takes an Excel data and runs the validator, and writes XML.

EXMLData: $ data is an array where $ key = & gt; $ Value is used to generate XML.

  interface iEXMLData {public function getData (); Public function getRoot (); Public ceremony getRuleset (); }  

EXMLRuleSet: An array with a function of the container square for each set of EXMLValidators basically to run each verifier.

EXMLValidator: Whatever checks run against EXMLData's $ data subscriber

  interface iEXMLValidator {public function valid ($ data); }  

Exclusions: The special class that knows about XLLRter Extender XMLM is allowed to use External XML. Really getData () and getAttributes () .

In the EXMLWriter class, I've added this type of argument:

  if (is_array ($ value)) {// code} elseif ($ value instanceof iEXMLData ) {// code} elseif ($ value instance's EXMLElement) {// code}  

Because there is only gates and setters for XML data, it is understood that this interface is not is.

The phpUnit method can be used on a class.

ClassToTest.php

  & lt; Php class classos {}  

TestClassToTest.php

   

  PHPUnit 3.7.20 is running by Sebastian Bergman. . Time: 0 seconds, Memory: 2.25 MB OK (1 Test, 2 claims)  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -