From 2c59b907b8f4617afcf0c78e4069aedbbbd33939 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 13:23:59 +0400 Subject: Added service environment Signed-off-by: Valentin Popov --- tests/Environments/ServiceEnvironmentTest.php | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/Environments/ServiceEnvironmentTest.php (limited to 'tests/Environments/ServiceEnvironmentTest.php') diff --git a/tests/Environments/ServiceEnvironmentTest.php b/tests/Environments/ServiceEnvironmentTest.php new file mode 100644 index 0000000..faa38da --- /dev/null +++ b/tests/Environments/ServiceEnvironmentTest.php @@ -0,0 +1,41 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Environments + */ +final class ServiceEnvironmentTest extends TestCase { + public function testGetUrl(): void { + $key = Faker::create()->sha256; + $method = Faker::create()->sha256; + + $url = ServiceEnvironment::getUrl($key, $method); + + self::assertStringContainsString($key, $url); + self::assertStringContainsString($method, $url); + } +} -- cgit v1.2.3 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(-) (limited to 'tests/Environments/ServiceEnvironmentTest.php') 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 From 63ba3120648cbcde5ebd818f90ad832539b1a9af Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 15:11:50 +0400 Subject: Updated method “getUrl()” MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Valentin Popov --- src/Environments/ServiceEnvironment.php | 8 +++----- tests/Environments/ServiceEnvironmentTest.php | 10 +--------- 2 files changed, 4 insertions(+), 14 deletions(-) (limited to 'tests/Environments/ServiceEnvironmentTest.php') diff --git a/src/Environments/ServiceEnvironment.php b/src/Environments/ServiceEnvironment.php index ade87c1..004586f 100644 --- a/src/Environments/ServiceEnvironment.php +++ b/src/Environments/ServiceEnvironment.php @@ -28,7 +28,7 @@ class ServiceEnvironment { /** * @var string */ - protected const BASE_URL = 'http://xmldata.epgservice.ru/EPGService/hs/xmldata/%s/%s'; + protected const BASE_URL = 'http://xmldata.epgservice.ru/EPGService/hs/xmldata/%s'; /** * @var string @@ -52,11 +52,9 @@ class ServiceEnvironment { } /** - * @param string $method - * * @return string */ - public function getUrl(string $method = ''): string { - return sprintf(self::BASE_URL, $this->key, $method); + public function getUrl(): string { + return sprintf(self::BASE_URL, $this->key); } } diff --git a/tests/Environments/ServiceEnvironmentTest.php b/tests/Environments/ServiceEnvironmentTest.php index 792fcd1..b14d909 100644 --- a/tests/Environments/ServiceEnvironmentTest.php +++ b/tests/Environments/ServiceEnvironmentTest.php @@ -29,15 +29,7 @@ use PHPUnit\Framework\TestCase; * @package Tests\Environments */ final class ServiceEnvironmentTest extends TestCase { - public function testGetUrlWithMethod(): void { - $key = Faker::create()->sha256; - $method = Faker::create()->sha256; - $url = ServiceEnvironment::create($key)->getUrl($method); - self::assertStringContainsString($key, $url); - self::assertStringContainsString($method, $url); - } - - public function testGetUrlWithoutMethod(): void { + public function testGetUrl(): void { $key = Faker::create()->sha256; $url = ServiceEnvironment::create($key)->getUrl(); self::assertStringContainsString($key, $url); -- cgit v1.2.3