Skip to content

Add tests and GitHub actions #6

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

Merged
merged 6 commits into from
Nov 24, 2024
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
69 changes: 69 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Main

on:
workflow_dispatch:
push:
branches:
- main
- master
- release/**
pull_request:
branches:
- main
- master
- release/**

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
steps:
- name: Get source code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
ini-values: post_max_size=256M, max_execution_time=180
- name: Check package
run: |
sudo pear list
sudo pear channel-update pear.php.net
sudo pear upgrade --force pear/pear
sudo pear list
sudo pear install --force package.xml
sudo pear list
sudo pear package
sudo pear package-validate
sudo pear install --force *.tgz
sudo pear list
# For some reason ttf-mscorefonts-installer doesn't work
# so we only install Verdana
- name: Download and install Verdana font
run: |
sudo apt install cabextract
curl -L -o verdan32.exe 'http://download.sourceforge.net/corefonts/verdan32.exe'
cabextract -d Image/Canvas/Fonts/ verdan32.exe
mv Image/Canvas/Fonts/Verdana.TTF Image/Canvas/Fonts/verdana.ttf
- name: Install pre-requisites and run test scripts
run: |
composer install
php tests/gradients.php > gradients.png
php tests/imagemap.php > imagemap.html
php tests/png.php
php tests/jpg.php
# php tests/ps.php
# php tests/pdf.php
php tests/svg.php
php tests/text.php > text.png
php tests/lineends.php > lineends.png
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
},
"type": "library",
"require": {
"php": ">=5.6, < 8.0",
"pear/pear_exception": "*",
"pear/image_color": "*"
},
"require-dev": {
"phpunit/phpunit": "*"
}
}
6 changes: 3 additions & 3 deletions tests/canvas_body.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@

$canvas->addText(array('x' => 375, 'y' => 455, 'text' => 'Image'));

$canvas->image(array('x' => 445, 'y' => 455, 'filename' => './pear-icon.png', 'url' => 'http://pear.veggerby.dk/', 'target' => '_blank'));
$canvas->image(array('x' => 445, 'y' => 455, 'filename' => __DIR__ . '/pear-icon.png', 'url' => 'http://pear.veggerby.dk/', 'target' => '_blank'));

$canvas->image(array('x' => 445, 'y' => 495, 'filename' => './pear-icon.png', 'width' => 20, 'height' => 20));
$canvas->image(array('x' => 445, 'y' => 495, 'filename' => __DIR__ . '/pear-icon.png', 'width' => 20, 'height' => 20));

$canvas->image(array('x' => 445, 'y' => 523, 'filename' => './pear-icon.png', 'width' => 40, 'height' => 40));
$canvas->image(array('x' => 445, 'y' => 523, 'filename' => __DIR__ . '/pear-icon.png', 'width' => 40, 'height' => 40));

//$canvas->show();
$type = basename($_SERVER['SCRIPT_NAME'], '.php');
Expand Down
2 changes: 1 addition & 1 deletion tests/gradients.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @link http://pear.php.net/package/Image_Canvas
*/

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';

$canvas =& Image_Canvas::factory(
'png',
Expand Down
2 changes: 1 addition & 1 deletion tests/imagemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @link http://pear.php.net/package/Image_Canvas
*/

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';

$canvas =& Image_Canvas::factory(
'png',
Expand Down
4 changes: 2 additions & 2 deletions tests/jpg.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
// SPECIFY HERE WHERE A TRUETYPE FONT CAN BE FOUND
$testFont = 'c:/windows/fonts/Arial.ttf';

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';

$canvas =& Image_Canvas::factory('jpg', array('width' => 600, 'height' => 600, 'quality' => 90));

require_once './canvas_body.php';
require_once __DIR__ . '/canvas_body.php';

?>
2 changes: 1 addition & 1 deletion tests/lineends.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @link http://pear.php.net/package/Image_Canvas
*/

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';

$font = array('name' => 'Verdana', 'size' => 10);

Expand Down
4 changes: 2 additions & 2 deletions tests/pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
// SPECIFY HERE WHERE A TRUETYPE FONT CAN BE FOUND
$testFont = 'c:/windows/fonts/Arial.ttf';

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';

$canvas =& Image_Canvas::factory('pdf', array('page' => 'A4', 'align' => 'center', 'width' => 600, 'height' => 600));

require_once './canvas_body.php';
require_once __DIR__ . '/canvas_body.php';

?>
4 changes: 2 additions & 2 deletions tests/png.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
// SPECIFY HERE WHERE A TRUETYPE FONT CAN BE FOUND
$testFont = 'c:/windows/fonts/Arial.ttf';

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';

$canvas =& Image_Canvas::factory('png', array('width' => 600, 'height' => 600));

require_once './canvas_body.php';
require_once __DIR__ . '/canvas_body.php';

?>
4 changes: 2 additions & 2 deletions tests/ps.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
// SPECIFY HERE WHERE A TRUETYPE FONT CAN BE FOUND
$testFont = 'c:/windows/fonts/Arial.ttf';

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';

$canvas =& Image_Canvas::factory('ps', array('page' => 'A4', 'align' => 'center', 'width' => 600, 'height' => 600, 'filename'=>'testps.ps'));

require_once './canvas_body.php';
require_once __DIR__ . '/canvas_body.php';

?>
4 changes: 2 additions & 2 deletions tests/svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
// SPECIFY HERE WHERE A TRUETYPE FONT CAN BE FOUND
$testFont = 'c:/windows/fonts/Arial.ttf';

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';

$canvas =& Image_Canvas::factory('svg', array('width' => 600, 'height' => 600));

require_once './canvas_body.php';
require_once __DIR__ . '/canvas_body.php';

?>
2 changes: 1 addition & 1 deletion tests/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @link http://pear.php.net/package/Image_Canvas
*/

require_once 'Image/Canvas.php';
require_once 'vendor/autoload.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't let this stop a merge now, but I'd prefer a more flexible approach here that doesn't force a composer installation before someone could run the testsuite. Just a simple existence check on the vendor autoload in order to require it, and fall back to the old PEAR-style require otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good remark but I'm not sure I understand all the details of it. Just testing the existence of vendor/autoload.php would be enough ? Do you know a package that does that (so I can take inspiration from it) ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (file_exists('vendor/autoload.php')) {
    // use composer if available
    require_once 'vendor/autoload.php';
} else {
    // otherwise rely on classic PEAR include_path
    require_once 'Image/Canvas.php';
}


$canvas =& Image_Canvas::factory(
'png',
Expand Down