Skip to content

Commit bb53ec1

Browse files
committed
minor symfony#58160 stop using TestCase::iniSet() (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- stop using `TestCase::iniSet()` | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- eb3db82 stop using TestCase::iniSet()
2 parents 4a7a68e + eb3db82 commit bb53ec1

File tree

3 files changed

+60
-46
lines changed

3 files changed

+60
-46
lines changed

src/Symfony/Component/Emoji/Tests/EmojiTransliteratorTest.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,34 +135,42 @@ public function testNotUtf8()
135135
{
136136
$tr = EmojiTransliterator::create('emoji-en');
137137

138-
$this->iniSet('intl.use_exceptions', 0);
138+
$oldUseExceptionsValue = ini_set('intl.use_exceptions', 0);
139139

140-
$this->assertFalse($tr->transliterate("Not \xE9 UTF-8"));
141-
$this->assertSame('String conversion of string to UTF-16 failed: U_INVALID_CHAR_FOUND', intl_get_error_message());
140+
try {
141+
$this->assertFalse($tr->transliterate("Not \xE9 UTF-8"));
142+
$this->assertSame('String conversion of string to UTF-16 failed: U_INVALID_CHAR_FOUND', intl_get_error_message());
142143

143-
$this->iniSet('intl.use_exceptions', 1);
144+
ini_set('intl.use_exceptions', 1);
144145

145-
$this->expectException(\IntlException::class);
146-
$this->expectExceptionMessage('String conversion of string to UTF-16 failed');
146+
$this->expectException(\IntlException::class);
147+
$this->expectExceptionMessage('String conversion of string to UTF-16 failed');
147148

148-
$tr->transliterate("Not \xE9 UTF-8");
149+
$tr->transliterate("Not \xE9 UTF-8");
150+
} finally {
151+
ini_set('intl.use_exceptions', $oldUseExceptionsValue);
152+
}
149153
}
150154

151155
public function testBadOffsets()
152156
{
153157
$tr = EmojiTransliterator::create('emoji-en');
154158

155-
$this->iniSet('intl.use_exceptions', 0);
159+
$oldUseExceptionsValue = ini_set('intl.use_exceptions', 0);
156160

157-
$this->assertFalse($tr->transliterate('Abc', 1, 5));
158-
$this->assertSame('transliterator_transliterate: Neither "start" nor the "end" arguments can exceed the number of UTF-16 code units (in this case, 3): U_ILLEGAL_ARGUMENT_ERROR', intl_get_error_message());
161+
try {
162+
$this->assertFalse($tr->transliterate('Abc', 1, 5));
163+
$this->assertSame('transliterator_transliterate: Neither "start" nor the "end" arguments can exceed the number of UTF-16 code units (in this case, 3): U_ILLEGAL_ARGUMENT_ERROR', intl_get_error_message());
159164

160-
$this->iniSet('intl.use_exceptions', 1);
165+
ini_set('intl.use_exceptions', 1);
161166

162-
$this->expectException(\IntlException::class);
163-
$this->expectExceptionMessage('transliterator_transliterate: Neither "start" nor the "end" arguments can exceed the number of UTF-16 code units (in this case, 3)');
167+
$this->expectException(\IntlException::class);
168+
$this->expectExceptionMessage('transliterator_transliterate: Neither "start" nor the "end" arguments can exceed the number of UTF-16 code units (in this case, 3)');
164169

165-
$this->assertFalse($tr->transliterate('Abc', 1, 5));
170+
$this->assertFalse($tr->transliterate('Abc', 1, 5));
171+
} finally {
172+
ini_set('intl.use_exceptions', $oldUseExceptionsValue);
173+
}
166174
}
167175

168176
public function testReverse()

src/Symfony/Component/Finder/Tests/FinderOpenBasedirTest.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,29 @@ public function testIgnoreVCSIgnoredWithOpenBasedir()
3535
->ignoreVCSIgnored(true)
3636
);
3737

38-
$this->iniSet('open_basedir', \dirname(__DIR__, 5).\PATH_SEPARATOR.self::toAbsolute('gitignore/search_root'));
39-
40-
$this->assertIterator(self::toAbsolute([
41-
'gitignore/search_root/b.txt',
42-
'gitignore/search_root/c.txt',
43-
'gitignore/search_root/dir',
44-
'gitignore/search_root/dir/a.txt',
45-
'gitignore/search_root/dir/c.txt',
46-
]), $finder->in(self::toAbsolute('gitignore/search_root'))->getIterator());
38+
$openBaseDir = \dirname(__DIR__, 5).\PATH_SEPARATOR.self::toAbsolute('gitignore/search_root');
39+
40+
if ($deprecationsFile = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
41+
$openBaseDir .= \PATH_SEPARATOR.$deprecationsFile;
42+
}
43+
44+
$oldOpenBaseDir = ini_set('open_basedir', $openBaseDir);
45+
46+
try {
47+
$this->assertIterator(self::toAbsolute([
48+
'gitignore/search_root/b.txt',
49+
'gitignore/search_root/c.txt',
50+
'gitignore/search_root/dir',
51+
'gitignore/search_root/dir/a.txt',
52+
'gitignore/search_root/dir/c.txt',
53+
]), $finder->in(self::toAbsolute('gitignore/search_root'))->getIterator());
54+
} finally {
55+
ini_set('open_basedir', $oldOpenBaseDir);
56+
}
4757
}
4858

4959
protected function buildFinder()
5060
{
5161
return Finder::create()->exclude('gitignore');
5262
}
53-
54-
protected function iniSet(string $varName, string $newValue): void
55-
{
56-
if ('open_basedir' === $varName && $deprecationsFile = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
57-
$newValue .= \PATH_SEPARATOR.$deprecationsFile;
58-
}
59-
60-
parent::iniSet($varName, $newValue);
61-
}
6263
}

src/Symfony/Component/HttpFoundation/Tests/UriSignerTest.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,25 @@ public function testCheck()
6464

6565
public function testCheckWithDifferentArgSeparator()
6666
{
67-
$this->iniSet('arg_separator.output', '&');
68-
$signer = new UriSigner('foobar');
69-
70-
$this->assertSame(
71-
'http://example.com/foo?_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D&baz=bay&foo=bar',
72-
$signer->sign('http://example.com/foo?foo=bar&baz=bay')
73-
);
74-
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
75-
76-
$this->assertSame(
77-
'http://example.com/foo?_expiration=2145916800&_hash=xLhnPMzV3KqqHaaUffBUJvtRDAZ4%2FZ9Y8Sw%2BgmS%2B82Q%3D&baz=bay&foo=bar',
78-
$signer->sign('http://example.com/foo?foo=bar&baz=bay', new \DateTimeImmutable('2038-01-01 00:00:00', new \DateTimeZone('UTC')))
79-
);
80-
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay', new \DateTimeImmutable('2099-01-01 00:00:00'))));
67+
$oldArgSeparatorOutputValue = ini_set('arg_separator.output', '&');
68+
69+
try {
70+
$signer = new UriSigner('foobar');
71+
72+
$this->assertSame(
73+
'http://example.com/foo?_hash=rIOcC%2FF3DoEGo%2FvnESjSp7uU9zA9S%2F%2BOLhxgMexoPUM%3D&baz=bay&foo=bar',
74+
$signer->sign('http://example.com/foo?foo=bar&baz=bay')
75+
);
76+
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay')));
77+
78+
$this->assertSame(
79+
'http://example.com/foo?_expiration=2145916800&_hash=xLhnPMzV3KqqHaaUffBUJvtRDAZ4%2FZ9Y8Sw%2BgmS%2B82Q%3D&baz=bay&foo=bar',
80+
$signer->sign('http://example.com/foo?foo=bar&baz=bay', new \DateTimeImmutable('2038-01-01 00:00:00', new \DateTimeZone('UTC')))
81+
);
82+
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&baz=bay', new \DateTimeImmutable('2099-01-01 00:00:00'))));
83+
} finally {
84+
ini_set('arg_separator.output', $oldArgSeparatorOutputValue);
85+
}
8186
}
8287

8388
public function testCheckWithRequest()

0 commit comments

Comments
 (0)