seeder-migration-issues

This commit is contained in:
RafficMohammed
2023-01-30 14:23:34 +05:30
parent 4d918c722f
commit 2ec836b447
3628 changed files with 116006 additions and 187 deletions

View File

@@ -0,0 +1,186 @@
<?php
namespace tests\units\Sly\NotificationPusher\Adapter;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Adapter\Apns as TestedModel;
use Sly\NotificationPusher\Model\Message as BaseMessage;
use Sly\NotificationPusher\Model\Device as BaseDevice;
use Sly\NotificationPusher\Collection\DeviceCollection as BaseDeviceCollection;
use ZendService\Apple\Apns\Message as BaseServiceMessage;
use ZendService\Apple\Apns\Client\Message as BaseServiceClient;
/**
* Apns.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class Apns extends Units\Test
{
const APNS_TOKEN_EXAMPLE = '111db24975bb6c6b63214a8d268052aa0a965cc1e32110ab06a72b19074c2222';
public function testConstruct()
{
$this
->exception(function() {
$object = new TestedModel();
})
->isInstanceOf('\Symfony\Component\OptionsResolver\Exception\MissingOptionsException')
->message
->contains('certificate')
->exception(function() {
$object = new TestedModel(array('certificate' => 'absent.pem'));
})
->isInstanceOf('\Sly\NotificationPusher\Exception\AdapterException')
->message
->contains('does not exist')
->when($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->and($object->setParameters(array('certificate' => 'test.pem', 'passPhrase' => 'test')))
->array($object->getParameters())
->isNotEmpty()
->hasSize(2)
->string($object->getParameter('certificate'))
->isEqualTo('test.pem')
;
}
public function testSupports()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->boolean($object->supports('wrongToken'))
->isFalse()
->boolean($object->supports(self::APNS_TOKEN_EXAMPLE))
->isTrue()
;
}
public function testDefaultParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->array($defaultParameters = $object->getDefaultParameters())
->isNotEmpty()
->hasKey('passPhrase')
->variable($defaultParameters['passPhrase'])
->isNull()
;
}
public function testRequiredParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->array($requiredParameters = $object->getRequiredParameters())
->isNotEmpty()
->contains('certificate')
;
}
public function testGetOpenedClient()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\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($serviceClient = new \Mock\ZendService\Message())
->and($object->getMockController()->getParameters = array())
->exception(function() use($object) {
$object->getOpenedClient(new BaseServiceClient());
})
->isInstanceOf('\ZendService\Apple\Exception\InvalidArgumentException')
->message
->contains('Certificate must be a valid path to a APNS certificate')
->when($object = new TestedModel(array('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($object = new \Mock\Apns())
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Model\Device', '\Mock'))
->and($device = new \Mock\Device())
->and($device->getMockController()->getToken = self::APNS_TOKEN_EXAMPLE)
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Model\Message', '\Mock'))
->and($message = new \Mock\Message())
->and($message->getMockController()->getText = 'Test')
->object($object->getServiceMessageFromOrigin($device, $message))
->isInstanceOf('\ZendService\Apple\Apns\Message')
;
}
public function testPush()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->and($this->mockClass('\ZendService\Apple\Apns\Response\Message', '\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\Message', '\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($push = new \Mock\Push())
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(self::APNS_TOKEN_EXAMPLE))))
->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())
->and($object->getMockController()->getOpenedClient = $serviceClient)
->object($object->push($push))
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
->hasSize(1)
;
}
public function testFeedback()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->and($this->mockClass('\ZendService\Apple\Apns\Response\Message', '\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($serviceClient = new \Mock\ZendService\Feedback())
->and($serviceClient->getMockController()->feedback = $serviceResponse)
->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())
->and($object->getMockController()->getOpenedClient = $serviceClient)
->array($object->getFeedback())
->isEmpty()
;
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace tests\units\Sly\NotificationPusher\Adapter;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\PushManager as BasePushManager;
/**
* BaseAdapter.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class BaseAdapter extends Units\Test
{
public function testAdapterKey()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->and($object->getMockController()->getAdapterKey = 'Apns')
->string($object->getAdapterKey())
->isEqualTo('Apns')
->string((string) $object)
->isEqualTo('Apns')
;
}
public function testEnvironment()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($object = new \Mock\Apns())
->when($object->setEnvironment(BasePushManager::ENVIRONMENT_DEV))
->string($object->getEnvironment())
->isEqualTo(BasePushManager::ENVIRONMENT_DEV)
->boolean($object->isDevelopmentEnvironment())
->isTrue()
->boolean($object->isProductionEnvironment())
->isFalse()
->when($object->setEnvironment(BasePushManager::ENVIRONMENT_PROD))
->string($object->getEnvironment())
->isEqualTo(BasePushManager::ENVIRONMENT_PROD)
->boolean($object->isProductionEnvironment())
->isTrue()
->boolean($object->isDevelopmentEnvironment())
->isFalse()
;
}
}

View File

@@ -0,0 +1,148 @@
<?php
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 ZendService\Google\Gcm\Client as BaseServiceClient;
use ZendService\Google\Gcm\Message as BaseServiceMessage;
/**
* Gcm.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class Gcm extends Units\Test
{
const GCM_TOKEN_EXAMPLE = 'AAA91bG9ISdL94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropAcRp4BSxVBBB';
public function testConstruct()
{
$this
->exception(function() {
$object = new TestedModel();
})
->isInstanceOf('\Symfony\Component\OptionsResolver\Exception\MissingOptionsException')
->message
->contains('apiKey')
->when($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->and($object->setParameters(array('apiKey' => 'test')))
->array($object->getParameters())
->isNotEmpty()
->hasSize(1)
->string($object->getParameter('apiKey'))
->isEqualTo('test')
;
}
public function testSupports()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->boolean($object->supports('*()*'))
->isFalse()
->boolean($object->supports(self::GCM_TOKEN_EXAMPLE))
->isTrue()
;
}
public function testDefaultParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->array($defaultParameters = $object->getDefaultParameters())
->isEmpty()
;
}
public function testRequiredParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->array($requiredParameters = $object->getRequiredParameters())
->isNotEmpty()
->contains('apiKey')
;
}
public function testGetOpenedClient()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\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($serviceClient = new \Mock\ZendService\Client())
->and($object->getMockController()->getParameters = array())
->exception(function() use($object) {
$object->getOpenedClient(new BaseServiceClient());
})
->isInstanceOf('\ZendService\Google\Exception\InvalidArgumentException')
->message
->contains('The api key must be a string and not empty')
->when($object = new TestedModel(array('apiKey' => 'test')))
->and($object->getOpenedClient($serviceClient))
;
}
public function testGetServiceMessageFromOrigin()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Model\Message', '\Mock'))
->and($message = new \Mock\Message())
->and($message->getMockController()->getText = 'Test')
->object($object->getServiceMessageFromOrigin(array(self::GCM_TOKEN_EXAMPLE), $message))
->isInstanceOf('\ZendService\Google\Gcm\Message')
;
}
public function testPush()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->and($this->mockClass('\ZendService\Google\Gcm\Response', '\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($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($push = new \Mock\Push())
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(self::GCM_TOKEN_EXAMPLE))))
->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())
->and($object->getMockController()->getOpenedClient = $serviceClient)
->object($object->push($push))
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
->hasSize(1)
;
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Message;
/**
* BaseOptionedModel.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class BaseOptionedModel extends Units\Test
{
public function testMethods()
{
$this->if($object = new Message('Test', array('param' => 'test')))
->boolean($object->hasOption('param'))
->isTrue()
->string($object->getOption('param'))
->isEqualTo('test')
->boolean($object->hasOption('notExist'))
->isFalse()
->variable($object->getOption('notExist'))
->isNull()
->string($object->getOption('renotExist', '12345'))
->isEqualTo('12345')
->when($object->setOptions(array('chuck' => 'norris')))
->boolean($object->hasOption('chuck'))
->isTrue()
->string($object->getOption('chuck'))
->isEqualTo('norris')
->when($object->setOption('poney', 'powerful'))
->boolean($object->hasOption('poney'))
->isTrue()
->string($object->getOption('poney'))
->isEqualTo('powerful')
->when($object->setOption('null', null))
->boolean($object->hasOption('null'))
->isTrue()
->variable($object->getOption('null'))
->isNull()
;
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Device;
/**
* BaseParameteredModel.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class BaseParameteredModel extends Units\Test
{
public function testMethods()
{
$this->if($object = new Device('Test', array('param' => 'test')))
->boolean($object->hasParameter('param'))
->isTrue()
->string($object->getParameter('param'))
->isEqualTo('test')
->boolean($object->hasParameter('notExist'))
->isFalse()
->variable($object->getParameter('notExist'))
->isNull()
->string($object->getParameter('renotExist', '12345'))
->isEqualTo('12345')
->when($object->setParameters(array('chuck' => 'norris')))
->boolean($object->hasParameter('chuck'))
->isTrue()
->string($object->getParameter('chuck'))
->isEqualTo('norris')
->when($object->setParameter('poney', 'powerful'))
->boolean($object->hasParameter('poney'))
->isTrue()
->string($object->getParameter('poney'))
->isEqualTo('powerful')
->when($object->setParameter('null', null))
->boolean($object->hasParameter('null'))
->isTrue()
->variable($object->getParameter('null'))
->isNull()
;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Device as TestedModel;
/**
* Device.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class Device extends Units\Test
{
public function testConstruct()
{
$this->if($object = new TestedModel('t0k3n'))
->string($object->getToken())->isEqualTo('t0k3n')
->array($object->getParameters())->isEmpty()
;
$this->if($object = new TestedModel('t0k3n', array('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)
;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Message as TestedModel;
/**
* Message.
*
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class Message extends Units\Test
{
public function testConstruct()
{
$this->if($object = new TestedModel('Test'))
->string($object->getText())->isEqualTo('Test')
->array($object->getOptions())->isEmpty()
;
$this->if($object = new TestedModel('Test', array('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)
;
}
}

View File

@@ -0,0 +1,165 @@
<?php
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
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';
public function testConstructWithOneDevice()
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDevice('Token1'))
->and($message = new BaseMessage('Test'))
->and($object = new TestedModel($adapter, $devices, $message))
->object($object->getDevices())
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
->integer($object->getDevices()->count())
->isEqualTo(1)
->array($object->getOptions())
->isEmpty()
;
}
public function testConstructWithManyDevicesAndOptions()
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection(array(new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3'))))
->and($message = new BaseMessage('Test'))
->and($object = new TestedModel($adapter, $devices, $message, array('param' => 'test')))
->object($object->getDevices())
->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')
->integer($object->getDevices()->count())
->isEqualTo(3)
->array($object->getOptions())
->hasKey('param')
->contains('test')
->size
->isEqualTo(1)
;
}
public function testStatus()
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection(array(new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3'))))
->and($message = new BaseMessage('Test'))
->and($object = new TestedModel($adapter, $devices, $message))
->string($object->getStatus())
->isEqualTo(TestedModel::STATUS_PENDING)
->boolean($object->isPushed())
->isFalse()
->when($object->pushed())
->and($dt = new \DateTime())
->string($object->getStatus())
->isEqualTo(TestedModel::STATUS_PUSHED)
->boolean($object->isPushed())
->isTrue()
->dateTime($object->getPushedAt())
->isCloneOf($dt)
->when($object->setStatus(TestedModel::STATUS_PENDING))
->string($object->getStatus())
->isEqualTo(TestedModel::STATUS_PENDING)
->boolean($object->isPushed())
->isFalse()
->when($fDt = new \DateTime('2013-01-01'))
->and($object->setPushedAt($fDt))
->dateTime($object->getPushedAt())
->isCloneOf(new \DateTime('2013-01-01'))
;
}
public function testDevicesTokensCheck()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($apnsAdapter = new \mock\Apns())
->and($gcmAdapter = new \mock\Gcm())
->and($badDevice = new BaseDevice('BadToken'))
->and($message = new BaseMessage('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))
;
}
public function testAdapter()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\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($object = new TestedModel($apnsAdapter, $devices, $message))
->object($object->getAdapter())
->isInstanceOf('\Sly\NotificationPusher\Adapter\Apns')
->when($object->setAdapter($gcmAdapter))
->and($object->setDevices(new BaseDeviceCollection(array(new BaseDevice(self::GCM_TOKEN_EXAMPLE)))))
->object($object->getAdapter())
->isInstanceOf('\Sly\NotificationPusher\Adapter\Gcm')
;
}
public function testMessage()
{
$this->if($this->mockClass('\Sly\NotificationPusher\Adapter\AdapterInterface', '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new BaseDeviceCollection(array(new BaseDevice('Token1'), new BaseDevice('Token2'), new BaseDevice('Token3'))))
->and($message = new BaseMessage('Test'))
->and($object = new TestedModel($adapter, $devices, $message))
->object($object->getMessage())
->isInstanceOf('\Sly\NotificationPusher\Model\Message')
->string($object->getMessage()->getText())
->isEqualTo('Test')
->when($object->setMessage(new BaseMessage('Test 2')))
->object($object->getMessage())
->isInstanceOf('\Sly\NotificationPusher\Model\Message')
->string($object->getMessage()->getText())
->isEqualTo('Test 2')
;
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace tests\units\Sly\NotificationPusher;
use mageekguy\atoum as Units;
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>
*/
class PushManager extends Units\Test
{
const APNS_TOKEN_EXAMPLE = '111db24975bb6c6b63214a8d268052aa0a965cc1e32110ab06a72b19074c2222';
public function testConstruct()
{
$this->if($object = new TestedModel())
->string($object->getEnvironment())
->isEqualTo(TestedModel::ENVIRONMENT_DEV)
->when($object = new TestedModel(TestedModel::ENVIRONMENT_PROD))
->string($object->getEnvironment())
->isEqualTo(TestedModel::ENVIRONMENT_PROD)
;
}
public function testCollection()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Model\Push', '\Mock'))
->and($push = new \Mock\Push())
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(self::APNS_TOKEN_EXAMPLE))))
->and($object = new TestedModel())
->when($object->add($push))
->object($object)
->isInstanceOf('\Sly\NotificationPusher\Collection\PushCollection')
->hasSize(1)
;
}
public function testPush()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))
->and($apnsAdapter = new \Mock\Apns())
->and($apnsAdapter->getMockController()->push = true)
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Model\Push', '\Mock'))
->and($push = new \Mock\Push())
->and($push->getMockController()->getMessage = new BaseMessage('Test'))
->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(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)
;
}
}