-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEXT-39768 - Removed the service definition form inside the compiler …
…pass and moved to the service.xml
- Loading branch information
Showing
5 changed files
with
125 additions
and
41 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
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
112 changes: 112 additions & 0 deletions
112
tests/EventListener/BeforeRegistrationStartsListenerTest.php
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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EventListener; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\RequestInterface; | ||
use Shopware\App\SDK\Event\BeforeRegistrationStartsEvent; | ||
use Shopware\App\SDK\Shop\ShopInterface; | ||
use Shopware\AppBundle\EventListener\BeforeRegistrationStartsListener; | ||
use Shopware\AppBundle\Exception\ShopURLIsNotReachableException; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
#[CoversClass(BeforeRegistrationStartsListener::class)] | ||
final class BeforeRegistrationStartsListenerTest extends TestCase | ||
{ | ||
private HttpClientInterface&MockObject $httpClient; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->httpClient = $this->createMock(HttpClientInterface::class); | ||
} | ||
|
||
public function testListenerMustReturnBecauseTheCheckIsSetToFalseInBundleConfiguration(): void | ||
{ | ||
$shop = $this->createMock(ShopInterface::class); | ||
$shop | ||
->expects(self::never()) | ||
->method('getShopUrl'); | ||
|
||
$this->httpClient | ||
->expects(self::never()) | ||
->method('request'); | ||
|
||
$listener = new BeforeRegistrationStartsListener( | ||
$this->httpClient, | ||
false | ||
); | ||
|
||
$listener->__invoke( | ||
new BeforeRegistrationStartsEvent( | ||
$this->createMock(RequestInterface::class), | ||
$shop | ||
) | ||
); | ||
} | ||
|
||
public function testListenerMustBeExecutedWithoutErrorsIfTheCheckIsSetToTrueInConfiguration(): void | ||
{ | ||
$shop = $this->createMock(ShopInterface::class); | ||
$shop | ||
->expects(self::once()) | ||
->method('getShopUrl') | ||
->willReturn('https://shop-url.com'); | ||
|
||
$this->httpClient | ||
->expects(self::once()) | ||
->method('request') | ||
->with('HEAD', 'https://shop-url.com', [ | ||
'timeout' => 10, | ||
'max_redirects' => 0, | ||
]); | ||
|
||
$listener = new BeforeRegistrationStartsListener( | ||
$this->httpClient, | ||
true | ||
); | ||
|
||
$listener->__invoke( | ||
new BeforeRegistrationStartsEvent( | ||
$this->createMock(RequestInterface::class), | ||
$shop | ||
) | ||
); | ||
} | ||
|
||
public function testListenerMustThrowExceptionBecauseTheShopURLIsNotReachable(): void | ||
{ | ||
$this->expectException(ShopURLIsNotReachableException::class); | ||
$this->expectExceptionMessage('Shop URL "https://shop-url.com" is not reachable from the internet and cannot be registered.'); | ||
|
||
$shop = $this->createMock(ShopInterface::class); | ||
$shop | ||
->expects(self::exactly(2)) | ||
->method('getShopUrl') | ||
->willReturn('https://shop-url.com'); | ||
|
||
$this->httpClient | ||
->expects(self::once()) | ||
->method('request') | ||
->with('HEAD', 'https://shop-url.com', [ | ||
'timeout' => 10, | ||
'max_redirects' => 0, | ||
]) | ||
->willThrowException(new \Exception('Shop url is not reachable')); | ||
|
||
$listener = new BeforeRegistrationStartsListener( | ||
$this->httpClient, | ||
true | ||
); | ||
|
||
$listener->__invoke( | ||
new BeforeRegistrationStartsEvent( | ||
$this->createMock(RequestInterface::class), | ||
$shop | ||
) | ||
); | ||
} | ||
} |