From ecabedfa1f7a8cbba7a522ca8440b82063d04686 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 14:57:48 +0400 Subject: Updated service environment Signed-off-by: Valentin Popov --- src/Environments/ServiceEnvironment.php | 26 +++++++++++++++++++++++--- tests/Environments/ServiceEnvironmentTest.php | 12 ++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Environments/ServiceEnvironment.php b/src/Environments/ServiceEnvironment.php index c24f6a6..ade87c1 100644 --- a/src/Environments/ServiceEnvironment.php +++ b/src/Environments/ServiceEnvironment.php @@ -28,15 +28,35 @@ class ServiceEnvironment { /** * @var string */ - private const BASE_URL = 'http://xmldata.epgservice.ru/EPGService/hs/xmldata/%s/%s'; + protected const BASE_URL = 'http://xmldata.epgservice.ru/EPGService/hs/xmldata/%s/%s'; + + /** + * @var string + */ + private string $key; + + /** + * @param string $key + */ + protected function __construct(string $key) { + $this->key = $key; + } /** * @param string $key + * + * @return \EPGService\Environments\ServiceEnvironment + */ + public static function create(string $key): ServiceEnvironment { + return new ServiceEnvironment($key); + } + + /** * @param string $method * * @return string */ - public static function getUrl(string $key, string $method = ''): string { - return sprintf(self::BASE_URL, $key, $method); + public function getUrl(string $method = ''): string { + return sprintf(self::BASE_URL, $this->key, $method); } } diff --git a/tests/Environments/ServiceEnvironmentTest.php b/tests/Environments/ServiceEnvironmentTest.php index faa38da..792fcd1 100644 --- a/tests/Environments/ServiceEnvironmentTest.php +++ b/tests/Environments/ServiceEnvironmentTest.php @@ -29,13 +29,17 @@ use PHPUnit\Framework\TestCase; * @package Tests\Environments */ final class ServiceEnvironmentTest extends TestCase { - public function testGetUrl(): void { + public function testGetUrlWithMethod(): void { $key = Faker::create()->sha256; $method = Faker::create()->sha256; - - $url = ServiceEnvironment::getUrl($key, $method); - + $url = ServiceEnvironment::create($key)->getUrl($method); self::assertStringContainsString($key, $url); self::assertStringContainsString($method, $url); } + + public function testGetUrlWithoutMethod(): void { + $key = Faker::create()->sha256; + $url = ServiceEnvironment::create($key)->getUrl(); + self::assertStringContainsString($key, $url); + } } -- cgit v1.2.3