Skip to content

Commit

Permalink
Ensured EM is closed and not cleared on CloseDbConnectionMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Dec 21, 2021
1 parent 9e2994b commit b4a5ffd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [4.2.1] - 2021-12-21
### Added
* *Nothing*

### Changed
* *Nothing*

### Deprecated
* *Nothing*

### Removed
* *Nothing*

### Fixed
* Ensured `CloseDbConnectionMiddleware` closes the EntityManager instead of clearing it.


## [4.2.0] - 2021-12-12
### Added
* Added support for openswoole.
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/CloseDbConnectionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $handler->handle($request);
} finally {
$this->em->getConnection()->close();
$this->em->clear();
$this->em->close();
}
}
}
6 changes: 3 additions & 3 deletions test/Middleware/CloseDbConnectionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setUp(): void
$this->conn->close()->will(function (): void {
});
$this->em->getConnection()->willReturn($this->conn->reveal());
$this->em->clear()->will(function (): void {
$this->em->close()->will(function (): void {
});
$this->em->open()->will(function (): void {
});
Expand All @@ -53,7 +53,7 @@ public function connectionIsClosedWhenMiddlewareIsProcessed(): void
$this->em->open()->shouldHaveBeenCalledOnce();
$this->em->getConnection()->shouldHaveBeenCalledOnce();
$this->conn->close()->shouldHaveBeenCalledOnce();
$this->em->clear()->shouldHaveBeenCalledOnce();
$this->em->close()->shouldHaveBeenCalledOnce();
$handle->shouldHaveBeenCalledOnce();
}

Expand All @@ -68,7 +68,7 @@ public function connectionIsClosedEvenIfExceptionIsThrownOnInnerMiddlewares(): v
$this->em->open()->shouldBeCalledOnce();
$this->em->getConnection()->shouldBeCalledOnce();
$this->conn->close()->shouldBeCalledOnce();
$this->em->clear()->shouldBeCalledOnce();
$this->em->close()->shouldBeCalledOnce();
$this->expectExceptionObject($expectedError);

$this->middleware->process($req, $this->handler->reveal());
Expand Down

0 comments on commit b4a5ffd

Please sign in to comment.