PluginProbe
PayPlug for WooCommerce (Official) / 1.0.3
PayPlug for WooCommerce (Official) v1.0.3
3.1.0 3.0.0 2.18.0 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.1.0 1.10.0 1.10.1 1.2.1 1.2.10 1.2.11 1.2.2 1.2.3 1.2.4 1.2.5 All 102 releases
payplug / vendor / payplug / payplug-php / tests / unit_tests / Resource / APIResourceTest.php

APIResourceTest.php in PayPlug for WooCommerce (Official) 1.0.3, at vendor/payplug/payplug-php/tests/unit_tests/Resource/APIResourceTest.php

88 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Payplug;
3
4 class APIResourceMock extends Resource\APIResource
5 {
6 static function fromAttributes(array $attributes)
7 {
8 $object = new APIResourceMock();
9 $object->initialize($attributes);
10 return $object;
11 }
12 }
13
14 /**
15 * @group unit
16 * @group ci
17 * @group recommended
18 */
19 class APIResourceTest extends \PHPUnit_Framework_TestCase
20 {
21 private $_myApiResource = null;
22
23 protected function setUp()
24 {
25 $this->_myApiResource = APIResourceMock::fromAttributes(array(
26 'attr1' => 'val_attr1',
27 'attr2' => 'val_attr2'
28 ));
29 }
30
31 public function testThrowsExceptionWhenKeyDoesNotExist()
32 {
33 $this->setExpectedException('\PayPlug\Exception\UndefinedAttributeException');
34 $this->_myApiResource->an_undefined_attribute;
35 }
36
37 public function testIssetReturnsTrueWhenPropertyExists()
38 {
39 $this->assertTrue(isset($this->_myApiResource->attr1));
40 }
41
42 public function testIssetReturnsFalseWhenPropertyDoesNotExist()
43 {
44 $this->assertFalse(isset($this->_myApiResource->an_undefined_attribute));
45 }
46
47 public function testPaymentFromAPIResourceFactory()
48 {
49 $attributes = array(
50 'id' => 'pay_123',
51 'object' => 'payment'
52 );
53 $payment = Resource\APIResource::factory($attributes);
54 $this->assertTrue($payment instanceof Resource\Payment);
55 $this->assertEquals('pay_123', $payment->id);
56 }
57
58 public function testRefundFromAPIResourceFactory()
59 {
60 $attributes = array(
61 'id' => 're_123',
62 'object' => 'refund'
63 );
64 $refund = Resource\APIResource::factory($attributes);
65 $this->assertTrue($refund instanceof Resource\Refund);
66 $this->assertEquals('re_123', $refund->id);
67 }
68
69 public function testAPIResourceFactoryWhenObjectIsNotDefined()
70 {
71 $this->setExpectedException('\PayPlug\Exception\UnknownAPIResourceException');
72 $attributes = array(
73 'id' => 'a_random_object'
74 );
75 Resource\APIResource::factory($attributes);
76 }
77
78 public function testAPIResourceFactoryWhenObjectIsUnknown()
79 {
80 $this->setExpectedException('\PayPlug\Exception\UnknownAPIResourceException');
81 $attributes = array(
82 'id' => 'a_random_object',
83 'object' => 'an_unknown_object'
84 );
85 Resource\APIResource::factory($attributes);
86 }
87 }
88