Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Introduce an adapter for better testability and DRY #2

Open
CloCkWeRX opened this Issue · 4 comments

3 participants

@CloCkWeRX
Owner

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.

@CloCkWeRX CloCkWeRX referenced this issue from a commit in CloCkWeRX/Image_Barcode2
@CloCkWeRX CloCkWeRX Issue #2 PHPCS acec7ee
@Gemorroj
Collaborator

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
Owner

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
Owner

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

@CloCkWeRX CloCkWeRX referenced this issue from a commit in CloCkWeRX/Image_Barcode2
@CloCkWeRX CloCkWeRX All drivers accept a writer for issue #2 0522043
@till
Owner

@CloCkWeRX Can you close issues when you resolved them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.