Skip to content

Commit 68311dd

Browse files
authored
Added grabCollector function (#47)
1 parent 2ea7ed1 commit 68311dd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Codeception/Module/Symfony.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Console\Tester\CommandTester;
2222
use Symfony\Component\DependencyInjection\ContainerInterface;
2323
use Symfony\Component\Finder\Finder;
24+
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
2425
use Symfony\Component\HttpKernel\Kernel;
2526
use Symfony\Component\HttpKernel\Profiler\Profile;
2627
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
@@ -665,6 +666,34 @@ protected function getProfile()
665666
return null;
666667
}
667668

669+
/**
670+
* Grabs a Symfony Data Collector
671+
*
672+
* @param string $collector
673+
* @param string $function
674+
* @param string|null $message
675+
* @return DataCollectorInterface
676+
*/
677+
protected function grabCollector(string $collector, string $function, $message = null): DataCollectorInterface
678+
{
679+
if (!$profile = $this->getProfile()) {
680+
$this->fail(
681+
sprintf("The Profile is needed to use the '%s' function.", $function)
682+
);
683+
}
684+
685+
if (!$profile->hasCollector($collector)) {
686+
if ($message) {
687+
$this->fail($message);
688+
}
689+
$this->fail(
690+
sprintf("The '%s' collector is needed to use the '%s' function.", $collector, $function)
691+
);
692+
}
693+
694+
return $profile->getCollector($collector);
695+
}
696+
668697
/**
669698
* @param $url
670699
*/

0 commit comments

Comments
 (0)