Skip to content

Commit 9b4cc54

Browse files
committed
Reorganize test suites
1 parent 90cd729 commit 9b4cc54

1 file changed

Lines changed: 22 additions & 24 deletions

File tree

tests/RuntimeChecker/ReturnCheckerTest.php

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use TypePHP\Internal\ErrorMessage;
88
use TypePHP\Tests\Fixtures\Collections\ConcreteFileCollection;
99
use TypePHP\Tests\Fixtures\Collections\PluginConfiguration;
10-
use TypePHP\Tests\Fixtures\Conditionals\ConditionalReturnService;
10+
use TypePHP\Tests\Fixtures\Conditionals\ConditionalReturnService;;
1111
use TypePHP\Tests\Fixtures\Generics\DogConditionalBox;
1212
use TypePHP\Tests\Fixtures\Services\AdminEntityFactory;
1313
use TypePHP\Tests\Fixtures\Services\FluentService;
@@ -19,6 +19,7 @@
1919
describe('ReturnChecker Unit Tests', function () {
2020
beforeEach(function () {
2121
Config::reset();
22+
Config::set(['returns' => true]);
2223
});
2324

2425
afterEach(function () {
@@ -44,19 +45,22 @@
4445
$result = ReturnChecker::checkReturn($target, $badValue, new UserService(), ['id' => -5], $registry, fn () => null);
4546

4647
expect($result)->toBeInstanceOf(ErrorMessage::class)
47-
->and($result->getMessage())->toContain("Return value['id'] must be of type positive-int")
48-
;
48+
->and($result->getMessage())->toContain("Return value['id'] must be of type positive-int");
4949
});
5050

5151
test('returns value directly when returns checking is disabled in config', function () {
52-
Config::set(['returns' => false]);
53-
$registry = new TypeValidatorRegistry();
54-
$target = UserService::class . '::find';
55-
56-
$badValue = ['id' => -99, 'name' => 'Alice'];
57-
$result = ReturnChecker::checkReturn($target, $badValue, new UserService(), ['id' => -99], $registry, fn () => null);
58-
59-
expect($result)->toBe($badValue);
52+
try {
53+
Config::set(['returns' => false]);
54+
$registry = new TypeValidatorRegistry();
55+
$target = UserService::class . '::find';
56+
57+
$badValue = ['id' => -99, 'name' => 'Alice'];
58+
$result = ReturnChecker::checkReturn($target, $badValue, new UserService(), ['id' => -99], $registry, fn () => null);
59+
60+
expect($result)->toBe($badValue);
61+
} finally {
62+
Config::reset();
63+
}
6064
});
6165
});
6266

@@ -79,8 +83,7 @@
7983
$result = ReturnChecker::checkReturn($target, new FluentService(), $service, [], $registry, fn () => null);
8084

8185
expect($result)->toBeInstanceOf(ErrorMessage::class)
82-
->and($result->getMessage())->toContain('must be $this instance')
83-
;
86+
->and($result->getMessage())->toContain('must be $this instance');
8487
});
8588
});
8689

@@ -103,8 +106,7 @@
103106
$result = ReturnChecker::checkReturn($target, $siblingInstance, UserEntityFactory::class, [], $registry, fn () => null);
104107

105108
expect($result)->toBeInstanceOf(ErrorMessage::class)
106-
->and($result->getMessage())->toContain('must be of type TypePHP\Tests\Fixtures\Services\UserEntityFactory')
107-
;
109+
->and($result->getMessage())->toContain('must be of type TypePHP\Tests\Fixtures\Services\UserEntityFactory');
108110
});
109111
});
110112

@@ -119,8 +121,7 @@
119121

120122
$badResult = ReturnChecker::checkReturn($target, -10, $service, ['format' => 'int', 'value' => -10], $registry, fn () => null);
121123
expect($badResult)->toBeInstanceOf(ErrorMessage::class)
122-
->and($badResult->getMessage())->toContain('positive-int')
123-
;
124+
->and($badResult->getMessage())->toContain('positive-int');
124125
});
125126

126127
test('evaluates fallback else branch (non-empty-string)', function () {
@@ -133,8 +134,7 @@
133134

134135
$badResult = ReturnChecker::checkReturn($target, '', $service, ['format' => 'other', 'value' => ''], $registry, fn () => null);
135136
expect($badResult)->toBeInstanceOf(ErrorMessage::class)
136-
->and($badResult->getMessage())->toContain('non-empty-string')
137-
;
137+
->and($badResult->getMessage())->toContain('non-empty-string');
138138
});
139139

140140
test('evaluates negated parameter conditions ($flag is not true)', function () {
@@ -161,8 +161,7 @@
161161

162162
$badResult = ReturnChecker::checkReturn($target, -50, $box, ['input' => -50], $registry, fn () => null);
163163
expect($badResult)->toBeInstanceOf(ErrorMessage::class)
164-
->and($badResult->getMessage())->toContain('positive-int')
165-
;
164+
->and($badResult->getMessage())->toContain('positive-int');
166165
});
167166
});
168167

@@ -193,8 +192,7 @@
193192
], $registry, fn () => null);
194193

195194
expect($result)->toBeInstanceOf(ErrorMessage::class)
196-
->and($result->getMessage())->toContain("Return value['id'] must be of type positive-int")
197-
;
195+
->and($result->getMessage())->toContain("Return value['id'] must be of type positive-int");
198196
});
199197
});
200198

@@ -224,4 +222,4 @@ function () use (&$wrappedCalled) {
224222
->and($wrappedCalled)->toBeFalse();
225223
});
226224
});
227-
});
225+
});

0 commit comments

Comments
 (0)