php - how to replace methods with phpunit -


Say that I would like to change a method in an object that can obtain a database from a database, whose data is already populated. How do I do this? According to

...

setMethods (array $ methods) can be said on the Mock Builder object that they specify methods to double a configurable test The place with other methods has not changed the behavior. If you call setMethods (NULL), then no method will be changed.

Great So she tells phpunit what methods I want to change, but where can I tell it? I

I found this example:

  make secure functions hmoc () {Return $ this- & gt; GetMockBuilder ('Net_SSH2') - & gt; Disableonational configuration () - & gt; Setmethan (Aray ('__ Destruction')) - & gt; GetMock (); }  

Great - therefore the __ destruction method is being replaced. But what is being changed with it? I do not know. The source for this is:

Whatever does not do with a method , But whose behavior you can configure later, though I'm not sure that you can fully understand how joke works, you do not want to duplicate the class you are investigating, Must make a joke on which the class is being examined. For example:

  // class I want to test class tax calculator {calculation of public function by celestec (product $ product) {$ price = $ product- & gt; Getprice (); Return $ value / 5; // whatever math}} // class I should be designing for testing purposes Product product {public function getPrice () {// connect to database, read product and return value}} // test class tax calculator test extended Do \ PHPUnit_Framework_TestCase {public function testCalculateSalesTax () {// since I want to test the argument within the calculation of SalesTax method / I duplicate a product and some predefined / values ​​/ Configure ways to reset which will allow me to check that everything is fine $$$$ this-> GetMock ('product'); $ Mock- & gt; Method ('getprice') - & gt; Will Ritter (10); $ Tax calculator = new tax calculator (); $ This- & gt; Emphasizing value (2, $ taxCalculator-> Sales tax calculations ($ counterfeit)); }}  

Your test examines the exact square that you are trying to test, which can be a mistake, because some methods can be overriden during the joke is.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -