Skip to content

FrOSCon - Test Proxies: How Problems Became Features

By Sebastian Bergman and Arne Blankerts.
Keep your eyes up and stay tuned for "patch coverage".
Second time, thanks for the book - handed over by sebastian himself. Mister HowTrueIsFalse, you will get back your book soon :-).

What Is The Talk About

Integration tests closing the gap between unit tests and system tests. This is resolved by keep the focus on interfaces between components and testing that the interaction between the components is working as expected.

Arne Blankerts and Sebastian Bergman showing how a problem by setting up the integration tests became a feature aka "Test Proxies" for PHPUnit.

They also discuss problems and provide solutions for implementing mock objects in php unit and how to ship them as features.

How To Visualize

How lower you go, the faster and the exact the tested code behaves. How higher you go, the more you can provide a stable and general testcase.

  • business
  • technology

  • ui

  • service
  • unit

Isolation, speed (top down) vs Confidence in whole system (bottom up) from how google tests software * large * medium * small

Terms

Test one unit is a unit test.

Write a test between two units is more a integration test than a unit test. Current idea is to stub or mock one of the two units and see how other unit acts.

Push the idea of stubbing and mocking more to the edge will lead to "edge to edge test" like "client to server test". In general, try to test components on the same level (layer).
Try to monitor systems for load tests and use appdynamcis or xdebug and xhprof.

Example

<?php
namespace Company\Project

class SampleWorkflow
{
    private $backend;
    private $service;

    public function __construct(Backend $backend, Service $service)
    {
        $this->backend = $backend;
        $this->service = $service;
    }

    public function execute(Request $request)
        $this->service->workflow(
            $this->backend->getObjectById($request->getValue('id));
        );
    }
}

How to test this?

Would be cool if we can log that code was executed like test proxies by adding an extra flag to the mock builder.
Provides way to see where dataflow changed or drifts from expected way (will be in PHPUnit 3.8).

<?php
namespace Company\Project

use PHPUnit_Framework_TestCase;

class SampleWorkflowTest extends PHPUnit_Framework_TestCase
{
    public function testServiceCallUpdatesObjects()
    {
        $service = $this->getMockBuilder('Service')
            ->enableProxyingToOriginalMethods()
            ->getMock();

        $service->expects($this->once())
            ->method('doWork');

        $backend = new Backend();
        $workflow = new SampleWorkflow($backend, $service);

        $workflow->execute(new Request(array('id' => 42)));
    }
}

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Markdown format allowed
Form options