Skip to content

Commit 6b487d0

Browse files
Merge branch '5.4' into 6.0
* 5.4: Update ComposerPlugin.php [Notifier] [OvhCloud] handle invalid receiver [Cache] fix collecting cache stats when nesting computations [VarDumper] Fix JS to expand / collapse [Tests] Remove `$this` occurrences in future static data providers
2 parents c351a4d + 39cd93a commit 6b487d0

File tree

15 files changed

+130
-43
lines changed

15 files changed

+130
-43
lines changed

src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private function calculateStatistics(): array
112112
/** @var TraceableAdapterEvent $call */
113113
foreach ($calls as $call) {
114114
++$statistics[$name]['calls'];
115-
$statistics[$name]['time'] += $call->end - $call->start;
115+
$statistics[$name]['time'] += ($call->end ?? microtime(true)) - $call->start;
116116
if ('get' === $call->name) {
117117
++$statistics[$name]['reads'];
118118
if ($call->hits) {
@@ -134,10 +134,8 @@ private function calculateStatistics(): array
134134
$statistics[$name]['misses'] += $call->misses;
135135
} elseif ('hasItem' === $call->name) {
136136
++$statistics[$name]['reads'];
137-
if (false === $call->result) {
138-
++$statistics[$name]['misses'];
139-
} else {
140-
++$statistics[$name]['hits'];
137+
foreach ($call->result ?? [] as $result) {
138+
++$statistics[$name][$result ? 'hits' : 'misses'];
141139
}
142140
} elseif ('save' === $call->name) {
143141
++$statistics[$name]['writes'];

src/Symfony/Component/Cache/Tests/DataCollector/CacheDataCollectorTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Cache\Tests\DataCollector;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Cache\Adapter\NullAdapter;
1516
use Symfony\Component\Cache\Adapter\TraceableAdapter;
1617
use Symfony\Component\Cache\DataCollector\CacheDataCollector;
1718
use Symfony\Component\HttpFoundation\Request;
@@ -55,16 +56,16 @@ public function testHitedEventDataCollector()
5556
$traceableAdapterEvent->name = 'hasItem';
5657
$traceableAdapterEvent->start = 0;
5758
$traceableAdapterEvent->end = 0;
58-
$traceableAdapterEvent->hits = 1;
59+
$traceableAdapterEvent->hits = 0;
5960
$traceableAdapterEvent->misses = 0;
6061
$traceableAdapterEvent->result = ['foo' => false];
6162

6263
$statistics = $this->getCacheDataCollectorStatisticsFromEvents([$traceableAdapterEvent]);
6364

6465
$this->assertEquals($statistics[self::INSTANCE_NAME]['calls'], 1, 'calls');
6566
$this->assertEquals($statistics[self::INSTANCE_NAME]['reads'], 1, 'reads');
66-
$this->assertEquals($statistics[self::INSTANCE_NAME]['hits'], 1, 'hits');
67-
$this->assertEquals($statistics[self::INSTANCE_NAME]['misses'], 0, 'misses');
67+
$this->assertEquals($statistics[self::INSTANCE_NAME]['hits'], 0, 'hits');
68+
$this->assertEquals($statistics[self::INSTANCE_NAME]['misses'], 1, 'misses');
6869
$this->assertEquals($statistics[self::INSTANCE_NAME]['writes'], 0, 'writes');
6970
}
7071

@@ -84,6 +85,25 @@ public function testSavedEventDataCollector()
8485
$this->assertEquals($statistics[self::INSTANCE_NAME]['writes'], 1, 'writes');
8586
}
8687

88+
public function testCollectBeforeEnd()
89+
{
90+
$adapter = new TraceableAdapter(new NullAdapter());
91+
92+
$collector = new CacheDataCollector();
93+
$collector->addInstance(self::INSTANCE_NAME, $adapter);
94+
95+
$adapter->get('foo', function () use ($collector) {
96+
$collector->collect(new Request(), new Response());
97+
98+
return 123;
99+
});
100+
101+
$stats = $collector->getStatistics();
102+
$this->assertGreaterThan(0, $stats[self::INSTANCE_NAME]['time']);
103+
$this->assertEquals($stats[self::INSTANCE_NAME]['hits'], 0, 'hits');
104+
$this->assertEquals($stats[self::INSTANCE_NAME]['misses'], 1, 'misses');
105+
}
106+
87107
private function getCacheDataCollectorStatisticsFromEvents(array $traceableAdapterEvents)
88108
{
89109
$traceableAdapterMock = $this->createMock(TraceableAdapter::class);

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
}];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy