-
-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/pestphp/pest
- Loading branch information
Showing
4 changed files
with
67 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,56 @@ | ||
<?php | ||
|
||
use Pest\Support\Str; | ||
|
||
global $globalHook; | ||
|
||
uses()->beforeAll(function () use ($globalHook) { | ||
// HACK: we have to determine our $globalHook->calls baseline. This is because | ||
// two other tests are executed before this one due to filename ordering. | ||
$args = $_SERVER['argv'] ?? []; | ||
$single = isset($args[1]) && Str::endsWith(__FILE__, $args[1]); | ||
$offset = $single ? 0 : 2; | ||
|
||
uses()->beforeAll(function () use ($globalHook, $offset) { | ||
expect($globalHook) | ||
->toHaveProperty('beforeAll') | ||
->and($globalHook->beforeAll) | ||
->toBe(0); | ||
->toBe(0) | ||
->and($globalHook->calls) | ||
->beforeAll | ||
->toBe(1 + $offset); | ||
|
||
$globalHook->beforeAll = 1; | ||
$globalHook->calls->beforeAll++; | ||
}); | ||
|
||
beforeAll(function () use ($globalHook) { | ||
beforeAll(function () use ($globalHook, $offset) { | ||
expect($globalHook) | ||
->toHaveProperty('beforeAll') | ||
->and($globalHook->beforeAll) | ||
->toBe(1); | ||
->toBe(1) | ||
->and($globalHook->calls) | ||
->beforeAll | ||
->toBe(2 + $offset); | ||
|
||
$globalHook->beforeAll = 2; | ||
$globalHook->calls->beforeAll++; | ||
}); | ||
|
||
test('global beforeAll execution order', function () use ($globalHook) { | ||
test('global beforeAll execution order', function () use ($globalHook, $offset) { | ||
expect($globalHook) | ||
->toHaveProperty('beforeAll') | ||
->and($globalHook->beforeAll) | ||
->toBe(2); | ||
->toBe(2) | ||
->and($globalHook->calls) | ||
->beforeAll | ||
->toBe(3 + $offset); | ||
}); | ||
|
||
it('only gets called once per file', function () use ($globalHook, $offset) { | ||
expect($globalHook) | ||
->beforeAll | ||
->toBe(2) | ||
->and($globalHook->calls) | ||
->beforeAll | ||
->toBe(3 + $offset); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters