From aa10ef56d540c017b198a85b85829430b80bc607 Mon Sep 17 00:00:00 2001 From: Josh Cunningham Date: Wed, 16 Oct 2019 15:06:14 -0700 Subject: [PATCH] Remove deprecated InformationHeaders methods and add types --- src/API/Helpers/InformationHeaders.php | 67 +++---------------- .../Helpers/InformationHeadersExtendTest.php | 31 --------- tests/API/Helpers/InformationHeadersTest.php | 25 ------- 3 files changed, 8 insertions(+), 115 deletions(-) diff --git a/src/API/Helpers/InformationHeaders.php b/src/API/Helpers/InformationHeaders.php index 4fd88822..7d16db45 100644 --- a/src/API/Helpers/InformationHeaders.php +++ b/src/API/Helpers/InformationHeaders.php @@ -1,4 +1,5 @@ data['name'] = $name; $this->data['version'] = $version; @@ -37,7 +38,7 @@ public function setPackage($name, $version) * * @return void */ - public function setCorePackage() + public function setCorePackage() : void { $this->setPackage('auth0-php', ApiClient::API_VERSION); $this->setEnvProperty('php', phpversion()); @@ -51,7 +52,7 @@ public function setCorePackage() * * @return void */ - public function setEnvProperty($name, $version) + public function setEnvProperty(string $name, $version) : void { if (! isset($this->data['env']) || ! is_array($this->data['env'])) { $this->data['env'] = []; @@ -67,7 +68,7 @@ public function setEnvProperty($name, $version) * * @return void */ - public function setEnvironmentData(array $data) + public function setEnvironmentData(array $data) : void { $this->data['env'] = $data; } @@ -77,7 +78,7 @@ public function setEnvironmentData(array $data) * * @return array */ - public function get() + public function get() : array { return $this->data; } @@ -87,7 +88,7 @@ public function get() * * @return string */ - public function build() + public function build() : string { return base64_encode(json_encode($this->get())); } @@ -100,7 +101,7 @@ public function build() * * @return InformationHeaders */ - public static function Extend(InformationHeaders $headers) + public static function Extend(InformationHeaders $headers) : InformationHeaders { $new_headers = new InformationHeaders; $old_headers = $headers->get(); @@ -113,56 +114,4 @@ public static function Extend(InformationHeaders $headers) return $new_headers; } - - /* - * Deprecated - */ - - // phpcs:disable - - /** - * @deprecated 5.4.0, use $this->setEnvProperty() instead. - * - * @param string $name Dependency or platform name. - * @param string $version Dependency or platform version. - * - * @return void - * - * @codeCoverageIgnore - Deprecated - */ - public function setEnvironment($name, $version) - { - $this->setEnvProperty($name, $version); - } - - /** - * @deprecated 5.4.0, use $this->setEnvProperty() instead. - * - * @param string $name Dependency name. - * @param string $version Dependency version. - * - * @return void - * - * @codeCoverageIgnore - Deprecated - */ - public function setDependency($name, $version) - { - $this->setEnvProperty($name, $version); - } - - /** - * @deprecated 5.4.0, use $this->setEnvProperty() instead. - * - * @param array $data Dependency data to store. - * - * @return void - * - * @codeCoverageIgnore - Deprecated - */ - public function setDependencyData(array $data) - { - $this->data['dependencies'] = $data; - } - - // phpcs:enable } diff --git a/tests/API/Helpers/InformationHeadersExtendTest.php b/tests/API/Helpers/InformationHeadersExtendTest.php index 329afdd6..5180a39d 100644 --- a/tests/API/Helpers/InformationHeadersExtendTest.php +++ b/tests/API/Helpers/InformationHeadersExtendTest.php @@ -24,37 +24,6 @@ public static function tearDownAfterClass() parent::tearDownAfterClass(); } - /** - * Extend existing headers and make sure existing data stays intact. - * - * @link https://github.com/auth0/jwt-auth-bundle/blob/master/src/JWTAuthBundle.php - * @link https://github.com/auth0/laravel-auth0/blob/master/src/Auth0/Login/LoginServiceProvider.php - * - * @return void - */ - public function testThatExtendedHeadersBuildCorrectly() - { - $new_headers = self::setExtendedHeaders('test-extend-sdk-1', '1.2.3'); - $new_headers->setEnvironment('test-extend-env', '2.3.4'); - - $new_header_data = $new_headers->get(); - - // Look for new SDK name and version. - $this->assertEquals( 'test-extend-sdk-1', $new_header_data['name'] ); - $this->assertEquals( '1.2.3', $new_header_data['version'] ); - - // Look for original env data. - $this->assertArrayHasKey('env', $new_header_data); - $this->assertArrayHasKey('php', $new_header_data['env']); - $this->assertEquals( phpversion(), $new_header_data['env']['php'] ); - $this->assertArrayHasKey('auth0-php', $new_header_data['env']); - $this->assertEquals(ApiClient::API_VERSION, $new_header_data['env']['auth0-php']); - - // Look for extended env data. - $this->assertArrayHasKey('test-extend-env', $new_header_data['env']); - $this->assertEquals('2.3.4', $new_header_data['env']['test-extend-env']); - } - /** * Test that extending the headers works for Management API calls. * diff --git a/tests/API/Helpers/InformationHeadersTest.php b/tests/API/Helpers/InformationHeadersTest.php index b7669c8e..0f07ffbe 100644 --- a/tests/API/Helpers/InformationHeadersTest.php +++ b/tests/API/Helpers/InformationHeadersTest.php @@ -56,31 +56,6 @@ public function testThatSetEnvPropertySetsDataCorrectly() $this->assertEquals('4.5.6', $header_data['env']['test_env_name_2']); } - /** - * Set and override an env property with the deprecated method and make sure it's returned correctly. - * - * @return void - */ - public function testThatSetEnvironmentSetsDataCorrectly() - { - $header = new InformationHeaders(); - $header->setEnvironment( 'test_env_name', '2.3.4' ); - $header_data = $header->get(); - - $this->assertArrayHasKey('env', $header_data); - $this->assertCount(1, $header_data['env']); - $this->assertArrayHasKey('test_env_name', $header_data['env']); - $this->assertEquals('2.3.4', $header_data['env']['test_env_name']); - - $header->setEnvironment( 'test_env_name', '3.4.5' ); - $header_data = $header->get(); - $this->assertEquals('3.4.5', $header_data['env']['test_env_name']); - - $header->setEnvironment( 'test_env_name_2', '4.5.6' ); - $header_data = $header->get(); - $this->assertEquals('4.5.6', $header_data['env']['test_env_name_2']); - } - /** * Set the package and env and make sure it's built correctly. *