forked from LiveCarta/PayPal-PHP-SDK
Auto-generated code for Webhooks API
This commit is contained in:
190
tests/PayPal/Test/Api/WebhookEventTest.php
Normal file
190
tests/PayPal/Test/Api/WebhookEventTest.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Test\Api;
|
||||
|
||||
use PayPal\Common\ResourceModel;
|
||||
use PayPal\Validation\ArgumentValidator;
|
||||
use PayPal\Api\WebhookEventList;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
use PayPal\Api\WebhookEvent;
|
||||
|
||||
/**
|
||||
* Class WebhookEvent
|
||||
*
|
||||
* @package PayPal\Test\Api
|
||||
*/
|
||||
class WebhookEventTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Gets Json String of Object WebhookEvent
|
||||
* @return string
|
||||
*/
|
||||
public static function getJson()
|
||||
{
|
||||
return '{"id":"TestSample","create_time":"TestSample","resource_type":"TestSample","event_type":"TestSample","summary":"TestSample","resource":"TestSampleObject","links":' .LinksTest::getJson() . '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Object Instance with Json data filled in
|
||||
* @return WebhookEvent
|
||||
*/
|
||||
public static function getObject()
|
||||
{
|
||||
return new WebhookEvent(self::getJson());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests for Serialization and Deserialization Issues
|
||||
* @return WebhookEvent
|
||||
*/
|
||||
public function testSerializationDeserialization()
|
||||
{
|
||||
$obj = new WebhookEvent(self::getJson());
|
||||
$this->assertNotNull($obj);
|
||||
$this->assertNotNull($obj->getId());
|
||||
$this->assertNotNull($obj->getCreateTime());
|
||||
$this->assertNotNull($obj->getResourceType());
|
||||
$this->assertNotNull($obj->getEventType());
|
||||
$this->assertNotNull($obj->getSummary());
|
||||
$this->assertNotNull($obj->getResource());
|
||||
$this->assertNotNull($obj->getLinks());
|
||||
$this->assertEquals(self::getJson(), $obj->toJson());
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSerializationDeserialization
|
||||
* @param WebhookEvent $obj
|
||||
*/
|
||||
public function testGetters($obj)
|
||||
{
|
||||
$this->assertEquals($obj->getId(), "TestSample");
|
||||
$this->assertEquals($obj->getCreateTime(), "TestSample");
|
||||
$this->assertEquals($obj->getResourceType(), "TestSample");
|
||||
$this->assertEquals($obj->getEventType(), "TestSample");
|
||||
$this->assertEquals($obj->getSummary(), "TestSample");
|
||||
$this->assertEquals($obj->getResource(), "TestSampleObject");
|
||||
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSerializationDeserialization
|
||||
* @param WebhookEvent $obj
|
||||
*/
|
||||
public function testDeprecatedGetters($obj)
|
||||
{
|
||||
$this->assertEquals($obj->getCreate_time(), "TestSample");
|
||||
$this->assertEquals($obj->getResource_type(), "TestSample");
|
||||
$this->assertEquals($obj->getEvent_type(), "TestSample");
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSerializationDeserialization
|
||||
* @param WebhookEvent $obj
|
||||
*/
|
||||
public function testDeprecatedSetterNormalGetter($obj)
|
||||
{
|
||||
|
||||
// Check for Create_time
|
||||
$obj->setCreateTime(null);
|
||||
$this->assertNull($obj->getCreate_time());
|
||||
$this->assertNull($obj->getCreateTime());
|
||||
$this->assertSame($obj->getCreateTime(), $obj->getCreate_time());
|
||||
$obj->setCreate_time("TestSample");
|
||||
$this->assertEquals($obj->getCreate_time(), "TestSample");
|
||||
|
||||
// Check for Resource_type
|
||||
$obj->setResourceType(null);
|
||||
$this->assertNull($obj->getResource_type());
|
||||
$this->assertNull($obj->getResourceType());
|
||||
$this->assertSame($obj->getResourceType(), $obj->getResource_type());
|
||||
$obj->setResource_type("TestSample");
|
||||
$this->assertEquals($obj->getResource_type(), "TestSample");
|
||||
|
||||
// Check for Event_type
|
||||
$obj->setEventType(null);
|
||||
$this->assertNull($obj->getEvent_type());
|
||||
$this->assertNull($obj->getEventType());
|
||||
$this->assertSame($obj->getEventType(), $obj->getEvent_type());
|
||||
$obj->setEvent_type("TestSample");
|
||||
$this->assertEquals($obj->getEvent_type(), "TestSample");
|
||||
|
||||
//Test All Deprecated Getters and Normal Getters
|
||||
$this->testDeprecatedGetters($obj);
|
||||
$this->testGetters($obj);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param WebhookEvent $obj
|
||||
*/
|
||||
public function testGet($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
WebhookEventTest::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->get("eventId", $mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param WebhookEvent $obj
|
||||
*/
|
||||
public function testResend($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
self::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->resend($mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param WebhookEvent $obj
|
||||
*/
|
||||
public function testList($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
WebhookEventListTest::getJson()
|
||||
));
|
||||
$params = array();
|
||||
|
||||
$result = $obj->all($params, $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