Skip to content

Commit

Permalink
Tests: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Nov 15, 2023
1 parent f979664 commit 632c776
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 109 deletions.
9 changes: 5 additions & 4 deletions tests/Cases/Annotations.phpt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php declare(strict_types = 1);

require_once __DIR__ . '/../bootstrap.php';

use Contributte\Tester\Toolkit;
use Contributte\Utils\Annotations;
use Tester\Assert;
use Tests\Fixtures\AnnotationFoo;

require_once __DIR__ . '/../bootstrap.php';

// Class
test(function (): void {
Toolkit::test(function (): void {
$r = new ReflectionClass(AnnotationFoo::class);
$annotations = Annotations::getAnnotations($r);

Expand All @@ -24,7 +25,7 @@ test(function (): void {
});

// Method
test(function (): void {
Toolkit::test(function (): void {
$r = new ReflectionMethod(AnnotationFoo::class, 'fake');
$annotations = Annotations::getAnnotations($r);

Expand Down
3 changes: 2 additions & 1 deletion tests/Cases/Arrays.phpt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php declare(strict_types = 1);

use Contributte\Tester\Toolkit;
use Contributte\Utils\Arrays;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

test(function (): void {
Toolkit::test(function (): void {
$array1 = ['a', 'b', 'c', 'd'];
$hash1 = Arrays::hash($array1);

Expand Down
7 changes: 4 additions & 3 deletions tests/Cases/Config.phpt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php declare(strict_types = 1);

require_once __DIR__ . '/../bootstrap.php';

use Contributte\Tester\Toolkit;
use Contributte\Utils\Config;
use Tester\Assert;

test(function (): void {
require_once __DIR__ . '/../bootstrap.php';

Toolkit::test(function (): void {
$data = [
'foo' => 'bar',
'conn' => [
Expand Down
21 changes: 9 additions & 12 deletions tests/Cases/Csv.phpt
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
<?php declare(strict_types = 1);

/**
* Test: Csv
*/

require_once __DIR__ . '/../bootstrap.php';

use Contributte\Tester\Toolkit;
use Contributte\Utils\Csv;
use Nette\InvalidStateException;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

// Simple array matching
test(function (): void {
Toolkit::test(function (): void {
Assert::equal([
0 => [
'name' => 'Milan',
Expand All @@ -37,7 +34,7 @@ test(function (): void {
});

// Complex array matching
test(function (): void {
Toolkit::test(function (): void {
Assert::equal([
0 => [
'user' => [
Expand Down Expand Up @@ -71,7 +68,7 @@ test(function (): void {
});

// Part of simple array matching
test(function (): void {
Toolkit::test(function (): void {
Assert::equal([
0 => [
'x' => 'foo',
Expand All @@ -85,7 +82,7 @@ test(function (): void {
});

// Part of complex array matching
test(function (): void {
Toolkit::test(function (): void {
Assert::equal([
0 => [
'x' => [
Expand All @@ -107,7 +104,7 @@ test(function (): void {
});

// Overriding
test(function (): void {
Toolkit::test(function (): void {
Assert::equal([
0 => [
'x' => 'foo',
Expand All @@ -122,7 +119,7 @@ test(function (): void {
});

// Invalid arguments
test(function (): void {
Toolkit::test(function (): void {
Assert::throws(function (): void {
Csv::structural([
0 => 'a',
Expand Down
10 changes: 4 additions & 6 deletions tests/Cases/DI/DateTimeFactoryExtensions.phpt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php declare(strict_types = 1);

/**
* Test: DI\DateTimeFactoryExtension
*/

use Contributte\Tester\Environment;
use Contributte\Tester\Toolkit;
use Contributte\Utils\DI\DateTimeFactoryExtension;
use Contributte\Utils\IDateTimeFactory;
use Nette\DI\Compiler;
Expand All @@ -13,8 +11,8 @@ use Tester\Assert;

require_once __DIR__ . '/../../bootstrap.php';

test(function (): void {
$loader = new ContainerLoader(TEMP_DIR, true);
Toolkit::test(function (): void {
$loader = new ContainerLoader(Environment::getTestDir(), true);
$class = $loader->load(function (Compiler $compiler): void {
$compiler->addExtension('datetime', new DateTimeFactoryExtension());
}, 1);
Expand Down
17 changes: 7 additions & 10 deletions tests/Cases/DateTime.compare.phpt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?php declare(strict_types = 1);

/**
* Test: DateTime [comparing]
*/

require_once __DIR__ . '/../bootstrap.php';

use Contributte\Tester\Toolkit;
use Contributte\Utils\DateTime;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

// Test: datetime
test(function (): void {
Toolkit::test(function (): void {
// Now
$now = new DateTime('2014-1-2 00:00:00');

Expand All @@ -23,7 +20,7 @@ test(function (): void {
});

// Test: datetime convert to strtotime
test(function (): void {
Toolkit::test(function (): void {
// Now
$now = strtotime((string) new DateTime('2014-1-2 00:00:00'));

Expand All @@ -36,7 +33,7 @@ test(function (): void {
});

// Test: now == until
test(function (): void {
Toolkit::test(function (): void {
// Now
$now = new DateTime('2014-1-5 00:00:00');

Expand All @@ -49,7 +46,7 @@ test(function (): void {
});

// Test: datetimes with DD.MM.YYYY 00:00:00
test(function (): void {
Toolkit::test(function (): void {
// Now
$now = new DateTime('now');
$now->setTime(0, 0, 0);
Expand Down
21 changes: 9 additions & 12 deletions tests/Cases/DateTime.phpt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?php declare(strict_types = 1);

/**
* Test: DateTime
*/

require_once __DIR__ . '/../bootstrap.php';

use Contributte\Tester\Toolkit;
use Contributte\Utils\DateTime;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

// DateTime::setCurrentTime()
test(function (): void {
Toolkit::test(function (): void {
$dt = DateTime::from('2020-10-10');
Assert::equal('10.10.2020 00:00:00', $dt->format('d.m.Y H:i:s'));

Expand All @@ -19,7 +16,7 @@ test(function (): void {
});

// DateTime::create
test(function (): void {
Toolkit::test(function (): void {
$dt = DateTime::create([]);
Assert::equal(DateTime::from(sprintf('%s.%s.%s', date('d'), date('m'), date('Y'))), $dt);

Expand All @@ -34,7 +31,7 @@ test(function (): void {
});

// DateTime::createBy
test(function (): void {
Toolkit::test(function (): void {
$dt = DateTime::createBy(2020, 6, 1);
Assert::equal(DateTime::from('2020-06-01'), $dt);
});
Expand All @@ -44,7 +41,7 @@ test(function (): void {
// DateTime::getFirstDayOfYear
// DateTime::getLastDayOfYear
// DateTime::getFirstDayOfMonth
test(function (): void {
Toolkit::test(function (): void {
$dt = new DateTime('15.6.2020');
Assert::equal(DateTime::from('1.6.2020 00:00:00'), $dt->getFirstDayOfMonth());
Assert::equal(DateTime::from('30.6.2020 23:59:59'), $dt->getLastDayOfMonth());
Expand All @@ -54,7 +51,7 @@ test(function (): void {

// DateTime::getFirstDayOfWeek
// DateTime::getLastDayOfWeek
test(function (): void {
Toolkit::test(function (): void {
$dt = new DateTime('18.6.2020');
Assert::equal(DateTime::from('15.6.2020 00:00:00'), $dt->getFirstDayOfWeek());
Assert::equal(DateTime::from('21.6.2020 23:59:59'), $dt->getLastDayOfWeek());
Expand All @@ -65,7 +62,7 @@ test(function (): void {
});

// DateTime::setToday
test(function (): void {
Toolkit::test(function (): void {
$dt = DateTime::createBy(2020, 6, 1);
$dt = $dt->setToday();
Assert::equal(date('d.m.Y'), $dt->format('d.m.Y'));
Expand Down
7 changes: 3 additions & 4 deletions tests/Cases/DeeperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Tests\Cases;

require_once __DIR__ . '/../bootstrap.php';

use Contributte\Utils\Deeper;
use Nette\InvalidArgumentException;
use Tester\Assert;
use Tester\TestCase;

require_once __DIR__ . '/../bootstrap.php';

class DeeperTest extends TestCase
{

Expand All @@ -34,10 +34,9 @@ public function testGetFailure(): void

/**
* @dataProvider validFlatProvider
* @param mixed $key
* @param mixed[] $array
*/
public function testFlat($key, array $array): void
public function testFlat(mixed $key, array $array): void
{
Assert::same($array, Deeper::flat($key));
}
Expand Down
17 changes: 7 additions & 10 deletions tests/Cases/Fields.phpt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?php declare(strict_types = 1);

/**
* Test: Fields
*/

require_once __DIR__ . '/../bootstrap.php';

use Contributte\Tester\Toolkit;
use Contributte\Utils\Fields;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

// Fields::inn
test(function (): void {
Toolkit::test(function (): void {
Assert::equal('11223344', Fields::inn('11223344'));
Assert::equal('11223344', Fields::inn('11-22-33-44'));
Assert::equal('11223344', Fields::inn('11 22 33 44'));
Expand All @@ -21,7 +18,7 @@ test(function (): void {
});

// Fields::tin
test(function (): void {
Toolkit::test(function (): void {
Assert::equal('CZ11223344', Fields::tin('CZ11223344'));
Assert::equal('CZ11223344', Fields::tin('CZ11-22-33-44'));
Assert::equal('CZ11223344', Fields::tin('CZ 11 22 33 44'));
Expand All @@ -32,7 +29,7 @@ test(function (): void {
});

// Fields::phone
test(function (): void {
Toolkit::test(function (): void {
Assert::equal('123456789', Fields::phone('123456789'));
Assert::equal('123456789', Fields::phone(' 123456789 '));
Assert::equal('123456789', Fields::phone(' 123 456 789 '));
Expand All @@ -42,7 +39,7 @@ test(function (): void {
});

// Fields::zip
test(function (): void {
Toolkit::test(function (): void {
Assert::equal('10000', Fields::zip('10000'));
Assert::equal('10000', Fields::zip('10 000'));
Assert::equal('10000', Fields::zip(' 10000 '));
Expand Down
11 changes: 4 additions & 7 deletions tests/Cases/Http.phpt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<?php declare(strict_types = 1);

/**
* Test: Http
*/

require_once __DIR__ . '/../bootstrap.php';

use Contributte\Tester\Toolkit;
use Contributte\Utils\Http;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

// Http::metadata
test(function (): void {
Toolkit::test(function (): void {
Assert::equal([
'bar' => 'foo',
'bar1' => 'foo',
Expand Down
7 changes: 3 additions & 4 deletions tests/Cases/LazyCollection.phpt
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?php declare(strict_types = 1);

use Contributte\Tester\Toolkit;
use Contributte\Utils\LazyCollection;
use Tester\Assert;

require_once __DIR__ . '/../bootstrap.php';

test(function (): void {
Toolkit::test(function (): void {
$data = ['foo', 'bar', 'baz'];

$callback = function () use ($data): array {
return $data;
};
$callback = fn (): array => $data;

$collection = LazyCollection::fromCallback($callback);

Expand Down
Loading

0 comments on commit 632c776

Please sign in to comment.