updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}

View File

@@ -6,8 +6,6 @@ use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Message;
/**
* BaseOptionedModel.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
@@ -17,34 +15,29 @@ class BaseOptionedModel extends Units\Test
{
$this->if($object = new Message('Test', ['param' => 'test']))
->boolean($object->hasOption('param'))
->isTrue()
->isTrue()
->string($object->getOption('param'))
->isEqualTo('test')
->isEqualTo('test')
->boolean($object->hasOption('notExist'))
->isFalse()
->isFalse()
->variable($object->getOption('notExist'))
->isNull()
->isNull()
->string($object->getOption('renotExist', '12345'))
->isEqualTo('12345')
->isEqualTo('12345')
->when($object->setOptions(['chuck' => 'norris']))
->boolean($object->hasOption('chuck'))
->isTrue()
->isTrue()
->string($object->getOption('chuck'))
->isEqualTo('norris')
->isEqualTo('norris')
->when($object->setOption('poney', 'powerful'))
->boolean($object->hasOption('poney'))
->isTrue()
->isTrue()
->string($object->getOption('poney'))
->isEqualTo('powerful')
->isEqualTo('powerful')
->when($object->setOption('null', null))
->boolean($object->hasOption('null'))
->isTrue()
->isTrue()
->variable($object->getOption('null'))
->isNull()
;
->isNull();
}
}

View File

@@ -6,8 +6,6 @@ use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Device;
/**
* BaseParameteredModel.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
@@ -17,34 +15,29 @@ class BaseParameteredModel extends Units\Test
{
$this->if($object = new Device('Test', ['param' => 'test']))
->boolean($object->hasParameter('param'))
->isTrue()
->isTrue()
->string($object->getParameter('param'))
->isEqualTo('test')
->isEqualTo('test')
->boolean($object->hasParameter('notExist'))
->isFalse()
->isFalse()
->variable($object->getParameter('notExist'))
->isNull()
->isNull()
->string($object->getParameter('renotExist', '12345'))
->isEqualTo('12345')
->isEqualTo('12345')
->when($object->setParameters(['chuck' => 'norris']))
->boolean($object->hasParameter('chuck'))
->isTrue()
->isTrue()
->string($object->getParameter('chuck'))
->isEqualTo('norris')
->isEqualTo('norris')
->when($object->setParameter('poney', 'powerful'))
->boolean($object->hasParameter('poney'))
->isTrue()
->isTrue()
->string($object->getParameter('poney'))
->isEqualTo('powerful')
->isEqualTo('powerful')
->when($object->setParameter('null', null))
->boolean($object->hasParameter('null'))
->isTrue()
->isTrue()
->variable($object->getParameter('null'))
->isNull()
;
->isNull();
}
}

View File

@@ -6,8 +6,6 @@ use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Device as TestedModel;
/**
* Device.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
@@ -17,18 +15,16 @@ class Device extends Units\Test
{
$this->if($object = new TestedModel('t0k3n'))
->string($object->getToken())->isEqualTo('t0k3n')
->array($object->getParameters())->isEmpty()
;
->array($object->getParameters())->isEmpty();
$this->if($object = new TestedModel('t0k3n', ['param' => 'test']))
->string($object->getToken())->isEqualTo('t0k3n')
->when($object->setToken('t0k3ns3tt3d'))
->string($object->getToken())->isEqualTo('t0k3ns3tt3d')
->array($object->getParameters())
->hasKey('param')
->contains('test')
->size
->isEqualTo(1)
;
->hasKey('param')
->contains('test')
->size
->isEqualTo(1);
}
}

View File

@@ -6,8 +6,6 @@ use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Message as TestedModel;
/**
* Message.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
@@ -17,20 +15,18 @@ class Message extends Units\Test
{
$this->if($object = new TestedModel('Test'))
->string($object->getText())->isEqualTo('Test')
->array($object->getOptions())->isEmpty()
;
->array($object->getOptions())->isEmpty();
$this->if($object = new TestedModel('Test', [
'param' => 'test',
]))
'param' => 'test',
]))
->string($object->getText())->isEqualTo('Test')
->when($object->setText('Test 2'))
->string($object->getText())->isEqualTo('Test 2')
->array($object->getOptions())
->hasKey('param')
->contains('test')
->size
->isEqualTo(1)
;
->hasKey('param')
->contains('test')
->size
->isEqualTo(1);
}
}

View File

@@ -3,165 +3,144 @@
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Adapter\AdapterInterface;
use Sly\NotificationPusher\Adapter\Apns;
use Sly\NotificationPusher\Adapter\Gcm;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Exception\AdapterException;
use Sly\NotificationPusher\Model\Device as DeviceModel;
use Sly\NotificationPusher\Model\Message as MessageModel;
use Sly\NotificationPusher\Model\Push 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\Adapter\Apns as BaseApnsAdapter;
/**
* Push.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class Push extends Units\Test
{
const APNS_TOKEN_EXAMPLE = '111db24975bb6c6b63214a8d268052aa0a965cc1e32110ab06a72b19074c2222';
const GCM_TOKEN_EXAMPLE = 'AAA91bG9ISdL94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropAcRp4BSxVBBB';
const GCM_TOKEN_EXAMPLE = 'AAA91bG9ISdL94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropAcRp4BSxVBBB';
public function testConstructWithOneDevice()
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
$this->if($this->mockClass(AdapterInterface::class, '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDevice('Token1'))
->and($message = new BaseMessage('Test'))
->and($devices = new DeviceModel('Token1'))
->and($message = new MessageModel('Test'))
->and($object = new TestedModel($adapter, $devices, $message))
->object($object->getDevices())
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
->isInstanceOf(DeviceCollection::class)
->integer($object->getDevices()->count())
->isEqualTo(1)
->isEqualTo(1)
->array($object->getOptions())
->isEmpty()
;
->isEmpty();
}
public function testConstructWithManyDevicesAndOptions()
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
$this->if($this->mockClass(AdapterInterface::class, '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection([new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3')]))
->and($message = new BaseMessage('Test'))
->and($devices = new DeviceCollection([new DeviceModel('Token1'), new DeviceModel('Token2'),
new DeviceModel('Token3')]))
->and($message = new MessageModel('Test'))
->and($object = new TestedModel($adapter, $devices, $message, ['param' => 'test']))
->object($object->getDevices())
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
->isInstanceOf(DeviceCollection::class)
->integer($object->getDevices()->count())
->isEqualTo(3)
->isEqualTo(3)
->array($object->getOptions())
->hasKey('param')
->contains('test')
->size
->isEqualTo(1)
;
->hasKey('param')
->contains('test')
->size
->isEqualTo(1);
}
public function testStatus()
{
date_default_timezone_set('UTC');
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
$this->if($this->mockClass(AdapterInterface::class, '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection([new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3')]))
->and($message = new BaseMessage('Test'))
->and($devices = new DeviceCollection([new DeviceModel('Token1'), new DeviceModel('Token2'),
new DeviceModel('Token3')]))
->and($message = new MessageModel('Test'))
->and($object = new TestedModel($adapter, $devices, $message))
->string($object->getStatus())
->isEqualTo(TestedModel::STATUS_PENDING)
->isEqualTo(TestedModel::STATUS_PENDING)
->boolean($object->isPushed())
->isFalse()
->isFalse()
->when($object->pushed())
->and($dt = new \DateTime())
->string($object->getStatus())
->isEqualTo(TestedModel::STATUS_PUSHED)
->isEqualTo(TestedModel::STATUS_PUSHED)
->boolean($object->isPushed())
->isTrue()
->isTrue()
->dateTime($object->getPushedAt())
->hasDate($dt->format("Y"), $dt->format("m"), $dt->format('d'))
->hasDate($dt->format("Y"), $dt->format("m"), $dt->format('d'))
->when($object->setStatus(TestedModel::STATUS_PENDING))
->string($object->getStatus())
->isEqualTo(TestedModel::STATUS_PENDING)
->isEqualTo(TestedModel::STATUS_PENDING)
->boolean($object->isPushed())
->isFalse()
->isFalse()
->when($fDt = new \DateTime('2013-01-01'))
->and($object->setPushedAt($fDt))
->dateTime($object->getPushedAt())
->isIdenticalTo($fDt)
;
->isIdenticalTo($fDt);
}
public function testDevicesTokensCheck()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($this->mockClass(Apns::class, '\Mock'))
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($this->mockClass(Gcm::class, '\Mock'))
->and($apnsAdapter = new \mock\Apns())
->and($gcmAdapter = new \mock\Gcm())
->and($badDevice = new BaseDevice('BadToken'))
->and($message = new BaseMessage('Test'))
->and($badDevice = new DeviceModel('BadToken'))
->and($message = new MessageModel('Test'))
->exception(function () use ($apnsAdapter, $badDevice, $message) {
$object = new TestedModel($apnsAdapter, $badDevice, $message);
})
->isInstanceOf('\Sly\NotificationPusher\Exception\AdapterException')
->when($goodDevice = new BaseDevice(self::APNS_TOKEN_EXAMPLE))
->object($object = new TestedModel($apnsAdapter, $goodDevice, $message))
;
->isInstanceOf(AdapterException::class)
->when($goodDevice = new DeviceModel(self::APNS_TOKEN_EXAMPLE))
->object($object = new TestedModel($apnsAdapter, $goodDevice, $message));
}
public function testAdapter()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($this->mockClass(Apns::class, '\Mock'))
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($this->mockClass(Gcm::class, '\Mock'))
->and($apnsAdapter = new \mock\Apns())
->and($gcmAdapter = new \mock\Gcm())
->and($devices = new BaseDevice(self::APNS_TOKEN_EXAMPLE))
->and($message = new BaseMessage('Test'))
->and($devices = new DeviceModel(self::APNS_TOKEN_EXAMPLE))
->and($message = new MessageModel('Test'))
->and($object = new TestedModel($apnsAdapter, $devices, $message))
->object($object->getAdapter())
->isInstanceOf('\Sly\NotificationPusher\Adapter\Apns')
->isInstanceOf(Apns::class)
->when($object->setAdapter($gcmAdapter))
->and($object->setDevices(new BaseDeviceCollection([new BaseDevice(self::GCM_TOKEN_EXAMPLE)])))
->and($object->setDevices(new DeviceCollection([new DeviceModel(self::GCM_TOKEN_EXAMPLE)])))
->object($object->getAdapter())
->isInstanceOf('\Sly\NotificationPusher\Adapter\Gcm')
;
->isInstanceOf(Gcm::class);
}
public function testMessage()
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
$this->if($this->mockClass(AdapterInterface::class, '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection([new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3')]))
->and($message = new BaseMessage('Test'))
->and($devices = new DeviceCollection([new DeviceModel('Token1'), new DeviceModel('Token2'),
new DeviceModel('Token3')]))
->and($message = new MessageModel('Test'))
->and($object = new TestedModel($adapter, $devices, $message))
->object($object->getMessage())
->isInstanceOf('\Sly\NotificationPusher\Model\Message')
->isInstanceOf(MessageModel::class)
->string($object->getMessage()->getText())
->isEqualTo('Test')
->when($object->setMessage(new BaseMessage('Test 2')))
->isEqualTo('Test')
->when($object->setMessage(new MessageModel('Test 2')))
->object($object->getMessage())
->isInstanceOf('\Sly\NotificationPusher\Model\Message')
->isInstanceOf(MessageModel::class)
->string($object->getMessage()->getText())
->isEqualTo('Test 2')
;
->isEqualTo('Test 2');
}
}

View File

@@ -3,16 +3,16 @@
namespace tests\units\Sly\NotificationPusher;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Adapter\Apns;
use Sly\NotificationPusher\Collection\DeviceCollection;
use Sly\NotificationPusher\Collection\PushCollection;
use Sly\NotificationPusher\Model\Device;
use Sly\NotificationPusher\Model\Message;
use Sly\NotificationPusher\Model\Push;
use Sly\NotificationPusher\Model\Response;
use Sly\NotificationPusher\PushManager as TestedModel;
use Sly\NotificationPusher\Model\Message as BaseMessage;
use Sly\NotificationPusher\Model\Device as BaseDevice;
use Sly\NotificationPusher\Collection\DeviceCollection as BaseDeviceCollection;
/**
* PushManager.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
@@ -24,69 +24,59 @@ class PushManager extends Units\Test
{
$this->if($object = new TestedModel())
->string($object->getEnvironment())
->isEqualTo(TestedModel::ENVIRONMENT_DEV)
->isEqualTo(TestedModel::ENVIRONMENT_DEV)
->when($object = new TestedModel(TestedModel::ENVIRONMENT_PROD))
->string($object->getEnvironment())
->isEqualTo(TestedModel::ENVIRONMENT_PROD)
;
->isEqualTo(TestedModel::ENVIRONMENT_PROD);
}
public function testCollection()
{
$this->if($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::APNS_TOKEN_EXAMPLE)]))
->and($push->getMockController()->getMessage = new Message('Test'))
->and($push->getMockController()->getDevices = new DeviceCollection([new Device(self::APNS_TOKEN_EXAMPLE)]))
->and($push2 = new \Mock\Push())
->and($push2->getMockController()->getMessage = new BaseMessage('Test 2'))
->and($push2->getMockController()->getDevices = new BaseDeviceCollection([new BaseDevice(self::APNS_TOKEN_EXAMPLE)]))
->and($push2->getMockController()->getMessage = new Message('Test 2'))
->and($push2->getMockController()->getDevices = new DeviceCollection([new Device(self::APNS_TOKEN_EXAMPLE)]))
->and($object = (new TestedModel())->getPushCollection())
->when($object->add($push))
->object($object)
->isInstanceOf('\Sly\NotificationPusher\Collection\PushCollection')
->isInstanceOf(PushCollection::class)
->object($object->getIterator())
->hasSize(1)
->hasSize(1)
->when($object->add($push2))
->object($object)
->isInstanceOf('\Sly\NotificationPusher\Collection\PushCollection')
->isInstanceOf(PushCollection::class)
->object($object->getIterator())
->hasSize(2)
->hasSize(2)
->object($object->first())
->isEqualTo($push)
->isEqualTo($push)
->object($object->last())
->isEqualTo($push2)
;
->isEqualTo($push2);
}
public function testPush()
{
date_default_timezone_set('UTC');
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($this->mockClass(Apns::class, '\Mock'))
->and($apnsAdapter = new \Mock\Apns())
->and($apnsAdapter->getMockController()->push = true)
->and($apnsAdapter->getMockController()->getResponse = new Response())
->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::APNS_TOKEN_EXAMPLE)]))
->and($push->getMockController()->getMessage = new Message('Test'))
->and($push->getMockController()->getDevices = new DeviceCollection([new Device(self::APNS_TOKEN_EXAMPLE)]))
->and($push->getMockController()->getAdapter = $apnsAdapter)
->and($object = new TestedModel())
->and($object->add($push))
->object($object->push())
->isInstanceOf('\Sly\NotificationPusher\Collection\PushCollection')
->hasSize(1)
->isInstanceOf(PushCollection::class)
->hasSize(1)
->object($object->getResponse())
->isInstanceOf('\Sly\NotificationPusher\Model\Response')
;
->isInstanceOf(Response::class);
}
}