Unit testing with MOCK

Unit-testing, integration testing for the code i write is what i prefer most. Either to increase the existing code coverage or at least maintain the existing code coverage is what i thrive for.

Many instance i will use Mock here are few code snippets of how i use them.

class MyClassTest extends \PHPUnit_Framework_TestCase {
    function testMethod() {
      $stub = $this->getMockBuilder('WebServiceRequest')
            ->disableOriginalConstructor()
            ->setMethods(array('getRequest'))
            ->getMock();

      $stub->expects($this->any())
            ->method('getRequest')
            ->will($this->returnValue("foo-bar"));

     $stub->getResult("dummy_url"); // when getRequest() is called will returns 'foo-bar'
    }
}

Selenium crashing for large strings in sendKeys

I had to automate setting up surveys on third party system since they din’t had bulk creation of surveys. As a part of survey setup we had huge css file (more than 10,000 bytes) to be setup on each survey.

When i tried to send the string in one go it was Selenium was crashing out both on Firefox and Chrome driver.

Got around by sending the text in chunks and calling sendKeys in a loop.