2019-06-18 03:49:07 +05:30
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace common\tests\unit\components\EmailsRenderer;
|
|
|
|
|
|
|
|
use common\components\EmailsRenderer\Api;
|
|
|
|
use common\components\EmailsRenderer\Component;
|
|
|
|
use common\components\EmailsRenderer\Request\TemplateRequest;
|
|
|
|
use common\tests\unit\TestCase;
|
2024-12-02 15:40:55 +05:30
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2019-06-18 03:49:07 +05:30
|
|
|
|
|
|
|
class ComponentTest extends TestCase {
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
private Api&MockObject $api;
|
2019-06-18 03:49:07 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
private Component $component;
|
2019-06-18 03:49:07 +05:30
|
|
|
|
2019-08-02 18:27:17 +05:30
|
|
|
protected function setUp(): void {
|
2019-06-18 03:49:07 +05:30
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->api = $this->createMock(Api::class);
|
|
|
|
$componentParams = [
|
|
|
|
'api' => $this->api,
|
|
|
|
'serviceUrl' => 'http://emails-renderer',
|
|
|
|
'basePath' => '/images/emails-templates',
|
|
|
|
];
|
|
|
|
$this->component = new class($componentParams) extends Component {
|
2024-12-02 15:40:55 +05:30
|
|
|
public Api $api;
|
2019-06-18 03:49:07 +05:30
|
|
|
|
|
|
|
protected function getApi(): Api {
|
|
|
|
return $this->api;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testRender(): void {
|
2019-06-18 03:49:07 +05:30
|
|
|
$expectedRequest = new TemplateRequest('mock-name', 'mock-locale', [
|
|
|
|
'find-me' => 'please',
|
|
|
|
'assetsHost' => 'http://localhost/images/emails-templates',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->api->expects($this->once())->method('getTemplate')->with($expectedRequest)->willReturn('mock-template');
|
|
|
|
|
|
|
|
$result = $this->component->render('mock-name', 'mock-locale', ['find-me' => 'please']);
|
|
|
|
$this->assertSame('mock-template', $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|