Skip to content
Draft
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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
**Learning:** When checking if a `DomCrawler` filter matched any elements, `assertGreaterThan(0, count($node))` was used. Since `$node` is an object implementing `Countable`, the global `count()` function checks the interface and dispatches to `$node->count()`. Calling `$node->count()` directly bypasses this overhead, resulting in slightly faster execution times (~2x speedup in isolated microbenchmarks).

**Action:** Replaced `count($node)` with `$node->count()` in `BrowserAssertionsTrait` and `FormAssertionsTrait`.
## 2024-05-18 - Optimize File Search with `glob()`
**Learning:** For simple, single-directory file searches (depth 0), using the native PHP `glob()` function is significantly faster than using the `Symfony\Component\Finder\Finder` component due to reduced object instantiation and iterator overhead. When checking for `*Kernel.php` files in a given app path, `glob()` provides a clean, native solution. Make sure to use the null coalescing operator (`?: []`) to safely handle `glob()` returning `false` on some file systems.
**Action:** Replaced `Symfony\Component\Finder\Finder` with `glob($path . DIRECTORY_SEPARATOR . '*Kernel.php') ?: []` in `getKernelClass()` within `src/Codeception/Module/Symfony.php` to improve performance. Unused `Finder` import was subsequently removed.
5 changes: 2 additions & 3 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Profiler\Profile;
Expand Down Expand Up @@ -334,8 +333,8 @@ protected function getKernelClass(): string
if (file_exists($expectedKernelPath)) {
include_once $expectedKernelPath;
} else {
foreach ((new Finder())->name('*Kernel.php')->depth('0')->in($path) as $file) {
include_once $file->getRealPath();
foreach (glob($path . DIRECTORY_SEPARATOR . '*Kernel.php') ?: [] as $file) {
include_once $file;
}
}

Expand Down