pear / Image_Barcode2

A PHP5 revamp of the Image_Barcode package
http://pear.php.net/package/Image_Barcode2
16 stars 17 forks source link

Introduce an adapter for better testability and DRY #2

Open CloCkWeRX opened 12 years ago

CloCkWeRX commented 12 years ago

There are lots of calls to code like

    imagestring(
        $img,
        $this->_font,
        $xpos + 1,
        $this->_barcodeheight,
        $value,
        $black
    );

littered through the codebase.

Introduce an Image_Barcode2 wrapper which provides a quick OO abstraction layer on the functional calls.

Gemorroj commented 12 years ago

I'm not sure what to do? Wrap over the image* functions? Do not see the point. Remove duplicated code? But in some cases (Code39 and ean13, for example) the implementation of a lot different.

CloCkWeRX commented 12 years ago

Well, there's no way to test the drivers at the moment; or to mock them out. If we created a simple

class ImageWriterererThingy {
   public function setWidth();
   public function setHeight();
   public function drawRect();
   public function drawString();
}

... then it's easy to do things like:

testShouldDrawThreeBlackBoxes
    $mock = $this->getMock('ImageWriterererThingy');
    $barcode = new ...
    $barcode->setThinger($mock);

    $mock->expects($this->times(3))
             ->method('drawRect')
             ->with(array('x', 'y', 'black'));
CloCkWeRX commented 12 years ago

(don't stress, I'll pick this one up in abit, with some basic test coverage)

till commented 10 years ago

@CloCkWeRX Can you close issues when you resolved them?