Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ae23e6

Browse files
committed
minor #48980 [Tests] Remove $this occurrences in future static data providers (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Tests] Remove `$this` occurrences in future static data providers | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes-ish | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Easing #48668 (comment) | License | MIT | Doc PR | _NA_ Commits ------- 6fb7cb9 [Tests] Remove `$this` occurrences in future static data providers
2 parents e9be173 + 6fb7cb9 commit 4ae23e6

File tree

9 files changed

+74
-32
lines changed

9 files changed

+74
-32
lines changed

src/Symfony/Component/DomCrawler/Tests/Html5ParserCrawlerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@ public function testHtml5ParserWithInvalidHeadedContent(string $content)
5252

5353
public function validHtml5Provider(): iterable
5454
{
55-
$html = $this->getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
55+
$html = static::getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
5656
$BOM = \chr(0xEF).\chr(0xBB).\chr(0xBF);
5757

5858
yield 'BOM first' => [$BOM.$html];
5959
yield 'Single comment' => ['<!-- comment -->'.$html];
6060
yield 'Multiline comment' => ["<!-- \n multiline comment \n -->".$html];
6161
yield 'Several comments' => ['<!--c--> <!--cc-->'.$html];
6262
yield 'Whitespaces' => [' '.$html];
63-
yield 'All together' => [$BOM.' '.'<!--c-->'.$html];
63+
yield 'All together' => [$BOM.' <!--c-->'.$html];
6464
}
6565

6666
public function invalidHtml5Provider(): iterable
6767
{
68-
$html = $this->getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
68+
$html = static::getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
6969

7070
yield 'Text' => ['hello world'.$html];
7171
yield 'Text between comments' => ['<!--c--> test <!--cc-->'.$html];

src/Symfony/Component/ExpressionLanguage/Tests/ExpressionLanguageTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,19 @@ public function testParseThrowsInsteadOfNotice()
121121

122122
public function shortCircuitProviderEvaluate()
123123
{
124-
$object = $this->getMockBuilder(\stdClass::class)->setMethods(['foo'])->getMock();
125-
$object->expects($this->never())->method('foo');
124+
$object = new class(\Closure::fromCallable([static::class, 'fail'])) {
125+
private $fail;
126+
127+
public function __construct(callable $fail)
128+
{
129+
$this->fail = $fail;
130+
}
131+
132+
public function foo()
133+
{
134+
($this->fail)();
135+
}
136+
};
126137

127138
return [
128139
['false and object.foo()', ['object' => $object], false],

src/Symfony/Component/Filesystem/Tests/PathTest.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,30 @@ public function providePathTests(): \Generator
458458
yield ['..', '/webmozart/symfony', '/webmozart'];
459459
}
460460

461+
private static function getPathTests(): \Generator
462+
{
463+
yield from [
464+
// relative to absolute path
465+
['css/style.css', '/webmozart/symfony', '/webmozart/symfony/css/style.css'],
466+
['../css/style.css', '/webmozart/symfony', '/webmozart/css/style.css'],
467+
['../../css/style.css', '/webmozart/symfony', '/css/style.css'],
468+
469+
// relative to root
470+
['css/style.css', '/', '/css/style.css'],
471+
['css/style.css', 'C:', 'C:/css/style.css'],
472+
['css/style.css', 'C:/', 'C:/css/style.css'],
473+
474+
// same sub directories in different base directories
475+
['../../symfony/css/style.css', '/webmozart/css', '/symfony/css/style.css'],
476+
477+
['', '/webmozart/symfony', '/webmozart/symfony'],
478+
['..', '/webmozart/symfony', '/webmozart'],
479+
];
480+
}
481+
461482
public function provideMakeAbsoluteTests(): \Generator
462483
{
463-
foreach ($this->providePathTests() as $set) {
464-
yield $set;
465-
}
484+
yield from static::getPathTests();
466485

467486
// collapse dots
468487
yield ['css/./style.css', '/webmozart/symfony', '/webmozart/symfony/css/style.css'];
@@ -589,7 +608,7 @@ public function testMakeAbsoluteDoesNotFailIfDifferentRoot(string $basePath, str
589608

590609
public function provideMakeRelativeTests(): \Generator
591610
{
592-
foreach ($this->providePathTests() as $set) {
611+
foreach (static::getPathTests() as $set) {
593612
yield [$set[2], $set[1], $set[0]];
594613
}
595614

src/Symfony/Component/Finder/Tests/Iterator/DepthRangeFilterIteratorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ public function getAcceptData()
9393
];
9494

9595
return [
96-
[0, 0, $this->toAbsolute($lessThan1)],
97-
[0, 1, $this->toAbsolute($lessThanOrEqualTo1)],
96+
[0, 0, static::toAbsolute($lessThan1)],
97+
[0, 1, static::toAbsolute($lessThanOrEqualTo1)],
9898
[2, \PHP_INT_MAX, []],
99-
[1, \PHP_INT_MAX, $this->toAbsolute($graterThanOrEqualTo1)],
100-
[1, 1, $this->toAbsolute($equalTo1)],
99+
[1, \PHP_INT_MAX, static::toAbsolute($graterThanOrEqualTo1)],
100+
[1, 1, static::toAbsolute($equalTo1)],
101101
];
102102
}
103103
}

src/Symfony/Component/Finder/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public function getAcceptData()
9999
];
100100

101101
return [
102-
[['foo'], $this->toAbsolute($foo)],
103-
[['fo'], $this->toAbsolute($fo)],
104-
[['toto/'], $this->toAbsolute($toto)],
102+
[['foo'], static::toAbsolute($foo)],
103+
[['fo'], static::toAbsolute($fo)],
104+
[['toto/'], static::toAbsolute($toto)],
105105
];
106106
}
107107
}

src/Symfony/Component/Finder/Tests/Iterator/FileTypeFilterIteratorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public function getAcceptData()
5757
];
5858

5959
return [
60-
[FileTypeFilterIterator::ONLY_FILES, $this->toAbsolute($onlyFiles)],
61-
[FileTypeFilterIterator::ONLY_DIRECTORIES, $this->toAbsolute($onlyDirectories)],
60+
[FileTypeFilterIterator::ONLY_FILES, static::toAbsolute($onlyFiles)],
61+
[FileTypeFilterIterator::ONLY_DIRECTORIES, static::toAbsolute($onlyDirectories)],
6262
];
6363
}
6464
}

src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ public function getAcceptData()
247247
];
248248

249249
return [
250-
[SortableIterator::SORT_BY_NAME, $this->toAbsolute($sortByName)],
251-
[SortableIterator::SORT_BY_TYPE, $this->toAbsolute($sortByType)],
252-
[SortableIterator::SORT_BY_ACCESSED_TIME, $this->toAbsolute($sortByAccessedTime)],
253-
[SortableIterator::SORT_BY_CHANGED_TIME, $this->toAbsolute($sortByChangedTime)],
254-
[SortableIterator::SORT_BY_MODIFIED_TIME, $this->toAbsolute($sortByModifiedTime)],
255-
[SortableIterator::SORT_BY_NAME_NATURAL, $this->toAbsolute($sortByNameNatural)],
256-
[function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, $this->toAbsolute($customComparison)],
250+
[SortableIterator::SORT_BY_NAME, static::toAbsolute($sortByName)],
251+
[SortableIterator::SORT_BY_TYPE, static::toAbsolute($sortByType)],
252+
[SortableIterator::SORT_BY_ACCESSED_TIME, static::toAbsolute($sortByAccessedTime)],
253+
[SortableIterator::SORT_BY_CHANGED_TIME, static::toAbsolute($sortByChangedTime)],
254+
[SortableIterator::SORT_BY_MODIFIED_TIME, static::toAbsolute($sortByModifiedTime)],
255+
[SortableIterator::SORT_BY_NAME_NATURAL, static::toAbsolute($sortByNameNatural)],
256+
[function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, static::toAbsolute($customComparison)],
257257
];
258258
}
259259
}

src/Symfony/Component/HttpKernel/Tests/EventListener/ErrorListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public function controllerProvider()
209209
}];
210210

211211
yield [function ($exception) {
212-
$this->assertInstanceOf(FlattenException::class, $exception);
212+
static::assertInstanceOf(FlattenException::class, $exception);
213213

214214
return new Response('OK: '.$exception->getMessage());
215215
}];

src/Symfony/Component/Messenger/Tests/Middleware/HandleMessageMiddlewareTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,28 @@ public function testItAddsHandledStamps(array $handlers, array $expectedStamps,
6969

7070
public function itAddsHandledStampsProvider(): iterable
7171
{
72-
$first = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
73-
$first->method('__invoke')->willReturn('first result');
72+
$first = new class() extends HandleMessageMiddlewareTestCallable {
73+
public function __invoke()
74+
{
75+
return 'first result';
76+
}
77+
};
7478
$firstClass = \get_class($first);
7579

76-
$second = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
77-
$second->method('__invoke')->willReturn(null);
80+
$second = new class() extends HandleMessageMiddlewareTestCallable {
81+
public function __invoke()
82+
{
83+
return null;
84+
}
85+
};
7886
$secondClass = \get_class($second);
7987

80-
$failing = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
81-
$failing->method('__invoke')->will($this->throwException(new \Exception('handler failed.')));
88+
$failing = new class() extends HandleMessageMiddlewareTestCallable {
89+
public function __invoke()
90+
{
91+
throw new \Exception('handler failed.');
92+
}
93+
};
8294

8395
yield 'A stamp is added' => [
8496
[$first],

0 commit comments

Comments
 (0)