Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
php: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
php: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6']

fail-fast: false

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": "8.0 - 8.5"
"php": "8.0 - 8.6"
},
"require-dev": {
"nette/tester": "^2.5",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The recommended way to install is via Composer:
composer require nette/utils
```

Nette Utils 4.0 is compatible with PHP 8.0 to 8.5.
Nette Utils 4.0 is compatible with PHP 8.0 to 8.6.

 <!---->

Expand Down
2 changes: 1 addition & 1 deletion src/Utils/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function ($m) use (&$relPart) {
);

if ($ctr) {
parent::__construct($absPart, $timezone);
parent::__construct(trim($absPart), $timezone);
$this->handleErrors($datetime);
} elseif (trim($absPart)) {
parent::modify($absPart) && $this->handleErrors($datetime);
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Image.alpha1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Assert::same($image->toString(), (string) $image);
$image = Image::fromBlank(200, 100, Image::rgb(255, 128, 0, 60));
$image->crop(0, 0, '60%', '60%');

Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha1.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha1.png', $image);
15 changes: 7 additions & 8 deletions tests/Utils/Image.alpha2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,41 @@
*/

use Nette\Utils\Image;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/fixtures.images/alpha2.png'), 0, 0, 100);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha2.100.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha2.100.png', $image);


$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/fixtures.images/alpha2.png'), 0, 0, 99);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha2.99.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha2.99.png', $image);


$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/fixtures.images/alpha2.png'), 0, 0, 50);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha2.50.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha2.50.png', $image);


$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/fixtures.images/alpha2.png'), 0, 0, 1);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha2.1.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha2.1.png', $image);


$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/fixtures.images/alpha2.png'), 0, 0, 0);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha2.0.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha2.0.png', $image);


$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/fixtures.images/alpha3.gif'), 0, 0, 100);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha2.100b.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha2.100b.png', $image);


$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/fixtures.images/alpha3.gif'), 0, 0, 50);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha2.50b.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha2.50b.png', $image);
6 changes: 2 additions & 4 deletions tests/Utils/Image.drawing.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

use Nette\Utils\Image;
use Nette\Utils\ImageColor;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';

Expand All @@ -33,11 +31,11 @@ $image->filledEllipse(187, 125, $radius, $radius, Image::rgb(0, 0, 255, 75));

$image->copyResampled($image, 200, 200, 0, 0, 80, 80, $size, $size);

Assert::same(file_get_contents(__DIR__ . '/expected/Image.drawing.1.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.drawing.1.png', $image);


// palette-based image
$image = Image::fromFile(__DIR__ . '/fixtures.images/logo.gif');
$image->filledEllipse(100, 50, 50, 50, Image::rgb(255, 255, 0, 75));
$image->filledEllipse(100, 150, 50, 50, Image::rgb(255, 255, 0, 75));
Assert::same(file_get_contents(__DIR__ . '/expected/Image.drawing.2.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.drawing.2.png', $image);
3 changes: 1 addition & 2 deletions tests/Utils/Image.place.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

use Nette\Utils\Image;
use Tester\Assert;


require __DIR__ . '/../bootstrap.php';
Expand All @@ -17,4 +16,4 @@ $rectangle = Image::fromBlank(50, 50, Image::rgb(255, 255, 255));
$image = Image::fromBlank(100, 100, Image::rgb(0, 0, 0));
$image->place($rectangle, '37.5%', '50%');

Assert::same(file_get_contents(__DIR__ . '/expected/Image.place.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.place.png', $image);
8 changes: 4 additions & 4 deletions tests/Utils/Image.resize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,26 @@ test('rotate', function () use ($main) {
test('alpha crop', function () use ($main) {
$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->crop(1, 1, 8, 8);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha.crop.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha.crop.png', $image);
});


test('alpha resize', function () use ($main) {
$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->resize(20, 20);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha.resize1.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha.resize1.png', $image);
});


test('alpha flip', function () use ($main) {
$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');
$image->resize(-10, -10);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha.flip1.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha.flip1.png', $image);
});


test('palette alpha resize', function () use ($main) {
$image = Image::fromFile(__DIR__ . '/fixtures.images/alpha3.gif');
$image->resize(20, 20);
Assert::same(file_get_contents(__DIR__ . '/expected/Image.alpha.resize2.png'), $image->toString($image::PNG));
assertImage(__DIR__ . '/expected/Image.alpha.resize2.png', $image);
});
14 changes: 7 additions & 7 deletions tests/Utils/Json.decode().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,42 @@ Assert::same(['a' => 1], Json::decode('{"a":1}', forceArrays: true));
Assert::exception(
fn() => Json::decode(''),
Nette\Utils\JsonException::class,
'Syntax error',
'Syntax error%a?%',
);


Assert::exception(
fn() => Json::decode('NULL'),
Nette\Utils\JsonException::class,
'Syntax error',
'Syntax error%a?%',
);


Assert::exception(
fn() => Json::decode('{'),
Nette\Utils\JsonException::class,
'Syntax error',
'Syntax error%a?%',
);


Assert::exception(
fn() => Json::decode('{}}'),
Nette\Utils\JsonException::class,
'Syntax error',
'Syntax error%a?%',
);


Assert::exception(
fn() => Json::decode("\x00"),
Nette\Utils\JsonException::class,
defined('JSON_C_VERSION') ? 'Syntax error' : 'Control character error, possibly incorrectly encoded',
defined('JSON_C_VERSION') ? 'Syntax error%a?%' : 'Control character error, possibly incorrectly encoded%a?%',
);


Assert::exception(
fn() => Json::decode('{"\u0000": 1}'),
Nette\Utils\JsonException::class,
'The decoded property name is invalid',
'The decoded property name is invalid%a?%',
);


Expand All @@ -71,7 +71,7 @@ Assert::equal((object) ["\"\x00" => 1], Json::decode('{"\"\u0000": 1}'));
Assert::exception(
fn() => Json::decode("\"\xC1\xBF\""),
Nette\Utils\JsonException::class,
'Malformed UTF-8 characters, possibly incorrectly encoded',
'Malformed UTF-8 characters, possibly incorrectly encoded%a?%',
);


Expand Down
14 changes: 14 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,17 @@ function getTempDir(): string

return $dir;
}


/**
* Compares the pixels of the images, as the bytes of a PNG depend on the version of GD.
*/
function assertImage(string $expectedFile, Nette\Utils\Image $actual): void
{
$normalize = function (Nette\Utils\Image $image): string {
$image = clone $image;
$image->paletteToTrueColor();
return $image->toString(Nette\Utils\Image::PNG);
};
Tester\Assert::same($normalize(Nette\Utils\Image::fromFile($expectedFile)), $normalize($actual));
}