Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gd resource type change in php 8.0 #69

Merged
merged 1 commit into from
Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions packages/zend-barcode/library/Zend/Barcode/Renderer/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function __construct($options = null)
* Set height of the result image
*
* @param null|integer $value
* @return Zend_Image_Barcode_Abstract
* @return self
* @throws Zend_Barcode_Renderer_Exception
*/
public function setHeight($value)
Expand Down Expand Up @@ -151,26 +151,25 @@ public function getWidth()
* Set an image resource to draw the barcode inside
*
* @param $image
* @return Zend_Barcode_Renderer
* @return self
* @throws Zend_Barcode_Renderer_Exception
*/
public function setResource($image)
{
if (gettype($image) != 'resource' || get_resource_type($image) != 'gd') {
// require_once 'Zend/Barcode/Renderer/Exception.php';
throw new Zend_Barcode_Renderer_Exception(
'Invalid image resource provided to setResource()'
);
if ((gettype($image) === 'resource' && get_resource_type($image) === 'gd') || get_class($image) === 'GdImage') {
$this->_resource = $image;
return $this;
}
$this->_resource = $image;
return $this;
throw new Zend_Barcode_Renderer_Exception(
'Invalid image resource provided to setResource()'
);
}

/**
* Set the image type to produce (png, jpeg, gif)
*
* @param string $value
* @return Zend_Barcode_RendererAbstract
* @return self
* @throws Zend_Barcode_Renderer_Exception
*/
public function setImageType($value)
Expand Down
8 changes: 6 additions & 2 deletions tests/Zend/Barcode/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,12 @@ public function testProxyBarcodeRendererDrawAsImage()
'GD extension is required to run this test');
}
$resource = Zend_Barcode::draw('code25', 'image');
$this->assertTrue(gettype($resource) == 'resource', 'Image must be a resource');
$this->assertTrue(get_resource_type($resource) == 'gd', 'Image must be a GD resource');
if (PHP_VERSION_ID < 80000) {
$this->assertTrue(gettype($resource) == 'resource', 'Image must be a resource');
$this->assertTrue(get_resource_type($resource) == 'gd', 'Image must be a GD resource');
} else {
$this->assertTrue(get_class($resource) === 'GdImage');
}
}

public function testProxyBarcodeRendererDrawAsPdf()
Expand Down
16 changes: 12 additions & 4 deletions tests/Zend/Barcode/Renderer/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ public function testDrawReturnResource()
$barcode = new Zend_Barcode_Object_Code39(array('text' => '0123456789'));
$this->_renderer->setBarcode($barcode);
$resource = $this->_renderer->draw();
$this->assertTrue(gettype($resource) == 'resource', 'Image must be a resource');
$this->assertTrue(get_resource_type($resource) == 'gd',
if (PHP_VERSION_ID < 80000) {
$this->assertTrue(gettype($resource) == 'resource', 'Image must be a resource');
$this->assertTrue(get_resource_type($resource) == 'gd',
'Image must be a GD resource');
} else {
$this->assertTrue(get_class($resource) === 'GdImage');
}
}

public function testDrawWithExistantResourceReturnResource()
Expand All @@ -143,9 +147,13 @@ public function testDrawWithExistantResourceReturnResource()
$imageResource = imagecreatetruecolor(500, 500);
$this->_renderer->setResource($imageResource);
$resource = $this->_renderer->draw();
$this->assertTrue(gettype($resource) == 'resource', 'Image must be a resource');
$this->assertTrue(get_resource_type($resource) == 'gd',
if (PHP_VERSION_ID < 80000) {
$this->assertTrue(gettype($resource) == 'resource', 'Image must be a resource');
$this->assertTrue(get_resource_type($resource) == 'gd',
'Image must be a GD resource');
} else {
$this->assertTrue(get_class($resource) === 'GdImage');
}
$this->assertSame($resource, $imageResource);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Zend/Barcode/Renderer/TestCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ abstract class Zend_Barcode_Renderer_TestCommon extends PHPUnit_Framework_TestCa
{

/**
* @var Zend_Barcode_Renderer
* @var Zend_Barcode_Renderer_RendererAbstract
*/
protected $_renderer = null;

Expand Down