Skip to content

Commit

Permalink
Update phpunit to get CI running (#315)
Browse files Browse the repository at this point in the history
* update dockerfile and composer file to versions of php and phpunit that will run in CI

* setUp and teardown must be void compatible

* fixup warning unit tests

* address phpunit deprecation warnings

* make integration tests setUp void compatible

* fix breaking changes in integration tests

* update tests to resolve deprecation warnings

* Don't create phpunit cache file

* add phpunit result cache to gitignore just in case

* fixup SSL unit test

* fixup failing integration tests
  • Loading branch information
hstotelmyer authored and GitHub Enterprise committed Mar 8, 2021
1 parent 481daa3 commit 80c1551
Show file tree
Hide file tree
Showing 35 changed files with 88 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/vendor
/docs
/tags
*.tgz
.phpunit.result.cache
composer.lock
composer.phar
*.tgz
tests/fixtures/large_file.png
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ RUN apt-get -y install gnupg curl wget
# For installing php7
RUN apt -y install lsb-release apt-transport-https ca-certificates
RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php7.2.list
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee /etc/apt/sources.list.d/php7.3.list

RUN apt-get update

RUN apt-get -y install rake php7.2 php7.2-cli php7.2-curl php-pear phpunit php7.2-xml php7.2-mbstring
RUN update-alternatives --set php /usr/bin/php7.2
RUN apt-get -y install rake php7.3 php7.3-cli php7.3-curl php-pear php7.3-xml php7.3-mbstring
RUN update-alternatives --set php /usr/bin/php7.3
WORKDIR /braintree-php
14 changes: 8 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
do_not_cache = "--do-not-cache-result"

task :default => :test
task :test => %w[test:unit test:integration]

Expand All @@ -14,11 +16,11 @@ namespace :test do
desc "run unit tests"
task :unit, [:file_name, :test_name] => :version do |task, args|
if args.file_name.nil?
sh "php ./vendor/bin/phpunit --testsuite unit"
sh "php ./vendor/bin/phpunit --testsuite unit #{do_not_cache}"
elsif args.test_name.nil?
sh "./vendor/bin/phpunit tests/unit/#{args.file_name}"
sh "./vendor/bin/phpunit #{do_not_cache} tests/unit/#{args.file_name}"
else
sh "./vendor/bin/phpunit tests/unit/#{args.file_name} --filter #{args.test_name}"
sh "./vendor/bin/phpunit #{do_not_cache} tests/unit/#{args.file_name} --filter #{args.test_name}"
end
end

Expand All @@ -29,11 +31,11 @@ namespace :test do
desc "run integration tests"
task :integration, [:file_name, :test_name] do |task, args|
if args.file_name.nil?
sh "php ./vendor/bin/phpunit --testsuite integration"
sh "php ./vendor/bin/phpunit --testsuite integration #{do_not_cache}"
elsif args.test_name.nil?
sh "./vendor/bin/phpunit tests/integration/#{args.file_name}"
sh "./vendor/bin/phpunit #{do_not_cache} tests/integration/#{args.file_name}"
else
sh "./vendor/bin/phpunit tests/integration/#{args.file_name} --filter #{args.test_name}"
sh "./vendor/bin/phpunit #{do_not_cache} tests/integration/#{args.file_name} --filter #{args.test_name}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ext-xmlwriter": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.5"
"phpunit/phpunit": ">=9.0"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions tests/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

class Setup extends TestCase
{
public function setUp()
{
public function setUp(): void {
parent::setUp();

self::integrationMerchantConfig();
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/ApplePayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ class ApplePayTest extends Setup
{
private static $gateway;

public static function setUpBeforeClass()
{
public static function setUpBeforeClass(): void {
self::$gateway = self::_buildMerchantGateway();
}

public static function tearDownAfterClass()
{
public static function tearDownAfterClass(): void {
self::$gateway = null;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public function testCreateCustomerWithUsBankAccount()
$this->assertEquals('021000021', $usBankAccount->routingNumber);
$this->assertEquals('1234', $usBankAccount->last4);
$this->assertEquals('checking', $usBankAccount->accountType);
$this->assertRegexp('/CHASE/', $usBankAccount->bankName);
$this->assertMatchesRegularExpression('/CHASE/', $usBankAccount->bankName);
}

public function testCreate_withUnicode()
Expand Down Expand Up @@ -1052,7 +1052,7 @@ public function test_findUsBankAccountGivenPaymentMethodToken()
$this->assertEquals('021000021', $usBankAccount->routingNumber);
$this->assertEquals('1234', $usBankAccount->last4);
$this->assertEquals('checking', $usBankAccount->accountType);
$this->assertRegexp('/CHASE/', $usBankAccount->bankName);
$this->assertMatchesRegularExpression('/CHASE/', $usBankAccount->bankName);
}

public function testFind_throwsExceptionIfNotFound()
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/DisputeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DisputeTest extends Setup
{
private $gateway;

public function setUp() {
public function setUp():void {
parent::setUp();

$this->gateway = new Braintree\Gateway([
Expand Down Expand Up @@ -138,7 +138,7 @@ public function testAddTextEvidence_addsTextEvidence()
$this->assertTrue($result->success);
$this->assertEquals("text evidence", $evidence->comment);
$this->assertNotNull($evidence->createdAt);
$this->assertRegExp('/^\w{16,}$/', $evidence->id);
$this->assertMatchesRegularExpression('/^\w{16,}$/', $evidence->id);
$this->assertNull($evidence->sentToProcessorAt);
$this->assertNull($evidence->url);
$this->assertNull($evidence->tag);
Expand All @@ -161,7 +161,7 @@ public function testAddTaggedTextEvidence_addsTextEvidence()
$this->assertTrue($result->success);
$this->assertEquals("UPS", $evidence->comment);
$this->assertNotNull($evidence->createdAt);
$this->assertRegExp('/^\w{16,}$/', $evidence->id);
$this->assertMatchesRegularExpression('/^\w{16,}$/', $evidence->id);
$this->assertNull($evidence->sentToProcessorAt);
$this->assertNull($evidence->url);
$this->assertEquals("CARRIER_NAME", $evidence->category);
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/DocumentUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class DocumentUploadTest extends Setup
private $gateway;
private $pngFile;

public function setUp() {
public function setUp(): void {
parent::setUp();

$this->gateway = new Braintree\Gateway([
Expand Down
14 changes: 6 additions & 8 deletions tests/integration/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class HttpTest extends Setup
{
public function setUp(){
public function setUp(): void{
parent::setUp();

Braintree\Configuration::environment('development');
Expand Down Expand Up @@ -65,13 +65,11 @@ public function testSandboxSSLFailsWithIncompatibleSSLVersion()

public function testSslError()
{
try {
Braintree\Configuration::environment('sandbox');
$http = new Braintree\Http(Braintree\Configuration::$global);
$http->_doUrlRequest('get', '/malformed_url');
} catch (Braintree\Exception\Connection $e) {
$this->assertEquals("<url> malformed", $e->getMessage());
}
$this->expectException('Braintree\Exception\Connection', null, 35);

Braintree\Configuration::environment('sandbox');
$http = new Braintree\Http(Braintree\Configuration::$global);
$http->_doUrlRequest('get', '/malformed_url');
}

public function testAcceptGzipEncodingSetFalse()
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/MasterpassCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testCreateWithMasterpassCardNonce()
$masterpassCard = $result->paymentMethod;
$this->assertSame(Braintree\CreditCard::DISCOVER, $masterpassCard->cardType);
$this->assertTrue($masterpassCard->default);
$this->assertContains('discover', $masterpassCard->imageUrl);
$this->assertStringContainsString('discover', $masterpassCard->imageUrl);
$this->assertTrue(intval($masterpassCard->expirationMonth) > 0);
$this->assertTrue(intval($masterpassCard->expirationYear) > 0);
$this->assertSame($customer->id, $masterpassCard->customerId);
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/PaymentMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ public function testCreate_fromFakeApplePayNonce()
$this->assertNotNull($applePayCard->token);
$this->assertNotNull($applePayCard->bin);
$this->assertSame(Braintree\ApplePayCard::VISA, $applePayCard->cardType);
$this->assertContains("Visa ", $applePayCard->paymentInstrumentName);
$this->assertContains("Visa ", $applePayCard->sourceDescription);
$this->assertStringContainsString("Visa ", $applePayCard->paymentInstrumentName);
$this->assertStringContainsString("Visa ", $applePayCard->sourceDescription);
$this->assertTrue($applePayCard->default);
$this->assertContains('apple_pay', $applePayCard->imageUrl);
$this->assertStringContainsString('apple_pay', $applePayCard->imageUrl);
$this->assertTrue(intval($applePayCard->expirationMonth) > 0);
$this->assertTrue(intval($applePayCard->expirationYear) > 0);
$this->assertSame($customer->id, $applePayCard->customerId);
Expand All @@ -188,7 +188,7 @@ public function testCreate_fromFakeAndroidPayProxyCardNonce()
$this->assertSame("1111", $androidPayCard->sourceCardLast4);
$this->assertSame("Discover 1111", $androidPayCard->sourceDescription);
$this->assertTrue($androidPayCard->default);
$this->assertContains('android_pay', $androidPayCard->imageUrl);
$this->assertStringContainsString('android_pay', $androidPayCard->imageUrl);
$this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
$this->assertTrue(intval($androidPayCard->expirationYear) > 0);
$this->assertSame($customer->id, $androidPayCard->customerId);
Expand All @@ -214,7 +214,7 @@ public function testCreate_fromFakeAndroidPayNetworkTokenNonce()
$this->assertSame("4444", $androidPayCard->sourceCardLast4);
$this->assertSame("MasterCard 4444", $androidPayCard->sourceDescription);
$this->assertTrue($androidPayCard->default);
$this->assertContains('android_pay', $androidPayCard->imageUrl);
$this->assertStringContainsString('android_pay', $androidPayCard->imageUrl);
$this->assertTrue(intval($androidPayCard->expirationMonth) > 0);
$this->assertTrue(intval($androidPayCard->expirationYear) > 0);
$this->assertSame($customer->id, $androidPayCard->customerId);
Expand All @@ -240,7 +240,7 @@ public function testCreate_fromFakeAmexExpressCheckoutCardNonce()
$this->assertSame("0005", $amexExpressCheckoutCard->cardMemberNumber);
$this->assertSame("American Express", $amexExpressCheckoutCard->cardType);
$this->assertNotNull($amexExpressCheckoutCard->sourceDescription);
$this->assertContains(".png", $amexExpressCheckoutCard->imageUrl);
$this->assertStringContainsString(".png", $amexExpressCheckoutCard->imageUrl);
$this->assertTrue(intval($amexExpressCheckoutCard->expirationMonth) > 0);
$this->assertTrue(intval($amexExpressCheckoutCard->expirationYear) > 0);
$this->assertTrue($amexExpressCheckoutCard->default);
Expand All @@ -262,7 +262,7 @@ public function testCreate_fromFakeVenmoAccountNonce()

$this->assertNotNull($venmoAccount->token);
$this->assertNotNull($venmoAccount->sourceDescription);
$this->assertContains(".png", $venmoAccount->imageUrl);
$this->assertStringContainsString(".png", $venmoAccount->imageUrl);
$this->assertTrue($venmoAccount->default);
$this->assertSame($customer->id, $venmoAccount->customerId);
$this->assertEquals(array(), $venmoAccount->subscriptions);
Expand Down Expand Up @@ -1223,7 +1223,7 @@ public function testFind_returnsAndroidPayCards()
$this->assertSame("1111", $foundAndroidPayCard->sourceCardLast4);
$this->assertSame($customer->id, $foundAndroidPayCard->customerId);
$this->assertTrue($foundAndroidPayCard->default);
$this->assertContains('android_pay', $foundAndroidPayCard->imageUrl);
$this->assertStringContainsString('android_pay', $foundAndroidPayCard->imageUrl);
$this->assertTrue(intval($foundAndroidPayCard->expirationMonth) > 0);
$this->assertTrue(intval($foundAndroidPayCard->expirationYear) > 0);
$this->assertFalse($foundAndroidPayCard->isNetworkTokenized);
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/PaymentMethodWithUsBankAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testCreate_fromUsBankAccountNonce()
$this->assertEquals('1234', $usBankAccount->last4);
$this->assertEquals('checking', $usBankAccount->accountType);
$this->assertEquals('Dan Schulman', $usBankAccount->accountHolderName);
$this->assertRegexp('/CHASE/', $usBankAccount->bankName);
$this->assertMatchesRegularExpression('/CHASE/', $usBankAccount->bankName);
$this->assertEquals(true, $usBankAccount->verified);

$this->assertEquals(1, count($usBankAccount->verifications));
Expand Down Expand Up @@ -53,7 +53,7 @@ public function testCreate_fromUsBankAccountNonceWithVerification()
$this->assertEquals('0000', $usBankAccount->last4);
$this->assertEquals('checking', $usBankAccount->accountType);
$this->assertEquals('Dan Schulman', $usBankAccount->accountHolderName);
$this->assertRegexp('/CHASE/', $usBankAccount->bankName);
$this->assertMatchesRegularExpression('/CHASE/', $usBankAccount->bankName);
$this->assertEquals(true, $usBankAccount->verified);

$this->assertEquals(1, count($usBankAccount->verifications));
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testCreate_fromPlaidUsBankAccountNonce()
$this->assertEquals('0000', $usBankAccount->last4);
$this->assertEquals('checking', $usBankAccount->accountType);
$this->assertEquals('Dan Schulman', $usBankAccount->accountHolderName);
$this->assertRegexp('/FEDERAL/', $usBankAccount->bankName);
$this->assertMatchesRegularExpression('/FEDERAL/', $usBankAccount->bankName);
$this->assertEquals(true, $usBankAccount->verified);

$this->assertEquals(1, count($usBankAccount->verifications));
Expand Down Expand Up @@ -109,7 +109,7 @@ public function testFind_returnsUsBankAccount()
$this->assertEquals('1234', $foundUsBankAccount->last4);
$this->assertEquals('checking', $foundUsBankAccount->accountType);
$this->assertEquals('Dan Schulman', $foundUsBankAccount->accountHolderName);
$this->assertRegExp('/CHASE/', $foundUsBankAccount->bankName);
$this->assertMatchesRegularExpression('/CHASE/', $foundUsBankAccount->bankName);
}

public function testCompliantCreate_fromUsBankAccountNonce()
Expand All @@ -134,7 +134,7 @@ public function testCompliantCreate_fromUsBankAccountNonce()
$this->assertEquals('1234', $usBankAccount->last4);
$this->assertEquals('checking', $usBankAccount->accountType);
$this->assertEquals('Dan Schulman', $usBankAccount->accountHolderName);
$this->assertRegexp('/CHASE/', $usBankAccount->bankName);
$this->assertMatchesRegularExpression('/CHASE/', $usBankAccount->bankName);
$this->assertEquals(false, $usBankAccount->verified);

$this->assertEquals(0, count($usBankAccount->verifications));
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/SamsungPayCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testCreateWithSamsungPayCardNonce()
$this->assertNotNull($samsungPayCard->token);
$this->assertSame(Braintree\CreditCard::DISCOVER, $samsungPayCard->cardType);
$this->assertTrue($samsungPayCard->default);
$this->assertContains('discover', $samsungPayCard->imageUrl);
$this->assertStringContainsString('discover', $samsungPayCard->imageUrl);
$this->assertTrue(intval($samsungPayCard->expirationMonth) > 0);
$this->assertTrue(intval($samsungPayCard->expirationYear) > 0);
$this->assertSame($customer->id, $samsungPayCard->customerId);
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/TestTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

class TestTransactionTest extends Setup
{
public function setUp()
{
public function setUp(): void {
parent::setUp();

Braintree\Configuration::environment('development');
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1726,11 +1726,11 @@ public function testCreateTransactionUsingFakeApplePayNonce()
$this->assertEquals('47.00', $transaction->amount);
$applePayDetails = $transaction->applePayCardDetails;
$this->assertSame(Braintree\ApplePayCard::AMEX, $applePayDetails->cardType);
$this->assertContains("AmEx ", $applePayDetails->sourceDescription);
$this->assertContains("AmEx ", $applePayDetails->paymentInstrumentName);
$this->assertStringContainsString("AmEx ", $applePayDetails->sourceDescription);
$this->assertStringContainsString("AmEx ", $applePayDetails->paymentInstrumentName);
$this->assertTrue(intval($applePayDetails->expirationMonth) > 0);
$this->assertTrue(intval($applePayDetails->expirationYear) > 0);
$this->assertContains('apple_pay', $applePayDetails->imageUrl);
$this->assertStringContainsString('apple_pay', $applePayDetails->imageUrl);
$this->assertNotNull($applePayDetails->cardholderName);
$this->assertNotNull($applePayDetails->bin);
$this->assertNotNull($applePayDetails->commercial);
Expand Down Expand Up @@ -1788,7 +1788,7 @@ public function testCreateTransactionUsingRawGooglePayParams()
$this->assertSame(Braintree\CreditCard::VISA, $androidPayCardDetails->sourceCardType);
$this->assertSame("1881", $androidPayCardDetails->sourceCardLast4);
$this->assertSame("Visa 1881", $androidPayCardDetails->sourceDescription);
$this->assertContains('android_pay', $androidPayCardDetails->imageUrl);
$this->assertStringContainsString('android_pay', $androidPayCardDetails->imageUrl);
$this->assertSame("10", $androidPayCardDetails->expirationMonth);
$this->assertSame("17", $androidPayCardDetails->expirationYear);
$this->assertNotNull($androidPayCardDetails->bin);
Expand Down Expand Up @@ -1821,7 +1821,7 @@ public function testCreateTransactionUsingFakeAndroidPayProxyCardNonce()
$this->assertSame(Braintree\CreditCard::DISCOVER, $androidPayCardDetails->sourceCardType);
$this->assertSame("1111", $androidPayCardDetails->sourceCardLast4);
$this->assertSame("Discover 1111", $androidPayCardDetails->sourceDescription);
$this->assertContains('android_pay', $androidPayCardDetails->imageUrl);
$this->assertStringContainsString('android_pay', $androidPayCardDetails->imageUrl);
$this->assertTrue(intval($androidPayCardDetails->expirationMonth) > 0);
$this->assertTrue(intval($androidPayCardDetails->expirationYear) > 0);
$this->assertNotNull($androidPayCardDetails->bin);
Expand Down Expand Up @@ -1854,7 +1854,7 @@ public function testCreateTransactionUsingFakeAndroidPayNetworkTokenNonce()
$this->assertSame(Braintree\CreditCard::MASTER_CARD, $androidPayCardDetails->sourceCardType);
$this->assertSame("4444", $androidPayCardDetails->sourceCardLast4);
$this->assertSame("MasterCard 4444", $androidPayCardDetails->sourceDescription);
$this->assertContains('android_pay', $androidPayCardDetails->imageUrl);
$this->assertStringContainsString('android_pay', $androidPayCardDetails->imageUrl);
$this->assertTrue(intval($androidPayCardDetails->expirationMonth) > 0);
$this->assertTrue(intval($androidPayCardDetails->expirationYear) > 0);
$this->assertNotNull($androidPayCardDetails->bin);
Expand Down Expand Up @@ -1887,7 +1887,7 @@ public function testCreateTransactionUsingFakeAmexExpressCheckoutNonce()
$this->assertSame("0005", $amexExpressCheckoutCardDetails->cardMemberNumber);
$this->assertNull($amexExpressCheckoutCardDetails->token);
$this->assertNotNull($amexExpressCheckoutCardDetails->sourceDescription);
$this->assertContains(".png", $amexExpressCheckoutCardDetails->imageUrl);
$this->assertStringContainsString(".png", $amexExpressCheckoutCardDetails->imageUrl);
$this->assertTrue(intval($amexExpressCheckoutCardDetails->expirationMonth) > 0);
$this->assertTrue(intval($amexExpressCheckoutCardDetails->expirationYear) > 0);
}
Expand Down Expand Up @@ -1924,7 +1924,7 @@ public function testCreateTransactionUsingFakeVenmoAccountNonce()

$this->assertNull($venmoAccountDetails->token);
$this->assertNotNull($venmoAccountDetails->sourceDescription);
$this->assertContains(".png", $venmoAccountDetails->imageUrl);
$this->assertStringContainsString(".png", $venmoAccountDetails->imageUrl);
$this->assertSame("venmojoe", $venmoAccountDetails->username);
$this->assertSame("Venmo-Joe-1", $venmoAccountDetails->venmoUserId);
}
Expand Down
Loading

0 comments on commit 80c1551

Please sign in to comment.