Skip to content

Commit

Permalink
Merge pull request #6481 from Codeception/4.2-execute-before-after-cl…
Browse files Browse the repository at this point in the history
…ass-hooks-once

Execute before/after class hooks only once
  • Loading branch information
Naktibalda committed Jun 21, 2022
2 parents 0f93270 + a9a4c27 commit 2bc7b3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Codeception/Subscriber/BeforeAfterTest.php
Expand Up @@ -20,6 +20,8 @@ class BeforeAfterTest implements EventSubscriberInterface

public function beforeClass(SuiteEvent $e)
{
$this->hooks = [];

foreach ($e->getSuite()->tests() as $test) {
/** @var $test \PHPUnit\Framework\Test * */
$testClass = get_class($test);
Expand Down
11 changes: 11 additions & 0 deletions tests/cli/OrderCest.php
Expand Up @@ -114,4 +114,15 @@ public function checkBootstrapIsLoadedBeforeTests(CliGuy $I)
$I->seeFileFound('order.txt', 'tests/_output');
$I->seeInThisFile('BIBP(T)');
}

public function checkAfterBeforeHooksAreExecutedOnlyOnce(CliGuy $I)
{
$I->amInPath('tests/data/sandbox');
$I->executeCommand('run math,order,scenario,skipped :BeforeAfterClassTest');
$I->seeFileFound('order.txt', 'tests/_output');
// Codeception 4 executes beforeClass hooks of all classes in TestSuite
// Codeception 5 - only matching
$I->seeInThisFile('BIBP({{{{[1][2]}}}})');
// $I->seeInThisFile('BIB({[1][2]})'); // Codeception 5 behaviour
}
}

0 comments on commit 2bc7b3d

Please sign in to comment.