Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async setUp & tearDown #13

Closed
wants to merge 2 commits into from
Closed

Async setUp & tearDown #13

wants to merge 2 commits into from

Conversation

prolic
Copy link

@prolic prolic commented Mar 29, 2020

No description provided.

$promise = call([$this, $this->realTestName], ...$args);
$promise->onResolve(function ($error, $value) use (&$invoked, &$exception, &$returnValue) {
$invoked = true;
$exception = $error;
$returnValue = $value;
yield $this->tearDownAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be a yield inside onResolve.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -146,4 +149,14 @@ abstract class AsyncTestCase extends PHPUnitTestCase

return $mock;
}

protected function setUpAsync(): Promise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether we should use this name or something like beforeEach.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm against, because those names (without Asnyc suffix) are used by PHPUnit and people will immediately understand what those are used for.

@prolic
Copy link
Author

prolic commented Mar 29, 2020 via email

@prolic
Copy link
Author

prolic commented Mar 30, 2020

@kelunik I changed the code a bit and added a test case. Is this good for you to merge?

@prolic prolic closed this Apr 6, 2020
@prolic prolic deleted the patch-1 branch April 6, 2020 17:15
class AsyncTestCaseWithSetUpAndTearDownTest extends AsyncTestCase
{
protected $setupCalled = false;
protected $tearDownCalled = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be reset in setup.

@@ -55,7 +57,21 @@ abstract class AsyncTestCase extends PHPUnitTestCase
$start = \microtime(true);

Loop::run(function () use (&$returnValue, &$exception, &$invoked, $args) {
$promise = call([$this, $this->realTestName], ...$args);
yield $this->setUpAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setup could be moved inside the call, too.

} catch (\Throwable $e) {
}

yield $this->tearDownAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exceptions thrown from teardown should probably be ignored if the actual test already threw an exception, otherwise they're hidden here?

@kelunik
Copy link
Member

kelunik commented Apr 6, 2020

Had these comments in a pending state the whole time.

@prolic
Copy link
Author

prolic commented Apr 6, 2020

@kelunik my branch is obsolete. Check "alt-13" created by @trowski instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants