Skip to content

Commit

Permalink
tests: cs fixes, some classes moved to /fixtures.* (doesn't suit CS)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 21, 2017
1 parent 62bbd4f commit 0757a42
Show file tree
Hide file tree
Showing 27 changed files with 95 additions and 96 deletions.
28 changes: 14 additions & 14 deletions tests/Utils/Image.alpha2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/images/alpha2.png'), 0, 0, 100);
$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, 0));


$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/images/alpha2.png'), 0, 0, 99);
$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, 0));


$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/images/alpha2.png'), 0, 0, 50);
$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, 0));


$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/images/alpha2.png'), 0, 0, 1);
$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, 0));


$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/images/alpha2.png'), 0, 0, 0);
$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, 0));


$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/images/alpha3.gif'), 0, 0, 100);
$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, 0));


$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$image->place(Image::fromFile(__DIR__ . '/images/alpha3.gif'), 0, 0, 50);
$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, 0));
2 changes: 1 addition & 1 deletion tests/Utils/Image.clone.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


$original = Image::fromFile(__DIR__ . '/images/logo.gif');
$original = Image::fromFile(__DIR__ . '/fixtures.images/logo.gif');

$dolly = clone $original;
Assert::notSame($dolly->getImageResource(), $original->getImageResource());
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Image.drawing.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Assert::same(file_get_contents(__DIR__ . '/expected/Image.drawing.1.png'), $imag


// palette-based image
$image = Image::fromFile(__DIR__ . '/images/logo.gif');
$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, 0));
14 changes: 7 additions & 7 deletions tests/Utils/Image.factories.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require __DIR__ . '/../bootstrap.php';


test(function () {
$image = Image::fromFile(__DIR__ . '/images/logo.gif', $format);
$image = Image::fromFile(__DIR__ . '/fixtures.images/logo.gif', $format);
Assert::same(176, $image->getWidth());
Assert::same(104, $image->getHeight());
Assert::same(Image::GIF, $format);
Expand All @@ -26,25 +26,25 @@ test(function () {
if (!function_exists('imagecreatefromwebp')) {
return;
}
$image = Image::fromFile(__DIR__ . '/images/logo.webp', $format);
$image = Image::fromFile(__DIR__ . '/fixtures.images/logo.webp', $format);
Assert::same(176, $image->getWidth());
Assert::same(104, $image->getHeight());
Assert::same(Image::WEBP, $format);
});


Assert::exception(function () {
Image::fromFile('images/missing.png');
}, Nette\Utils\UnknownImageFileException::class, "File 'images/missing.png' not found.");
Image::fromFile('fixtures.images/missing.png');
}, Nette\Utils\UnknownImageFileException::class, "File 'fixtures.images/missing.png' not found.");


Assert::exception(function () {
Image::fromFile(__DIR__ . '/images/logo.tiff');
}, Nette\Utils\UnknownImageFileException::class, "Unknown type of file '%a%images/logo.tiff'.");
Image::fromFile(__DIR__ . '/fixtures.images/logo.tiff');
}, Nette\Utils\UnknownImageFileException::class, "Unknown type of file '%a%fixtures.images/logo.tiff'.");


Assert::exception(function () {
Image::fromFile(__DIR__ . '/images/bad.gif');
Image::fromFile(__DIR__ . '/fixtures.images/bad.gif');
}, Nette\Utils\ImageException::class, '%a% not a valid GIF file');


Expand Down
8 changes: 4 additions & 4 deletions tests/Utils/Image.resize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


$main = Image::fromFile(__DIR__ . '/images/logo.gif');
$main = Image::fromFile(__DIR__ . '/fixtures.images/logo.gif');


test(function () use ($main) { // cropping...
Expand Down Expand Up @@ -133,21 +133,21 @@ test(function () use ($main) { // rotate


test(function () use ($main) { // alpha resize
$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$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, 0));
});


test(function () use ($main) { // alpha flip
$image = Image::fromFile(__DIR__ . '/images/alpha1.png');
$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, 0));
});


test(function () use ($main) { // palette alpha resize
$image = Image::fromFile(__DIR__ . '/images/alpha3.gif');
$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, 0));
});
2 changes: 1 addition & 1 deletion tests/Utils/Image.save.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


$main = Image::fromFile(__DIR__ . '/images/alpha1.png');
$main = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');


test(function () use ($main) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Image.send.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


$main = Image::fromFile(__DIR__ . '/images/alpha1.png');
$main = Image::fromFile(__DIR__ . '/fixtures.images/alpha1.png');


test(function () use ($main) {
Expand Down
8 changes: 4 additions & 4 deletions tests/Utils/Json.decode().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ Assert::exception(function () {
// default JSON_BIGINT_AS_STRING
if (defined('JSON_C_VERSION')) {
if (PHP_INT_SIZE > 4) {
# 64-bit
Assert::same([9223372036854775807], Json::decode('[12345678901234567890]')); # trimmed to max 64-bit integer
// 64-bit
Assert::same([9223372036854775807], Json::decode('[12345678901234567890]')); // trimmed to max 64-bit integer
} else {
# 32-bit
Assert::same(['9223372036854775807'], Json::decode('[12345678901234567890]')); # trimmed to max 64-bit integer
// 32-bit
Assert::same(['9223372036854775807'], Json::decode('[12345678901234567890]')); // trimmed to max 64-bit integer
}

} else {
Expand Down
6 changes: 3 additions & 3 deletions tests/Utils/Reflection.expandClassName.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


require __DIR__ . '/files/expandClass.noNamespace.php';
require __DIR__ . '/files/expandClass.inBracketedNamespace.php';
require __DIR__ . '/files/expandClass.inNamespace.php';
require __DIR__ . '/fixtures.reflection/expandClass.noNamespace.php';
require __DIR__ . '/fixtures.reflection/expandClass.inBracketedNamespace.php';
require __DIR__ . '/fixtures.reflection/expandClass.inNamespace.php';

$rcTest = new \ReflectionClass(Test::class);
$rcBTest = new \ReflectionClass(BTest::class);
Expand Down
76 changes: 22 additions & 54 deletions tests/Utils/Reflection.getParameterDefaultValue.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,37 @@

declare(strict_types=1);

namespace NS {
define('DEFINED', 123);
define('NS_DEFINED', 'xxx');
const NS_DEFINED = 456;
use Nette\Utils\Reflection;
use Tester\Assert;

interface Bar
{
const DEFINED = 'xyz';
}
require __DIR__ . '/../bootstrap.php';
require __DIR__ . '/fixtures.reflection/defaultValue.php';

class Foo
{
const DEFINED = 'abc';

Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'a'));
}, ReflectionException::class);

public function method(
$a,
$b = self::DEFINED,
$c = Foo::DEFINED,
$d = SELF::DEFINED,
$e = bar::DEFINED,
$f = self::UNDEFINED,
$g = Undefined::ANY,
$h = DEFINED,
$i = UNDEFINED,
$j = NS_DEFINED
) {
}
}
}
Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'b')));

namespace {
use Nette\Utils\Reflection;
use Tester\Assert;
Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'c')));

require __DIR__ . '/../bootstrap.php';
Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'd')));

Assert::same(NS\Bar::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'e')));

Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'a'));
}, ReflectionException::class);
Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'f'));
}, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $f in NS\Foo::method().');

Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'b')));
Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'g'));
}, ReflectionException::class, 'Unable to resolve constant NS\Undefined::ANY used as default value of $g in NS\Foo::method().');

Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'c')));
Assert::same(DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'h')));

Assert::same(NS\Foo::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'd')));
Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'i'));
}, ReflectionException::class, 'Unable to resolve constant NS\UNDEFINED used as default value of $i in NS\Foo::method().');

Assert::same(NS\Bar::DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'e')));

Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'f'));
}, ReflectionException::class, 'Unable to resolve constant self::UNDEFINED used as default value of $f in NS\Foo::method().');

Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'g'));
}, ReflectionException::class, 'Unable to resolve constant NS\Undefined::ANY used as default value of $g in NS\Foo::method().');

Assert::same(DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'h')));

Assert::exception(function () {
Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'i'));
}, ReflectionException::class, 'Unable to resolve constant NS\UNDEFINED used as default value of $i in NS\Foo::method().');

Assert::same(NS\NS_DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'j')));
}
Assert::same(NS\NS_DEFINED, Reflection::getParameterDefaultValue(new ReflectionParameter(['NS\Foo', 'method'], 'j')));
3 changes: 1 addition & 2 deletions tests/Utils/Reflection.getParameterType.php71.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
declare(strict_types=1);

use Nette\Utils\Reflection;
use Test\B; // for testing purposes
use Tester\Assert;


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


use Test\B; // for testing purposes

class A
{
public function method(Undeclared $undeclared, B $b, array $array, callable $callable, $none, ?B $nullable)
Expand Down
3 changes: 1 addition & 2 deletions tests/Utils/Reflection.getParameterType.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
declare(strict_types=1);

use Nette\Utils\Reflection;
use Test\B; // for testing purposes
use Tester\Assert;


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


use Test\B; // for testing purposes

class A
{
public function method(Undeclared $undeclared, B $b, array $array, callable $callable, self $self, $none)
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Reflection.groupUseStatements.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


require __DIR__ . '/files/expandClass.groupUse.php';
require __DIR__ . '/fixtures.reflection/expandClass.groupUse.php';

Assert::same(
['A' => 'A\B\A', 'C' => 'A\B\B\C', 'D' => 'A\B\C', 'E' => 'D\E'],
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Reflection.nonClassUseStatements.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


require __DIR__ . '/files/expandClass.nonClassUse.php';
require __DIR__ . '/fixtures.reflection/expandClass.nonClassUse.php';

Assert::same(
[],
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions tests/Utils/fixtures.reflection/defaultValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);

namespace NS;

define('DEFINED', 123);
define('NS_DEFINED', 'xxx');
const NS_DEFINED = 456;

interface Bar
{
const DEFINED = 'xyz';
}

class Foo
{
const DEFINED = 'abc';


public function method(
$a,
$b = self::DEFINED,
$c = Foo::DEFINED,
$d = SELF::DEFINED,
$e = bar::DEFINED,
$f = self::UNDEFINED,
$g = Undefined::ANY,
$h = DEFINED,
$i = UNDEFINED,
$j = NS_DEFINED
) {
}
}
File renamed without changes.

0 comments on commit 0757a42

Please sign in to comment.