From 61145f4bb0c23cc7cbc541e27c5aef01b6b4fb22 Mon Sep 17 00:00:00 2001 From: Craig Paul Date: Thu, 20 Oct 2016 18:15:47 -0600 Subject: [PATCH] Changes static moneris constructor to return Gateway --- src/Moneris.php | 6 ++++-- tests/GatewayTest.php | 2 +- tests/MonerisTest.php | 13 ++++++------- tests/ProcessorTest.php | 6 +++--- tests/ResponseTest.php | 2 +- tests/TransactionTest.php | 2 +- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Moneris.php b/src/Moneris.php index 0964e27..3d9f76c 100644 --- a/src/Moneris.php +++ b/src/Moneris.php @@ -70,11 +70,13 @@ public function __construct(string $id, string $token, array $params = []) * @param string $token * @param array $params * - * @return $this + * @return \CraigPaul\Moneris\Gateway */ public static function create(string $id, string $token, array $params = []) { - return new static($id, $token, $params); + $moneris = new static($id, $token, $params); + + return $moneris->connect(); } /** diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index d7f2905..7b4602b 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -30,7 +30,7 @@ public function setUp() parent::setUp(); $params = ['environment' => $this->environment]; - $this->gateway = Moneris::create($this->id, $this->token, $params)->connect(); + $this->gateway = Moneris::create($this->id, $this->token, $params); $this->params = [ 'order_id' => uniqid('1234-56789', true), 'amount' => '1.00', diff --git a/tests/MonerisTest.php b/tests/MonerisTest.php index 6c4ad70..5e5c307 100644 --- a/tests/MonerisTest.php +++ b/tests/MonerisTest.php @@ -37,15 +37,14 @@ public function it_can_instantiate_via_the_constructor() } /** @test */ - public function it_can_instantiate_via_a_static_create_method() + public function it_can_instantiate_via_a_static_create_method_and_return_the_gateway() { - $moneris = Moneris::create($this->id, $this->token, $this->params); + $gateway = Moneris::create($this->id, $this->token, $this->params); - $this->assertEquals(Moneris::class, get_class($moneris)); - $this->assertObjectHasAttribute('id', $moneris); - $this->assertObjectHasAttribute('token', $moneris); - $this->assertObjectHasAttribute('environment', $moneris); - $this->assertObjectHasAttribute('params', $moneris); + $this->assertEquals(Gateway::class, get_class($gateway)); + $this->assertObjectHasAttribute('id', $gateway); + $this->assertObjectHasAttribute('token', $gateway); + $this->assertObjectHasAttribute('environment', $gateway); } /** @test */ diff --git a/tests/ProcessorTest.php b/tests/ProcessorTest.php index 8dc1035..ff631bb 100644 --- a/tests/ProcessorTest.php +++ b/tests/ProcessorTest.php @@ -39,7 +39,7 @@ public function setUp() parent::setUp(); $this->params = ['environment' => Moneris::ENV_TESTING]; - $this->gateway = Moneris::create($this->id, $this->token, $this->params)->connect(); + $this->gateway = Moneris::create($this->id, $this->token, $this->params); $this->params = [ 'type' => 'purchase', 'crypt_type' => Crypt::SSL_ENABLED_MERCHANT, @@ -74,7 +74,7 @@ public function it_can_submit_a_proper_request_to_the_moneris_api() public function it_can_submit_a_avs_secured_request_to_the_moneris_api() { $params = ['environment' => Moneris::ENV_TESTING, 'avs' => true]; - $gateway = Moneris::create($this->id, $this->token, $params)->connect(); + $gateway = Moneris::create($this->id, $this->token, $params); $response = $gateway->purchase([ 'order_id' => uniqid('1234-56789', true), 'amount' => '1.00', @@ -92,7 +92,7 @@ public function it_can_submit_a_avs_secured_request_to_the_moneris_api() public function it_can_submit_a_cvd_secured_request_to_the_moneris_api() { $params = ['environment' => Moneris::ENV_TESTING, 'cvd' => true]; - $gateway = Moneris::create($this->id, $this->token, $params)->connect(); + $gateway = Moneris::create($this->id, $this->token, $params); $response = $gateway->purchase([ 'order_id' => uniqid('1234-56789', true), 'amount' => '1.00', diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 2738ccf..6d0be72 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -46,7 +46,7 @@ public function setUp() parent::setUp(); $this->params = ['environment' => Moneris::ENV_TESTING]; - $this->gateway = Moneris::create($this->id, $this->token, $this->params)->connect(); + $this->gateway = Moneris::create($this->id, $this->token, $this->params); $this->params = [ 'type' => 'purchase', 'crypt_type' => Crypt::SSL_ENABLED_MERCHANT, diff --git a/tests/TransactionTest.php b/tests/TransactionTest.php index 06d066f..07d4de7 100644 --- a/tests/TransactionTest.php +++ b/tests/TransactionTest.php @@ -36,7 +36,7 @@ public function setUp() parent::setUp(); $this->params = ['environment' => Moneris::ENV_TESTING]; - $this->gateway = Moneris::create($this->id, $this->token, $this->params)->connect(); + $this->gateway = Moneris::create($this->id, $this->token, $this->params); $this->params = [ 'type' => 'purchase', 'order_id' => uniqid('1234-56789', true),