Skip to content

Commit edd0652

Browse files
committed
update tests
1 parent b09ac2f commit edd0652

50 files changed

Lines changed: 199 additions & 337 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
"ext-curl": "*"
2222
},
2323
"require-dev": {
24-
"phpstan/phpstan": "^1.9",
24+
"phpstan/phpstan": "^2",
2525
"nette/tester": "^2",
26-
"mockery/mockery": "1.4.2",
27-
"tracy/tracy": "^2.9",
28-
"rector/rector": "^0.16"
26+
"mockery/mockery": "^1.6",
27+
"tracy/tracy": "^2.9"
2928
},
3029
"scripts": {
3130
"tester": "tester -C tests --colors=1",
32-
"coverage": "tester -C --coverage=coverage.html --coverage-src=src --colors=1",
31+
"coverage": "tester -C --coverage=coverage.html --coverage-src=src --colors=1 -o console-lines",
3332
"phpstan": "phpstan analyse -c phpstan.neon --memory-limit=1G"
3433
}
3534
}

rector.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/DI/FactoryStatic.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use function is_callable;
1111

12+
/**
13+
* @phpstan-ignore trait.unused
14+
*/
1215
trait FactoryStatic
1316
{
1417
private static Container $container;

src/Database/ResultCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ResultCollection implements ArrayAccess, Countable, IteratorAggregate
4343

4444

4545
/**
46-
* @param array<array-key, array<array-key, mixed>> $list
46+
* @param array<array-key, array<array-key, mixed>|mixed> $list
4747
*/
4848
public function __construct(array $list = [])
4949
{

src/Debug/Requirements.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class Requirements
2828
*/
2929
public function run(array $output = []): array
3030
{
31+
/**
32+
* @phpstan-ignore greaterOrEqual.alwaysTrue
33+
*/
3134
$output[] = $this->same(true, PHP_VERSION_ID >= 70400, 'PHP >= 7.4 Version');
3235
$output[] = $this->same(true, extension_loaded('intl'), 'INTL Extension', true);
3336
$output[] = $this->same(true, extension_loaded('curl'), 'cURL Extension', true);

src/Settings/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Settings
1515
use Strict;
1616

1717
/**
18-
* @var array<string, Collection<string, Repository\Entity\Setting>>
18+
* @var array<string, Collection<string, Repository\Entity\Setting>|mixed>
1919
*/
2020
private array $settings = [];
2121

tests/DI/Assets/TestClass.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,14 @@ public function __construct(ConnectionTest $service)
6262
$this->service = $service;
6363
}
6464
}
65+
66+
67+
class TestExternalService
68+
{
69+
public DateTime $service;
70+
71+
public function __construct(DateTime $service)
72+
{
73+
$this->service = $service;
74+
}
75+
}

tests/DI/ContainerTest.phpt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
namespace BulkGate\Plugin\DI\Test;
44

5-
/**
6-
* @author Lukáš Piják 2023 TOPefekt s.r.o.
7-
* @link https://www.bulkgate.com/
8-
*/
5+
require __DIR__ . '/../bootstrap.php';
6+
require_once __DIR__ . '/Assets/TestClass.php';
97

8+
use DateTime;
109
use Tester\{Assert, TestCase};
11-
use Connection, TestClassEntity, ConnectionTest;
10+
use Connection, TestClassEntity, ConnectionTest, TestExternalService;
1211
use BulkGate\Plugin\DI\{AutoWiringException, Container, InvalidStateException, MissingParameterException, MissingServiceException};
1312

14-
require __DIR__ . '/../bootstrap.php';
15-
require_once __DIR__ . '/Assets/TestClass.php';
16-
1713
/**
14+
* @author Lukáš Piják 2023 TOPefekt s.r.o.
15+
* @link https://www.bulkgate.com/
1816
* @testCase
1917
*/
2018
class ContainerTest extends TestCase
@@ -96,6 +94,9 @@ class ContainerTest extends TestCase
9694
$container['entity'] = TestClassEntity::class;
9795

9896
Assert::exception(fn() => $container->getByClass(TestClassEntity::class), MissingParameterException::class, 'Missing \'string\' parameter \'TestClassEntity::$name\'');
97+
98+
$container['external'] = ['factory' => \TestExternalService::class];
99+
Assert::exception(fn () => $container->getByClass(\TestExternalService::class), MissingServiceException::class, "Service 'DateTime' not found");
99100
}
100101

101102

@@ -134,8 +135,11 @@ class ContainerTest extends TestCase
134135
{
135136
$container = new Container('rewrite');
136137
$container['production'] = ['factory' => \ConnectionTest::class, 'factory_method' => fn () => new \ConnectionProduction()];
138+
$container['external'] = ['factory' => \TestExternalService::class, 'factory_method' => fn () => new TestExternalService(new DateTime())];
137139

138140
Assert::exception(fn () => $container->getByClass(\Connection::class), MissingParameterException::class, 'Factory method must return instance of \'ConnectionTest\'');
141+
142+
Assert::type(TestExternalService::class, $container->getByClass(\TestExternalService::class));
139143
}
140144

141145

tests/DI/FactoryTest.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
namespace BulkGate\Plugin\DI\Test;
44

5-
/**
6-
* @author Lukáš Piják 2023 TOPefekt s.r.o.
7-
* @link https://www.bulkgate.com/
8-
*/
5+
require __DIR__ . '/../bootstrap.php';
96

107
use Tester\{Assert, TestCase};
118
use BulkGate\Plugin\DI\{Factory, Container, FactoryStatic};
129

13-
require __DIR__ . '/../bootstrap.php';
14-
1510
/**
11+
* @author Lukáš Piják 2023 TOPefekt s.r.o.
12+
* @link https://www.bulkgate.com/
1613
* @testCase
1714
*/
1815
class FactoryTest extends TestCase

tests/Database/ResultCollectionTest.phpt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,15 @@
22

33
namespace BulkGate\Plugin\Debug\Test;
44

5-
/**
6-
* @author Lukáš Piják 2023 TOPefekt s.r.o.
7-
* @link https://www.bulkgate.com/
8-
*/
5+
require __DIR__ . '/../bootstrap.php';
96

107
use Tester\{Assert, TestCase};
118
use BulkGate\Plugin\Database\Result;
129
use BulkGate\Plugin\Database\ResultCollection;
1310

14-
require __DIR__ . '/../bootstrap.php';
15-
1611
/**
12+
* @author Lukáš Piják 2023 TOPefekt s.r.o.
13+
* @link https://www.bulkgate.com/
1714
* @testCase
1815
*/
1916
class ResultCollectionTest extends TestCase

0 commit comments

Comments
 (0)