forked from LiveCarta/PayPal-PHP-SDK
Auto-generated code for Webhooks API
This commit is contained in:
213
tests/PayPal/Test/Api/WebhookTest.php
Normal file
213
tests/PayPal/Test/Api/WebhookTest.php
Normal file
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Test\Api;
|
||||
|
||||
use PayPal\Common\ResourceModel;
|
||||
use PayPal\Validation\ArgumentValidator;
|
||||
use PayPal\Api\WebhookList;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
use PayPal\Api\Webhook;
|
||||
|
||||
/**
|
||||
* Class Webhook
|
||||
*
|
||||
* @package PayPal\Test\Api
|
||||
*/
|
||||
class WebhookTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Gets Json String of Object Webhook
|
||||
* @return string
|
||||
*/
|
||||
public static function getJson()
|
||||
{
|
||||
return '{"id":"TestSample","url":"http://www.google.com","event_types":' .WebhookEventTypeTest::getJson() . ',"links":' .LinksTest::getJson() . '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Object Instance with Json data filled in
|
||||
* @return Webhook
|
||||
*/
|
||||
public static function getObject()
|
||||
{
|
||||
return new Webhook(self::getJson());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests for Serialization and Deserialization Issues
|
||||
* @return Webhook
|
||||
*/
|
||||
public function testSerializationDeserialization()
|
||||
{
|
||||
$obj = new Webhook(self::getJson());
|
||||
$this->assertNotNull($obj);
|
||||
$this->assertNotNull($obj->getId());
|
||||
$this->assertNotNull($obj->getUrl());
|
||||
$this->assertNotNull($obj->getEventTypes());
|
||||
$this->assertNotNull($obj->getLinks());
|
||||
$this->assertEquals(self::getJson(), $obj->toJson());
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSerializationDeserialization
|
||||
* @param Webhook $obj
|
||||
*/
|
||||
public function testGetters($obj)
|
||||
{
|
||||
$this->assertEquals($obj->getId(), "TestSample");
|
||||
$this->assertEquals($obj->getUrl(), "http://www.google.com");
|
||||
$this->assertEquals($obj->getEventTypes(), WebhookEventTypeTest::getObject());
|
||||
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSerializationDeserialization
|
||||
* @param Webhook $obj
|
||||
*/
|
||||
public function testDeprecatedGetters($obj)
|
||||
{
|
||||
$this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSerializationDeserialization
|
||||
* @param Webhook $obj
|
||||
*/
|
||||
public function testDeprecatedSetterNormalGetter($obj)
|
||||
{
|
||||
|
||||
// Check for Event_types
|
||||
$obj->setEventTypes(null);
|
||||
$this->assertNull($obj->getEvent_types());
|
||||
$this->assertNull($obj->getEventTypes());
|
||||
$this->assertSame($obj->getEventTypes(), $obj->getEvent_types());
|
||||
$obj->setEvent_types(WebhookEventTypeTest::getObject());
|
||||
$this->assertEquals($obj->getEvent_types(), WebhookEventTypeTest::getObject());
|
||||
|
||||
//Test All Deprecated Getters and Normal Getters
|
||||
$this->testDeprecatedGetters($obj);
|
||||
$this->testGetters($obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Url is not a fully qualified URL
|
||||
*/
|
||||
public function testUrlValidationForUrl()
|
||||
{
|
||||
$obj = new Webhook();
|
||||
$obj->setUrl(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Webhook $obj
|
||||
*/
|
||||
public function testCreate($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
self::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->create($mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Webhook $obj
|
||||
*/
|
||||
public function testGet($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
WebhookTest::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->get("webhookId", $mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Webhook $obj
|
||||
*/
|
||||
public function testGetAll($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
WebhookListTest::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->getAll($mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Webhook $obj
|
||||
*/
|
||||
public function testUpdate($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
self::getJson()
|
||||
));
|
||||
$patchRequest = PatchRequestTest::getObject();
|
||||
|
||||
$result = $obj->update($patchRequest, $mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Webhook $obj
|
||||
*/
|
||||
public function testDelete($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
true
|
||||
));
|
||||
|
||||
$result = $obj->delete($mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
|
||||
public function mockProvider()
|
||||
{
|
||||
$obj = self::getObject();
|
||||
$mockApiContext = $this->getMockBuilder('ApiContext')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
return array(
|
||||
array($obj, $mockApiContext),
|
||||
array($obj, null)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user