Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

We need to ensure, that before even writing any tests the In-Portal code is adapted to allow that. Here is the plan:

  1. we adapt, that code, that can be adapted easily to allow testing in isolation (test each class separately)

  2. what can't be adapted right now will be tested using integration tests using Mink/Selenium later

Main concept of testing in isolation is by using Mock objects. These are special stub-type objects, that replace real object, that testable class used to depend on, but they just return "null" or whatever we tell them to return. PHPUnit (https://github.com/sebastianbergmann/phpunit/) has already some basic mocking capabilities (http://phpunit.de/manual/3.6/en/test-doubles.html#test-doubles.mock-objects), but compared to dedicated mocking framework called Mockery (see https://github.com/padraic/mockery) they are fairly limited and hard to comprehend.

...

Based on code above we just need to add following 2 methods to kBase class, which is base class of all In-Portal classes. This would result in following benefits:

  1. each class now would have static "shouldReceive" method, that when called will:

    1. create mock object of that class

    2. put it in Factory, so anyone calling it will get a Mock back

  2. in tests we can use original class name (one to be mocked) for IDE auto-complete and all will work, because both original and mocked class have "shouldReceive" method

  3. anywhere in code (e.g. outside of tests) we can alter behavior based on fact, a mock class came in instead of a real class (but won't advise to do so)

Instantiating application

...

To learn more about Laravel framework visit http://laravel.com/ page.

Related Discussions

Related Tasks