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

Skip to content

[Tests] Remove $this occurrences in future static data providers #48980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ public function testHtml5ParserWithInvalidHeadedContent(string $content)

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

yield 'BOM first' => [$BOM.$html];
yield 'Single comment' => ['<!-- comment -->'.$html];
yield 'Multiline comment' => ["<!-- \n multiline comment \n -->".$html];
yield 'Several comments' => ['<!--c--> <!--cc-->'.$html];
yield 'Whitespaces' => [' '.$html];
yield 'All together' => [$BOM.' '.'<!--c-->'.$html];
yield 'All together' => [$BOM.' <!--c-->'.$html];
}

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

yield 'Text' => ['hello world'.$html];
yield 'Text between comments' => ['<!--c--> test <!--cc-->'.$html];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,19 @@ public function testParseThrowsInsteadOfNotice()

public function shortCircuitProviderEvaluate()
{
$object = $this->getMockBuilder(\stdClass::class)->setMethods(['foo'])->getMock();
$object->expects($this->never())->method('foo');
$object = new class(\Closure::fromCallable([static::class, 'fail'])) {
private $fail;

public function __construct(callable $fail)
{
$this->fail = $fail;
}

public function foo()
{
($this->fail)();
}
};

return [
['false and object.foo()', ['object' => $object], false],
Expand Down
27 changes: 23 additions & 4 deletions src/Symfony/Component/Filesystem/Tests/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,30 @@ public function providePathTests(): \Generator
yield ['..', '/webmozart/symfony', '/webmozart'];
}

private static function getPathTests(): \Generator
{
yield from [
// relative to absolute path
['css/style.css', '/webmozart/symfony', '/webmozart/symfony/css/style.css'],
['../css/style.css', '/webmozart/symfony', '/webmozart/css/style.css'],
['../../css/style.css', '/webmozart/symfony', '/css/style.css'],

// relative to root
['css/style.css', '/', '/css/style.css'],
['css/style.css', 'C:', 'C:/css/style.css'],
['css/style.css', 'C:/', 'C:/css/style.css'],

// same sub directories in different base directories
['../../symfony/css/style.css', '/webmozart/css', '/symfony/css/style.css'],

['', '/webmozart/symfony', '/webmozart/symfony'],
['..', '/webmozart/symfony', '/webmozart'],
];
}

public function provideMakeAbsoluteTests(): \Generator
{
foreach ($this->providePathTests() as $set) {
yield $set;
}
yield from static::getPathTests();

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

public function provideMakeRelativeTests(): \Generator
{
foreach ($this->providePathTests() as $set) {
foreach (static::getPathTests() as $set) {
yield [$set[2], $set[1], $set[0]];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public function getAcceptData()
];

return [
[0, 0, $this->toAbsolute($lessThan1)],
[0, 1, $this->toAbsolute($lessThanOrEqualTo1)],
[0, 0, static::toAbsolute($lessThan1)],
[0, 1, static::toAbsolute($lessThanOrEqualTo1)],
[2, \PHP_INT_MAX, []],
[1, \PHP_INT_MAX, $this->toAbsolute($graterThanOrEqualTo1)],
[1, 1, $this->toAbsolute($equalTo1)],
[1, \PHP_INT_MAX, static::toAbsolute($graterThanOrEqualTo1)],
[1, 1, static::toAbsolute($equalTo1)],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public function getAcceptData()
];

return [
[['foo'], $this->toAbsolute($foo)],
[['fo'], $this->toAbsolute($fo)],
[['toto/'], $this->toAbsolute($toto)],
[['foo'], static::toAbsolute($foo)],
[['fo'], static::toAbsolute($fo)],
[['toto/'], static::toAbsolute($toto)],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public function getAcceptData()
];

return [
[FileTypeFilterIterator::ONLY_FILES, $this->toAbsolute($onlyFiles)],
[FileTypeFilterIterator::ONLY_DIRECTORIES, $this->toAbsolute($onlyDirectories)],
[FileTypeFilterIterator::ONLY_FILES, static::toAbsolute($onlyFiles)],
[FileTypeFilterIterator::ONLY_DIRECTORIES, static::toAbsolute($onlyDirectories)],
];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ public function getAcceptData()
];

return [
[SortableIterator::SORT_BY_NAME, $this->toAbsolute($sortByName)],
[SortableIterator::SORT_BY_TYPE, $this->toAbsolute($sortByType)],
[SortableIterator::SORT_BY_ACCESSED_TIME, $this->toAbsolute($sortByAccessedTime)],
[SortableIterator::SORT_BY_CHANGED_TIME, $this->toAbsolute($sortByChangedTime)],
[SortableIterator::SORT_BY_MODIFIED_TIME, $this->toAbsolute($sortByModifiedTime)],
[SortableIterator::SORT_BY_NAME_NATURAL, $this->toAbsolute($sortByNameNatural)],
[function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, $this->toAbsolute($customComparison)],
[SortableIterator::SORT_BY_NAME, static::toAbsolute($sortByName)],
[SortableIterator::SORT_BY_TYPE, static::toAbsolute($sortByType)],
[SortableIterator::SORT_BY_ACCESSED_TIME, static::toAbsolute($sortByAccessedTime)],
[SortableIterator::SORT_BY_CHANGED_TIME, static::toAbsolute($sortByChangedTime)],
[SortableIterator::SORT_BY_MODIFIED_TIME, static::toAbsolute($sortByModifiedTime)],
[SortableIterator::SORT_BY_NAME_NATURAL, static::toAbsolute($sortByNameNatural)],
[function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, static::toAbsolute($customComparison)],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function controllerProvider()
}];

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

return new Response('OK: '.$exception->getMessage());
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,28 @@ public function testItAddsHandledStamps(array $handlers, array $expectedStamps,

public function itAddsHandledStampsProvider(): iterable
{
$first = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
$first->method('__invoke')->willReturn('first result');
$first = new class() extends HandleMessageMiddlewareTestCallable {
public function __invoke()
{
return 'first result';
}
};
$firstClass = \get_class($first);

$second = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
$second->method('__invoke')->willReturn(null);
$second = new class() extends HandleMessageMiddlewareTestCallable {
public function __invoke()
{
return null;
}
};
$secondClass = \get_class($second);

$failing = $this->createPartialMock(HandleMessageMiddlewareTestCallable::class, ['__invoke']);
$failing->method('__invoke')->will($this->throwException(new \Exception('handler failed.')));
$failing = new class() extends HandleMessageMiddlewareTestCallable {
public function __invoke()
{
throw new \Exception('handler failed.');
}
};

yield 'A stamp is added' => [
[$first],
Expand Down