From 540b52697168412a87e355c7fc3c00fed0cddcde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Wed, 10 Apr 2019 12:43:02 +0200 Subject: [PATCH 1/4] Allow HTTP2, update phpunit, fix some tests --- composer.json | 4 ++-- src/Bitpay/Application.php | 16 ---------------- src/Bitpay/Client/Response.php | 4 ++-- tests/Bitpay/ApplicationTest.php | 11 ++--------- tests/Bitpay/BillTest.php | 4 ++-- tests/Bitpay/Client/ClientTest.php | 28 ++++++++++++++-------------- tests/Bitpay/Client/ResponseTest.php | 15 +++++++++++++++ tests/Bitpay/Math/GmpEngineTest.php | 4 ++-- tests/Bitpay/Math/MathTest.php | 2 +- tests/Bitpay/PublicKeyTest.php | 2 +- 10 files changed, 41 insertions(+), 49 deletions(-) diff --git a/composer.json b/composer.json index 98259175..3df433a2 100644 --- a/composer.json +++ b/composer.json @@ -39,9 +39,9 @@ "fabpot/goutte": "~1.0.4", "behat/mink-goutte-driver": "1.*", "phpmd/phpmd": "~2.1.3", - "phpunit/phpunit": "~4.8.35", + "phpunit/phpunit": "~5.7.9", "fzaninotto/faker": "~1.4.0", - "mikey179/vfsStream": "~1.4.0", + "mikey179/vfsstream": "~1.4.0", "squizlabs/php_codesniffer": "~1.5.5", "satooshi/php-coveralls": "~0.6.1", "symfony/phpunit-bridge": "^4.0" diff --git a/src/Bitpay/Application.php b/src/Bitpay/Application.php index 2e6931ca..4f5148a2 100644 --- a/src/Bitpay/Application.php +++ b/src/Bitpay/Application.php @@ -61,20 +61,4 @@ public function addUser(UserInterface $user) return $this; } - - /** - * Add org to stack - * - * @param OrgInterface $org - * - * @return ApplicationInterface - */ - public function addOrg(OrgInterface $org) - { - if (!empty($org)) { - $this->orgs[] = $org; - } - - return $this; - } } diff --git a/src/Bitpay/Client/Response.php b/src/Bitpay/Client/Response.php index cc378586..4715f3c0 100644 --- a/src/Bitpay/Client/Response.php +++ b/src/Bitpay/Client/Response.php @@ -71,9 +71,9 @@ public static function createFromRawResponse($rawResponse) for ($i = 0; $i < $linesLen; $i++) { if (0 == $i) { - preg_match('/^HTTP\/(\d\.\d)\s(\d+)\s(.+)/', $lines[$i], $statusLine); + preg_match('#^HTTP/[0-9\\.]+\s(\d+)#', $lines[$i], $statusLine); - $response->setStatusCode($statusCode = $statusLine[2]); + $response->setStatusCode($statusCode = $statusLine[1]); continue; } diff --git a/tests/Bitpay/ApplicationTest.php b/tests/Bitpay/ApplicationTest.php index 7cd700da..b1dc4580 100644 --- a/tests/Bitpay/ApplicationTest.php +++ b/tests/Bitpay/ApplicationTest.php @@ -52,19 +52,12 @@ public function testAddOrg() $this->assertNotNull($application); - $application->addOrg($this->getMockOrg()); - $this->assertInternalType('array', $application->getOrgs()); - $this->assertCount(1, $application->getOrgs()); + $this->assertCount(0, $application->getOrgs()); } private function getMockUser() { - return $this->getMock('Bitpay\UserInterface'); - } - - private function getMockOrg() - { - return $this->getMock('Bitpay\OrgInterface'); + return $this->createMock('Bitpay\UserInterface'); } } diff --git a/tests/Bitpay/BillTest.php b/tests/Bitpay/BillTest.php index d399b13c..2aaf293d 100644 --- a/tests/Bitpay/BillTest.php +++ b/tests/Bitpay/BillTest.php @@ -232,11 +232,11 @@ public function testSetArchived() private function getMockItem() { - return $this->getMock('Bitpay\ItemInterface'); + return $this->createMock('Bitpay\ItemInterface'); } private function getMockCurrency() { - return $this->getMock('Bitpay\CurrencyInterface'); + return $this->createMock('Bitpay\CurrencyInterface'); } } diff --git a/tests/Bitpay/Client/ClientTest.php b/tests/Bitpay/Client/ClientTest.php index 9cda4d40..7d34fa01 100644 --- a/tests/Bitpay/Client/ClientTest.php +++ b/tests/Bitpay/Client/ClientTest.php @@ -27,7 +27,7 @@ public function setUp() $this->client->setPublicKey($this->getMockPublicKey()); $this->client->setPrivateKey($this->getMockPrivateKey()); $adapter = $this->getMockAdapter(); - $adapter->method('sendRequest')->willReturn($this->getMock('Bitpay\Client\ResponseInterface')); + $adapter->method('sendRequest')->willReturn($this->createMock('Bitpay\Client\ResponseInterface')); $this->client->setAdapter($adapter); } @@ -204,7 +204,7 @@ public function testCreateInvoice() } /** - * @expectedException Exception + * @expectedException \Exception */ public function testCreateResponseWithException() { @@ -238,7 +238,7 @@ public function testCreateResponseWithException() } /** - * @expectedException Exception + * @expectedException \Exception */ public function testCreateInvoiceWithTooMuchPrecisionForAnythingButBitcoin() { @@ -268,7 +268,7 @@ public function testCreateInvoiceWithTooMuchPrecisionForAnythingButBitcoin() /** - * @expectedException Exception + * @expectedException \Exception */ public function testCreateInvoiceWithTooMuchPrecisionEvenForBitcoin() { @@ -315,7 +315,7 @@ public function testGetRequest() /** * @depends testGetRequest * @depends testGetResponse - * @expectedException Exception + * @expectedException \Exception */ public function testCreateInvoiceWithError() { @@ -346,7 +346,7 @@ public function testCreateInvoiceWithError() } /** - * @expectedException Exception + * @expectedException \Exception */ public function testGetCurrenciesWithException() { @@ -453,7 +453,7 @@ public function testCreateToken() } /** - * @expectedException Exception + * @expectedException \Exception */ public function testCreateTokenWithException() { @@ -496,7 +496,7 @@ public function testGetInvoice() } /** - * @expectedException Exception + * @expectedException \Exception */ public function testGetInvoiceException() { @@ -528,7 +528,7 @@ public function testGetPayout() } /** - * @expectedException Exception + * @expectedException \Exception */ public function testGetPayoutException() { @@ -717,26 +717,26 @@ private function getMockCurrency() private function getMockToken() { - return $this->getMock('Bitpay\TokenInterface'); + return $this->createMock('Bitpay\TokenInterface'); } private function getMockAdapter() { - return $this->getMock('Bitpay\Client\Adapter\AdapterInterface'); + return $this->createMock('Bitpay\Client\Adapter\AdapterInterface'); } private function getMockPublicKey() { - return $this->getMock('Bitpay\PublicKey'); + return $this->createMock('Bitpay\PublicKey'); } private function getMockPrivateKey() { - return $this->getMock('Bitpay\PrivateKey'); + return $this->createMock('Bitpay\PrivateKey'); } private function getMockResponse() { - return $this->getMock('Bitpay\Client\ResponseInterface'); + return $this->createMock('Bitpay\Client\ResponseInterface'); } } diff --git a/tests/Bitpay/Client/ResponseTest.php b/tests/Bitpay/Client/ResponseTest.php index 40242cce..29e9e3d5 100644 --- a/tests/Bitpay/Client/ResponseTest.php +++ b/tests/Bitpay/Client/ResponseTest.php @@ -51,6 +51,9 @@ public function testCreateFromRawResponse() { $response = Response::createFromRawResponse($this->getTestResponse200()); $this->assertSame(200, $response->getStatusCode()); + + $response = Response::createFromRawResponse($this->getTestHttp2Response200()); + $this->assertSame(200, $response->getStatusCode()); } /** @@ -70,6 +73,18 @@ private function getTestResponse200() HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 +{ + "response": "example" +} +EOF; + } + + private function getTestHttp2Response200() + { + return <<assertEquals(gmp_strval(gmp_pow($a, $a)), $math->pow($a, $a)); - $this->assertEquals(gmp_strval(gmp_pow($b, $b)), $math->pow($b, $b)); - $this->assertEquals(gmp_strval(gmp_pow($c, $c)), $math->pow($c, $c)); + $this->assertEquals(gmp_strval(gmp_pow($b, $a)), $math->pow($b, $a)); + $this->assertEquals(gmp_strval(gmp_pow($c, $a)), $math->pow($c, $a)); $this->assertEquals(1, $math->pow(1, 1)); } diff --git a/tests/Bitpay/Math/MathTest.php b/tests/Bitpay/Math/MathTest.php index 0bdb5f4a..f4c24c61 100644 --- a/tests/Bitpay/Math/MathTest.php +++ b/tests/Bitpay/Math/MathTest.php @@ -17,7 +17,7 @@ public function testIsEngineSet() { Math::setEngine(null); $this->assertNull(Math::getEngine()); - $engine = $this->getMock('Bitpay\Math\EngineInterface'); + $engine = $this->createMock('Bitpay\Math\EngineInterface'); Math::setEngine($engine); $this->assertInstanceOf('Bitpay\Math\EngineInterface', Math::getEngine()); } diff --git a/tests/Bitpay/PublicKeyTest.php b/tests/Bitpay/PublicKeyTest.php index 1a89b7e7..1519e447 100644 --- a/tests/Bitpay/PublicKeyTest.php +++ b/tests/Bitpay/PublicKeyTest.php @@ -236,7 +236,7 @@ public function testIsGenerated() private function getMockPrivateKey($hex = null) { $hex = ($hex === null) ? $this->hexKeys[0]['private'] : $hex; - $key = $this->getMock('Bitpay\PrivateKey'); + $key = $this->createMock('Bitpay\PrivateKey'); $key->method('isValid')->will($this->returnValue(true)); $key From 901a544b47e50e39741a613fed4ce4e5a83cdf49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Wed, 10 Apr 2019 12:53:08 +0200 Subject: [PATCH 2/4] Update codesniffer and fix style accordingly --- composer.json | 2 +- src/Bitpay/AccessTokenInterface.php | 2 +- src/Bitpay/Application.php | 2 +- src/Bitpay/ApplicationInterface.php | 2 +- src/Bitpay/Bill.php | 2 +- src/Bitpay/BillInterface.php | 2 +- src/Bitpay/Bitpay.php | 2 +- src/Bitpay/Buyer.php | 2 +- src/Bitpay/BuyerInterface.php | 2 +- src/Bitpay/Client/Adapter/AdapterInterface.php | 2 +- src/Bitpay/Client/ArgumentException.php | 2 +- src/Bitpay/Client/BitpayException.php | 2 +- src/Bitpay/Client/Client.php | 2 +- src/Bitpay/Client/ClientInterface.php | 2 +- src/Bitpay/Client/ConnectionException.php | 2 +- src/Bitpay/Client/Request.php | 4 ++-- src/Bitpay/Client/RequestInterface.php | 2 +- src/Bitpay/Client/ResponseInterface.php | 2 +- src/Bitpay/Crypto/CryptoInterface.php | 2 +- src/Bitpay/Crypto/HashExtension.php | 2 +- src/Bitpay/Crypto/OpenSSLExtension.php | 3 +-- src/Bitpay/CurrencyInterface.php | 2 +- src/Bitpay/DependencyInjection/Loader/ArrayLoader.php | 2 +- src/Bitpay/Invoice.php | 4 ++-- src/Bitpay/InvoiceInterface.php | 1 - src/Bitpay/Item.php | 4 ++-- src/Bitpay/ItemInterface.php | 2 +- src/Bitpay/Key.php | 2 +- src/Bitpay/KeyInterface.php | 2 +- src/Bitpay/KeyManager.php | 2 +- src/Bitpay/Math/BcEngine.php | 8 +++----- src/Bitpay/Network/Customnet.php | 2 +- src/Bitpay/Network/Livenet.php | 2 +- src/Bitpay/Network/NetworkAware.php | 2 +- src/Bitpay/Network/NetworkAwareInterface.php | 2 +- src/Bitpay/Network/NetworkInterface.php | 2 +- src/Bitpay/Network/Testnet.php | 2 +- src/Bitpay/Point.php | 2 +- src/Bitpay/PointInterface.php | 2 +- src/Bitpay/PublicKey.php | 2 +- src/Bitpay/SinKey.php | 2 +- src/Bitpay/Storage/EncryptedFilesystemStorage.php | 2 +- src/Bitpay/Storage/FilesystemStorage.php | 2 +- src/Bitpay/Storage/MockStorage.php | 2 +- src/Bitpay/Storage/StorageInterface.php | 2 +- src/Bitpay/Token.php | 2 +- src/Bitpay/TokenInterface.php | 2 +- src/Bitpay/User.php | 2 +- src/Bitpay/UserInterface.php | 2 +- src/Bitpay/Util/CurveParameterInterface.php | 2 +- src/Bitpay/Util/Error.php | 2 +- src/Bitpay/Util/Fingerprint.php | 2 +- src/Bitpay/Util/Secp256k1.php | 2 +- src/Bitpay/Util/SecureRandom.php | 2 +- src/Bitpay/Util/Util.php | 1 - 55 files changed, 58 insertions(+), 63 deletions(-) diff --git a/composer.json b/composer.json index 3df433a2..11dc7211 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "phpunit/phpunit": "~5.7.9", "fzaninotto/faker": "~1.4.0", "mikey179/vfsstream": "~1.4.0", - "squizlabs/php_codesniffer": "~1.5.5", + "squizlabs/php_codesniffer": "~3.4", "satooshi/php-coveralls": "~0.6.1", "symfony/phpunit-bridge": "^4.0" }, diff --git a/src/Bitpay/AccessTokenInterface.php b/src/Bitpay/AccessTokenInterface.php index b701db3a..bd293ebb 100644 --- a/src/Bitpay/AccessTokenInterface.php +++ b/src/Bitpay/AccessTokenInterface.php @@ -1,6 +1,6 @@ 2) { throw new \Bitpay\Client\BitpayException('Incorrect price format or currency type.'); } - elseif ($decimalPrecision > 6) { + if ($decimalPrecision > 6) { throw new \Bitpay\Client\BitpayException('Incorrect price format or currency type.'); } } diff --git a/src/Bitpay/Client/ClientInterface.php b/src/Bitpay/Client/ClientInterface.php index 8d490582..bcde3aa0 100644 --- a/src/Bitpay/Client/ClientInterface.php +++ b/src/Bitpay/Client/ClientInterface.php @@ -1,6 +1,6 @@ getMessage()); } From 08b00b300f8f8aae82e4bc5c319ea68014e977f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Wed, 10 Apr 2019 13:15:51 +0200 Subject: [PATCH 3/4] Disable coverage as it's not compatible with php7.2, see https://github.com/sebastianbergmann/php-code-coverage/issues/551#issuecomment-430804261 for possible workaround --- build/phpunit.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/build/phpunit.xml.dist b/build/phpunit.xml.dist index 8bcc3780..ac00eac0 100644 --- a/build/phpunit.xml.dist +++ b/build/phpunit.xml.dist @@ -20,7 +20,6 @@ - From e74beed92afba6c97b0a10fe06489d704ccd2348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Jura=CC=81sek?= Date: Wed, 10 Apr 2019 13:16:14 +0200 Subject: [PATCH 4/4] Add php 7.3 to travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 08f43fb4..1d80a39b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ php: - 7.0 - 7.1 - 7.2 + - 7.3 install: - composer install