updated-packages
This commit is contained in:
@@ -4,207 +4,192 @@ namespace tests\units\Sly\NotificationPusher\Adapter;
|
||||
|
||||
use mageekguy\atoum as Units;
|
||||
use Sly\NotificationPusher\Adapter\Apns as TestedModel;
|
||||
use Sly\NotificationPusher\Collection\DeviceCollection as BaseDeviceCollection;
|
||||
use Sly\NotificationPusher\Collection\DeviceCollection;
|
||||
use Sly\NotificationPusher\Model\Device as BaseDevice;
|
||||
use Sly\NotificationPusher\Model\Message as BaseMessage;
|
||||
use Sly\NotificationPusher\Exception\AdapterException;
|
||||
use Sly\NotificationPusher\Model\Device;
|
||||
use Sly\NotificationPusher\Model\Message;
|
||||
use Sly\NotificationPusher\Model\Push;
|
||||
use Sly\NotificationPusher\Model\Response;
|
||||
use ZendService\Apple\Apns\Client\Message as BaseServiceClient;
|
||||
use ZendService\Apple\Apns\Message as BaseServiceMessage;
|
||||
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
|
||||
use ZendService\Apple\Apns\Client\Feedback;
|
||||
use ZendService\Apple\Apns\Client\Message as ZendClientMessage;
|
||||
use ZendService\Apple\Apns\Message as ZendServiceMessage;
|
||||
use ZendService\Apple\Apns\Response\Message as ZendResponseMessage;
|
||||
use ZendService\Apple\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Apns.
|
||||
*
|
||||
* @uses atoum\test
|
||||
* @author Cédric Dugat <cedric@dugat.me>
|
||||
*/
|
||||
class Apns extends Units\Test
|
||||
{
|
||||
const APNS_TOKEN_EXAMPLE = '111db24975bb6c6b63214a8d268052aa0a965cc1e32110ab06a72b19074c2222';
|
||||
const APNS_TOKEN_EXAMPLE_64 = '111db24975bb6c6b63214a8d268052aa0a965cc1e32110ab06a72b19074c2222';
|
||||
const APNS_TOKEN_EXAMPLE_65 = '111db24975bb6c6b63214a8d268052aa0a965cc1e32110ab06a72b19074c22225';
|
||||
|
||||
public function testConstruct()
|
||||
{
|
||||
$this
|
||||
->exception(function() {
|
||||
->exception(static function () {
|
||||
$object = new TestedModel();
|
||||
})
|
||||
->isInstanceOf('\Symfony\Component\OptionsResolver\Exception\MissingOptionsException')
|
||||
->message
|
||||
->contains('certificate')
|
||||
->exception(function() {
|
||||
->isInstanceOf(MissingOptionsException::class)
|
||||
->message
|
||||
->contains('certificate')
|
||||
->exception(static function () {
|
||||
$object = new TestedModel(['certificate' => 'absent.pem']);
|
||||
})
|
||||
->isInstanceOf('\Sly\NotificationPusher\Exception\AdapterException')
|
||||
->message
|
||||
->contains('does not exist')
|
||||
|
||||
->isInstanceOf(AdapterException::class)
|
||||
->message
|
||||
->contains('does not exist')
|
||||
->when($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
->and($object->setParameters(['certificate' => 'test.pem', 'passPhrase' => 'test']))
|
||||
->and($object->setResponse(new Response()))
|
||||
->array($object->getParameters())
|
||||
->isNotEmpty()
|
||||
->hasSize(2)
|
||||
->isNotEmpty()
|
||||
->hasSize(2)
|
||||
->string($object->getParameter('certificate'))
|
||||
->isEqualTo('test.pem')
|
||||
;
|
||||
->isEqualTo('test.pem');
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
->boolean($object->supports('wrongToken'))
|
||||
->isFalse()
|
||||
->boolean($object->supports(self::APNS_TOKEN_EXAMPLE))
|
||||
->isTrue()
|
||||
;
|
||||
->isFalse()
|
||||
->boolean($object->supports(self::APNS_TOKEN_EXAMPLE_64))
|
||||
->isTrue()
|
||||
->boolean($object->supports(self::APNS_TOKEN_EXAMPLE_65))
|
||||
->isTrue();
|
||||
}
|
||||
|
||||
public function testDefinedParameters()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
->array($defaultParameters = $object->getDefinedParameters())
|
||||
->isEmpty()
|
||||
;
|
||||
->isEmpty();
|
||||
}
|
||||
|
||||
public function testDefaultParameters()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
->array($defaultParameters = $object->getDefaultParameters())
|
||||
->isNotEmpty()
|
||||
->hasKey('passPhrase')
|
||||
->isNotEmpty()
|
||||
->hasKey('passPhrase')
|
||||
->variable($defaultParameters['passPhrase'])
|
||||
->isNull()
|
||||
;
|
||||
->isNull();
|
||||
}
|
||||
|
||||
public function testRequiredParameters()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
->array($requiredParameters = $object->getRequiredParameters())
|
||||
->isNotEmpty()
|
||||
->contains('certificate')
|
||||
;
|
||||
->isNotEmpty()
|
||||
->contains('certificate');
|
||||
}
|
||||
|
||||
public function testGetOpenedClient()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockGenerator()->orphanize('open'))
|
||||
->and($this->mockClass('\ZendService\Apple\Apns\Client\Message', '\Mock\ZendService'))
|
||||
->and($this->mockClass(ZendClientMessage::class, '\Mock\ZendService'))
|
||||
->and($serviceClient = new \Mock\ZendService\Message())
|
||||
->and($object->getMockController()->getParameters = [])
|
||||
->exception(function() use($object) {
|
||||
$object->getOpenedClient(new BaseServiceClient());
|
||||
->exception(static function () use ($object) {
|
||||
$object->getOpenedClient(new ZendClientMessage());
|
||||
})
|
||||
->isInstanceOf('\ZendService\Apple\Exception\InvalidArgumentException')
|
||||
->message
|
||||
->contains('Certificate must be a valid path to a APNS certificate')
|
||||
|
||||
->when($object = new TestedModel(['certificate' => __DIR__.'/../Resources/apns-certificate.pem']))
|
||||
->and($object->getOpenedClient($serviceClient))
|
||||
;
|
||||
->isInstanceOf(InvalidArgumentException::class)
|
||||
->message
|
||||
->contains('Certificate must be a valid path to a APNS certificate')
|
||||
->when($object = new TestedModel(['certificate' => __DIR__ . '/../Resources/apns-certificate.pem']))
|
||||
->and($object->getOpenedClient($serviceClient));
|
||||
}
|
||||
|
||||
public function testGetServiceMessageFromOrigin()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Model\Device', '\Mock'))
|
||||
->and($this->mockClass(Device::class, '\Mock'))
|
||||
->and($device = new \Mock\Device())
|
||||
->and($device->getMockController()->getToken = self::APNS_TOKEN_EXAMPLE)
|
||||
|
||||
->and($device->getMockController()->getToken = self::APNS_TOKEN_EXAMPLE_64)
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Model\Message', '\Mock'))
|
||||
->and($this->mockClass(Message::class, '\Mock'))
|
||||
->and($message = new \Mock\Message())
|
||||
->and($message->getMockController()->getText = 'Test')
|
||||
|
||||
->object($object->getServiceMessageFromOrigin($device, $message))
|
||||
->isInstanceOf('\ZendService\Apple\Apns\Message')
|
||||
;
|
||||
->isInstanceOf(ZendServiceMessage::class);
|
||||
}
|
||||
|
||||
public function testPush()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct')
|
||||
->makeVisible('getOpenedServiceClient')
|
||||
->generate(\Sly\NotificationPusher\Adapter\Apns::class, '\Mock', 'Apns'))
|
||||
->makeVisible('getOpenedServiceClient')
|
||||
->generate(TestedModel::class, '\Mock', 'Apns'))
|
||||
->and($object = new \Mock\Apns())
|
||||
->and($object->setResponse(new Response()))
|
||||
|
||||
->and($this->mockClass(\ZendService\Apple\Apns\Response\Message::class, '\Mock\ZendService', 'Response'))
|
||||
->and($this->mockClass(ZendResponseMessage::class, '\Mock\ZendService', 'Response'))
|
||||
->and($serviceResponse = new \Mock\ZendService\Response())
|
||||
->and($serviceResponse->getMockController()->getCode = \ZendService\Apple\Apns\Response\Message::RESULT_OK)
|
||||
->and($serviceResponse->getMockController()->getCode = ZendResponseMessage::RESULT_OK)
|
||||
->and($serviceResponse->getMockController()->getId = 0)
|
||||
|
||||
->and($this->mockGenerator()->orphanize('__construct')
|
||||
->orphanize('open')
|
||||
->orphanize('send')
|
||||
->generate(\ZendService\Apple\Apns\Client\Message::class, '\Mock\ZendService'))
|
||||
->orphanize('open')
|
||||
->orphanize('send')
|
||||
->generate(ZendClientMessage::class, '\Mock\ZendService'))
|
||||
->and($serviceClient = new \Mock\ZendService\Message())
|
||||
->and($serviceClient->getMockController()->send = $serviceResponse)
|
||||
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass(\Sly\NotificationPusher\Model\Push::class, '\Mock'))
|
||||
->and($this->mockClass(Push::class, '\Mock'))
|
||||
->and($push = new \Mock\Push())
|
||||
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
|
||||
->and($push->getMockController()->getDevices = new BaseDeviceCollection(
|
||||
[new BaseDevice(self::APNS_TOKEN_EXAMPLE)]
|
||||
->and($push->getMockController()->getMessage = new Message('Test'))
|
||||
->and($push->getMockController()->getDevices = new DeviceCollection(
|
||||
[new Device(self::APNS_TOKEN_EXAMPLE_64)]
|
||||
))
|
||||
|
||||
->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())
|
||||
->and($object->getMockController()->getServiceMessageFromOrigin = new ZendServiceMessage())
|
||||
->and($object->getMockController()->getOpenedClient = $serviceClient)
|
||||
->and($this->calling($object)->getOpenedServiceClient = $serviceClient)
|
||||
|
||||
->object($result = $object->push($push))
|
||||
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
|
||||
->boolean($result->count() == 1)
|
||||
->isTrue();
|
||||
->isInstanceOf(DeviceCollection::class)
|
||||
->boolean($result->count() == 1)
|
||||
->isTrue();
|
||||
}
|
||||
|
||||
public function testCountIsEmpty() {
|
||||
public function testCountIsEmpty()
|
||||
{
|
||||
$this->if($dcoll = new DeviceCollection())
|
||||
->boolean($dcoll->isEmpty())
|
||||
->isTrue();
|
||||
->isTrue();
|
||||
}
|
||||
|
||||
public function testFeedback()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
|
||||
->and($this->mockClass('\ZendService\Apple\Apns\Response\Message', '\Mock\ZendService', 'Response'))
|
||||
->and($this->mockClass(ZendResponseMessage::class, '\Mock\ZendService', 'Response'))
|
||||
->and($serviceResponse = new \Mock\ZendService\Response())
|
||||
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockGenerator()->orphanize('open'))
|
||||
->and($this->mockGenerator()->orphanize('send'))
|
||||
->and($this->mockClass('\ZendService\Apple\Apns\Client\Feedback', '\Mock\ZendService'))
|
||||
->and($this->mockClass(Feedback::class, '\Mock\ZendService'))
|
||||
->and($serviceClient = new \Mock\ZendService\Feedback())
|
||||
->and($serviceClient->getMockController()->feedback = $serviceResponse)
|
||||
|
||||
->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())
|
||||
->and($object->getMockController()->getServiceMessageFromOrigin = new ZendServiceMessage())
|
||||
->and($object->getMockController()->getOpenedClient = $serviceClient)
|
||||
|
||||
->array($object->getFeedback())
|
||||
->isEmpty()
|
||||
;
|
||||
->isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
namespace tests\units\Sly\NotificationPusher\Adapter;
|
||||
|
||||
use mageekguy\atoum as Units;
|
||||
use Sly\NotificationPusher\PushManager as BasePushManager;
|
||||
use Sly\NotificationPusher\PushManager;
|
||||
|
||||
/**
|
||||
* BaseAdapter.
|
||||
*
|
||||
* @uses atoum\test
|
||||
* @author Cédric Dugat <cedric@dugat.me>
|
||||
*/
|
||||
@@ -16,37 +14,33 @@ class BaseAdapter extends Units\Test
|
||||
public function testAdapterKey()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(\Sly\NotificationPusher\Adapter\Apns::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
->and($object->getMockController()->getAdapterKey = 'Apns')
|
||||
->string($object->getAdapterKey())
|
||||
->isEqualTo('Apns')
|
||||
->isEqualTo('Apns')
|
||||
->string((string) $object)
|
||||
->isEqualTo('Apns')
|
||||
;
|
||||
->isEqualTo('Apns');
|
||||
}
|
||||
|
||||
public function testEnvironment()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
|
||||
->and($this->mockClass(\Sly\NotificationPusher\Adapter\Apns::class, '\Mock'))
|
||||
->and($object = new \Mock\Apns())
|
||||
|
||||
->when($object->setEnvironment(BasePushManager::ENVIRONMENT_DEV))
|
||||
->when($object->setEnvironment(PushManager::ENVIRONMENT_DEV))
|
||||
->string($object->getEnvironment())
|
||||
->isEqualTo(BasePushManager::ENVIRONMENT_DEV)
|
||||
->isEqualTo(PushManager::ENVIRONMENT_DEV)
|
||||
->boolean($object->isDevelopmentEnvironment())
|
||||
->isTrue()
|
||||
->isTrue()
|
||||
->boolean($object->isProductionEnvironment())
|
||||
->isFalse()
|
||||
|
||||
->when($object->setEnvironment(BasePushManager::ENVIRONMENT_PROD))
|
||||
->isFalse()
|
||||
->when($object->setEnvironment(PushManager::ENVIRONMENT_PROD))
|
||||
->string($object->getEnvironment())
|
||||
->isEqualTo(BasePushManager::ENVIRONMENT_PROD)
|
||||
->isEqualTo(PushManager::ENVIRONMENT_PROD)
|
||||
->boolean($object->isProductionEnvironment())
|
||||
->isTrue()
|
||||
->isTrue()
|
||||
->boolean($object->isDevelopmentEnvironment())
|
||||
->isFalse()
|
||||
;
|
||||
->isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ namespace tests\units\Sly\NotificationPusher\Adapter;
|
||||
|
||||
use mageekguy\atoum as Units;
|
||||
use Sly\NotificationPusher\Adapter\Gcm as TestedModel;
|
||||
|
||||
use Sly\NotificationPusher\Model\Message as BaseMessage;
|
||||
use Sly\NotificationPusher\Model\Device as BaseDevice;
|
||||
use Sly\NotificationPusher\Collection\DeviceCollection as BaseDeviceCollection;
|
||||
|
||||
use Sly\NotificationPusher\Collection\DeviceCollection;
|
||||
use Sly\NotificationPusher\Model\Device;
|
||||
use Sly\NotificationPusher\Model\GcmMessage;
|
||||
use Sly\NotificationPusher\Model\Message;
|
||||
use Sly\NotificationPusher\Model\Push;
|
||||
use Sly\NotificationPusher\Model\Response;
|
||||
use ZendService\Google\Gcm\Client as BaseServiceClient;
|
||||
use ZendService\Google\Gcm\Message as BaseServiceMessage;
|
||||
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
|
||||
use ZendService\Google\Exception\InvalidArgumentException;
|
||||
use ZendService\Google\Gcm\Client as ZendServiceClient;
|
||||
use ZendService\Google\Gcm\Message as ZendServiceMessage;
|
||||
use ZendService\Google\Gcm\Response as ZendResponseAlias;
|
||||
|
||||
/**
|
||||
* Gcm.
|
||||
*
|
||||
* @uses atoum\test
|
||||
* @author Cédric Dugat <cedric@dugat.me>
|
||||
*/
|
||||
@@ -28,49 +29,46 @@ class Gcm extends Units\Test
|
||||
public function testConstruct()
|
||||
{
|
||||
$this
|
||||
->exception(function() {
|
||||
->exception(function () {
|
||||
$object = new TestedModel();
|
||||
})
|
||||
->isInstanceOf('\Symfony\Component\OptionsResolver\Exception\MissingOptionsException')
|
||||
->message
|
||||
->contains('apiKey')
|
||||
|
||||
->isInstanceOf(MissingOptionsException::class)
|
||||
->message
|
||||
->contains('apiKey')
|
||||
->when($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
->and($object->setParameters(['apiKey' => 'test']))
|
||||
->array($object->getParameters())
|
||||
->isNotEmpty()
|
||||
->hasSize(1)
|
||||
->isNotEmpty()
|
||||
->hasSize(1)
|
||||
->string($object->getParameter('apiKey'))
|
||||
->isEqualTo('test')
|
||||
;
|
||||
->isEqualTo('test');
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
->boolean($object->supports('')) // Test empty string
|
||||
->isFalse()
|
||||
->isFalse()
|
||||
->boolean($object->supports(2)) // Test a number
|
||||
->isFalse()
|
||||
->isFalse()
|
||||
->boolean($object->supports([])) // Test an array
|
||||
->isFalse()
|
||||
->isFalse()
|
||||
->boolean($object->supports(json_decode('{}'))) // Tests an object
|
||||
->isFalse()
|
||||
->isFalse()
|
||||
->boolean($object->supports(self::GCM_TOKEN_EXAMPLE))
|
||||
->isTrue()
|
||||
->isTrue()
|
||||
->boolean($object->supports(self::ALT_GCM_TOKEN_EXAMPLE))
|
||||
->isTrue()
|
||||
;
|
||||
->isTrue();
|
||||
}
|
||||
|
||||
public function testDefinedParameters()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
->array($definedParameters = $object->getDefinedParameters())
|
||||
->isNotEmpty()
|
||||
@@ -79,129 +77,115 @@ class Gcm extends Units\Test
|
||||
'delayWhileIdle',
|
||||
'ttl',
|
||||
'restrictedPackageName',
|
||||
'dryRun'
|
||||
'dryRun',
|
||||
]);
|
||||
}
|
||||
|
||||
public function testDefaultParameters()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
->array($defaultParameters = $object->getDefaultParameters())
|
||||
->isEmpty()
|
||||
;
|
||||
->isEmpty();
|
||||
}
|
||||
|
||||
public function testRequiredParameters()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
->array($requiredParameters = $object->getRequiredParameters())
|
||||
->isNotEmpty()
|
||||
->contains('apiKey')
|
||||
;
|
||||
->isNotEmpty()
|
||||
->contains('apiKey');
|
||||
}
|
||||
|
||||
public function testGetOpenedClient()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockGenerator()->orphanize('open'))
|
||||
->and($this->mockClass('\ZendService\Google\Gcm\Client', '\Mock\ZendService'))
|
||||
->and($this->mockClass(ZendServiceClient::class, '\Mock\ZendService'))
|
||||
->and($serviceClient = new \Mock\ZendService\Client())
|
||||
->and($object->getMockController()->getParameters = [])
|
||||
->exception(function() use($object) {
|
||||
$object->getOpenedClient(new BaseServiceClient());
|
||||
->exception(function () use ($object) {
|
||||
$object->getOpenedClient(new ZendServiceClient());
|
||||
})
|
||||
->isInstanceOf('\ZendService\Google\Exception\InvalidArgumentException')
|
||||
->message
|
||||
->contains('The api key must be a string and not empty')
|
||||
|
||||
->isInstanceOf(InvalidArgumentException::class)
|
||||
->message
|
||||
->contains('The api key must be a string and not empty')
|
||||
->when($object = new TestedModel(['apiKey' => 'test']))
|
||||
->and($object->getOpenedClient($serviceClient))
|
||||
;
|
||||
->and($object->getOpenedClient($serviceClient));
|
||||
}
|
||||
|
||||
public function testGetServiceMessageFromOrigin()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass(\Sly\NotificationPusher\Adapter\Gcm::class, '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass(\Sly\NotificationPusher\Model\Message::class, '\Mock'))
|
||||
->and($this->mockClass(Message::class, '\Mock'))
|
||||
->and($message = new \Mock\Message())
|
||||
->and($message->getMockController()->getOptions = [
|
||||
'param' => 'test',
|
||||
'notificationData' => ['some' => 'foobar']
|
||||
])
|
||||
'param' => 'test',
|
||||
'notificationData' => ['some' => 'foobar'],
|
||||
])
|
||||
->and($message->getMockController()->getText = 'Test')
|
||||
|
||||
->object($originalMessage = $object->getServiceMessageFromOrigin([self::GCM_TOKEN_EXAMPLE], $message))
|
||||
->isInstanceOf(\ZendService\Google\Gcm\Message::class)
|
||||
->array($originalMessage->getData())
|
||||
->notHasKey('notificationData')
|
||||
->array($originalMessage->getNotification())
|
||||
->hasKey('some')
|
||||
->contains('foobar');
|
||||
->isInstanceOf(ZendServiceMessage::class)
|
||||
->array($originalMessage->getData())
|
||||
->notHasKey('notificationData')
|
||||
->array($originalMessage->getNotification())
|
||||
->hasKey('some')
|
||||
->contains('foobar');
|
||||
}
|
||||
|
||||
public function testGcmMessageUse()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass(\Sly\NotificationPusher\Adapter\Gcm::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass(\Sly\NotificationPusher\Model\GcmMessage::class, '\Mock'))
|
||||
->and($message = new \Mock\GcmMessage())
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass(GcmMessage::class, '\Mock'))
|
||||
->and($message = new \Mock\GcmMessage())
|
||||
->and($message->getMockController()->getNotificationData = [
|
||||
'some' => 'foobar'
|
||||
'some' => 'foobar',
|
||||
])
|
||||
->and($message->getMockController()->getText = 'Test')
|
||||
|
||||
->object($originalMessage = $object->getServiceMessageFromOrigin([self::GCM_TOKEN_EXAMPLE], $message))
|
||||
->isInstanceOf(\ZendService\Google\Gcm\Message::class)
|
||||
->array($originalMessage->getData())
|
||||
->notHasKey('notificationData')
|
||||
->array($originalMessage->getNotification())
|
||||
->hasKey('some')
|
||||
->contains('foobar');
|
||||
->isInstanceOf(ZendServiceMessage::class)
|
||||
->array($originalMessage->getData())
|
||||
->notHasKey('notificationData')
|
||||
->array($originalMessage->getNotification())
|
||||
->hasKey('some')
|
||||
->contains('foobar');
|
||||
}
|
||||
|
||||
public function testPush()
|
||||
{
|
||||
$this->if($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
|
||||
->and($this->mockClass(TestedModel::class, '\Mock'))
|
||||
->and($object = new \Mock\Gcm())
|
||||
->and($object->setResponse(new Response()))
|
||||
|
||||
->and($this->mockClass('\ZendService\Google\Gcm\Response', '\Mock\ZendService'))
|
||||
->and($this->mockClass(ZendResponseAlias::class, '\Mock\ZendService'))
|
||||
->and($serviceResponse = new \Mock\ZendService\Response())
|
||||
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockGenerator()->orphanize('open'))
|
||||
->and($this->mockGenerator()->orphanize('send'))
|
||||
->and($this->mockClass('\ZendService\Google\Gcm\Client', '\Mock\ZendService'))
|
||||
->and($this->mockClass(ZendServiceClient::class, '\Mock\ZendService'))
|
||||
->and($serviceClient = new \Mock\ZendService\Message())
|
||||
->and($serviceClient->getMockController()->send = new $serviceResponse)
|
||||
|
||||
->and($this->mockGenerator()->orphanize('__construct'))
|
||||
->and($this->mockClass('\Sly\NotificationPusher\Model\Push', '\Mock'))
|
||||
->and($this->mockClass(Push::class, '\Mock'))
|
||||
->and($push = new \Mock\Push())
|
||||
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
|
||||
->and($push->getMockController()->getDevices = new BaseDeviceCollection([new BaseDevice(self::GCM_TOKEN_EXAMPLE)]))
|
||||
|
||||
->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())
|
||||
->and($push->getMockController()->getMessage = new Message('Test'))
|
||||
->and($push->getMockController()->getDevices = new DeviceCollection([new Device(self::GCM_TOKEN_EXAMPLE)]))
|
||||
->and($object->getMockController()->getServiceMessageFromOrigin = new ZendServiceMessage())
|
||||
->and($object->getMockController()->getOpenedClient = $serviceClient)
|
||||
|
||||
->object($object->push($push))
|
||||
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
|
||||
->hasSize(1)
|
||||
;
|
||||
->isInstanceOf(DeviceCollection::class)
|
||||
->hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user