views:

53

answers:

2

Hi all,

I've following abstract class and have a question about how to write a unit test for this. Is this in fact needed? As this class doesn't have any concrete methods.

<?php

abstract class PickupPoint_Abstract {
    public function __construct($client) {}
    public function getPickupPoints($countryCode, $postalCode, $city) {}
    public function getPickupPointDetails($pickupPointId, $countryCode) {} }
+2  A: 

No, you don't need to test it, because there is nothing to test.

By the way abstract methods should be defined like

<?php
abstract class PickupPoint_Abstract {
    public function __construct($client) {}
    abstract public function getPickupPoints($countryCode, $postalCode, $city);
    abstract public function getPickupPointDetails($pickupPointId, $countryCode);
}
?>

You made hooks, which may not be overridden.

See Class Abstraction.

Christian Strempfer
I did forgot the abstract! Thx.
Skelton
+2  A: 

Since you can't test for any expected behavior it seems really hard to produce any meaningful test.


If you have at least one concrete method you can mock the class and test that one method but without any code to be tested i'd say you are good to go.

( I guess you know that always but for sake of completion: See Example 11.8 for getMockForAbstractClass on the phpunit site )


Even so i'm curios to why you didn't define the methods as abstract like this:

<?php
abstract class PickupPoint_Abstract {
    abstract public function __construct($client);
    abstract public function getPickupPoints($countryCode, $postalCode, $city);
    abstract public function getPickupPointDetails($pickupPointId, $countryCode); }

since only then the interpreter will enforce that all methods are implemented in the child classes.

edorian