Skip to content

Commit e4cdf95

Browse files
authored
⚡ Bolt: [performance improvement] (#88)
* ⚡ Bolt: Optimize `SessionAssertionsTrait::seeSessionHasValues` 💡 What: Retrieved the current session once before iterating through bindings, and inlined `assertTrue` and `assertSame` assertions instead of repeatedly calling `seeInSession`. 🎯 Why: Calling `seeInSession` inside a loop triggered `$this->getCurrentSession()` repeatedly, causing O(N) repetitive DI container service lookups/checks. 📊 Impact: Eliminates unnecessary overhead and memory usage during array iteration for session assertions, shaving off milliseconds in test execution time. 🔬 Measurement: Run `vendor/bin/phpunit tests/SessionAssertionsTest.php` and observe standard fast execution speeds while guaranteeing no regressions. * Delete .jules/bolt.md
1 parent 7b37157 commit e4cdf95

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/Codeception/Module/Symfony/SessionAssertionsTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,18 @@ public function seeInSession(string $attribute, mixed $value = null): void
164164
*/
165165
public function seeSessionHasValues(array $bindings): void
166166
{
167+
$session = $this->getCurrentSession();
168+
167169
foreach ($bindings as $key => $value) {
168170
if (!is_int($key)) {
169-
$this->seeInSession($key, $value);
171+
$this->assertTrue($session->has($key), "No session attribute with name '{$key}'");
172+
$this->assertSame($value, $session->get($key));
170173
continue;
171174
}
172175
if (!is_string($value)) {
173176
throw new InvalidArgumentException(sprintf('Attribute name must be string, %s given.', get_debug_type($value)));
174177
}
175-
$this->seeInSession($value);
178+
$this->assertTrue($session->has($value), "No session attribute with name '{$value}'");
176179
}
177180
}
178181

0 commit comments

Comments
 (0)