laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

View File

@@ -1,195 +0,0 @@
<?php
namespace tests\units\Sly\NotificationPusher\Adapter;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Adapter\Apns as TestedModel;
use Sly\NotificationPusher\Collection\DeviceCollection;
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 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;
/**
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class Apns extends Units\Test
{
const APNS_TOKEN_EXAMPLE_64 = '111db24975bb6c6b63214a8d268052aa0a965cc1e32110ab06a72b19074c2222';
const APNS_TOKEN_EXAMPLE_65 = '111db24975bb6c6b63214a8d268052aa0a965cc1e32110ab06a72b19074c22225';
public function testConstruct()
{
$this
->exception(static function () {
$object = new TestedModel();
})
->isInstanceOf(MissingOptionsException::class)
->message
->contains('certificate')
->exception(static function () {
$object = new TestedModel(['certificate' => 'absent.pem']);
})
->isInstanceOf(AdapterException::class)
->message
->contains('does not exist')
->when($this->mockGenerator()->orphanize('__construct'))
->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)
->string($object->getParameter('certificate'))
->isEqualTo('test.pem');
}
public function testSupports()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(TestedModel::class, '\Mock'))
->and($object = new \Mock\Apns())
->boolean($object->supports('wrongToken'))
->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(TestedModel::class, '\Mock'))
->and($object = new \Mock\Apns())
->array($defaultParameters = $object->getDefinedParameters())
->isEmpty();
}
public function testDefaultParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(TestedModel::class, '\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(TestedModel::class, '\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(TestedModel::class, '\Mock'))
->and($object = new \Mock\Apns())
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockGenerator()->orphanize('open'))
->and($this->mockClass(ZendClientMessage::class, '\Mock\ZendService'))
->and($serviceClient = new \Mock\ZendService\Message())
->and($object->getMockController()->getParameters = [])
->exception(static function () use ($object) {
$object->getOpenedClient(new ZendClientMessage());
})
->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(TestedModel::class, '\Mock'))
->and($object = new \Mock\Apns())
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(Device::class, '\Mock'))
->and($device = new \Mock\Device())
->and($device->getMockController()->getToken = self::APNS_TOKEN_EXAMPLE_64)
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(Message::class, '\Mock'))
->and($message = new \Mock\Message())
->and($message->getMockController()->getText = 'Test')
->object($object->getServiceMessageFromOrigin($device, $message))
->isInstanceOf(ZendServiceMessage::class);
}
public function testPush()
{
$this->if($this->mockGenerator()->orphanize('__construct')
->makeVisible('getOpenedServiceClient')
->generate(TestedModel::class, '\Mock', 'Apns'))
->and($object = new \Mock\Apns())
->and($object->setResponse(new Response()))
->and($this->mockClass(ZendResponseMessage::class, '\Mock\ZendService', 'Response'))
->and($serviceResponse = new \Mock\ZendService\Response())
->and($serviceResponse->getMockController()->getCode = ZendResponseMessage::RESULT_OK)
->and($serviceResponse->getMockController()->getId = 0)
->and($this->mockGenerator()->orphanize('__construct')
->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(Push::class, '\Mock'))
->and($push = new \Mock\Push())
->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 ZendServiceMessage())
->and($object->getMockController()->getOpenedClient = $serviceClient)
->and($this->calling($object)->getOpenedServiceClient = $serviceClient)
->object($result = $object->push($push))
->isInstanceOf(DeviceCollection::class)
->boolean($result->count() == 1)
->isTrue();
}
public function testCountIsEmpty()
{
$this->if($dcoll = new DeviceCollection())
->boolean($dcoll->isEmpty())
->isTrue();
}
public function testFeedback()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(TestedModel::class, '\Mock'))
->and($object = new \Mock\Apns())
->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(Feedback::class, '\Mock\ZendService'))
->and($serviceClient = new \Mock\ZendService\Feedback())
->and($serviceClient->getMockController()->feedback = $serviceResponse)
->and($object->getMockController()->getServiceMessageFromOrigin = new ZendServiceMessage())
->and($object->getMockController()->getOpenedClient = $serviceClient)
->array($object->getFeedback())
->isEmpty();
}
}

View File

@@ -1,46 +0,0 @@
<?php
namespace tests\units\Sly\NotificationPusher\Adapter;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\PushManager;
/**
* @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::class, '\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::class, '\Mock'))
->and($object = new \Mock\Apns())
->when($object->setEnvironment(PushManager::ENVIRONMENT_DEV))
->string($object->getEnvironment())
->isEqualTo(PushManager::ENVIRONMENT_DEV)
->boolean($object->isDevelopmentEnvironment())
->isTrue()
->boolean($object->isProductionEnvironment())
->isFalse()
->when($object->setEnvironment(PushManager::ENVIRONMENT_PROD))
->string($object->getEnvironment())
->isEqualTo(PushManager::ENVIRONMENT_PROD)
->boolean($object->isProductionEnvironment())
->isTrue()
->boolean($object->isDevelopmentEnvironment())
->isFalse();
}
}

View File

@@ -1,191 +0,0 @@
<?php
namespace tests\units\Sly\NotificationPusher\Adapter;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Adapter\Gcm as TestedModel;
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 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;
/**
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class Gcm extends Units\Test
{
const GCM_TOKEN_EXAMPLE = 'AAA91bG9ISdL94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropAcRp4BSxVBBB';
// The format of GCM tokens apparently have changed, this string looks similar to new format:
const ALT_GCM_TOKEN_EXAMPLE = 'AAA91bG9ISd:L94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropA';
public function testConstruct()
{
$this
->exception(function () {
$object = new TestedModel();
})
->isInstanceOf(MissingOptionsException::class)
->message
->contains('apiKey')
->when($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(TestedModel::class, '\Mock'))
->and($object = new \Mock\Gcm())
->and($object->setParameters(['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(TestedModel::class, '\Mock'))
->and($object = new \Mock\Gcm())
->boolean($object->supports('')) // Test empty string
->isFalse()
->boolean($object->supports(2)) // Test a number
->isFalse()
->boolean($object->supports([])) // Test an array
->isFalse()
->boolean($object->supports(json_decode('{}'))) // Tests an object
->isFalse()
->boolean($object->supports(self::GCM_TOKEN_EXAMPLE))
->isTrue()
->boolean($object->supports(self::ALT_GCM_TOKEN_EXAMPLE))
->isTrue();
}
public function testDefinedParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(TestedModel::class, '\Mock'))
->and($object = new \Mock\Gcm())
->array($definedParameters = $object->getDefinedParameters())
->isNotEmpty()
->containsValues([
'collapseKey',
'delayWhileIdle',
'ttl',
'restrictedPackageName',
'dryRun',
]);
}
public function testDefaultParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(TestedModel::class, '\Mock'))
->and($object = new \Mock\Gcm())
->array($defaultParameters = $object->getDefaultParameters())
->isEmpty();
}
public function testRequiredParameters()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(TestedModel::class, '\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(TestedModel::class, '\Mock'))
->and($object = new \Mock\Gcm())
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockGenerator()->orphanize('open'))
->and($this->mockClass(ZendServiceClient::class, '\Mock\ZendService'))
->and($serviceClient = new \Mock\ZendService\Client())
->and($object->getMockController()->getParameters = [])
->exception(function () use ($object) {
$object->getOpenedClient(new ZendServiceClient());
})
->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));
}
public function testGetServiceMessageFromOrigin()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(TestedModel::class, '\Mock'))
->and($object = new \Mock\Gcm())
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(Message::class, '\Mock'))
->and($message = new \Mock\Message())
->and($message->getMockController()->getOptions = [
'param' => 'test',
'notificationData' => ['some' => 'foobar'],
])
->and($message->getMockController()->getText = 'Test')
->object($originalMessage = $object->getServiceMessageFromOrigin([self::GCM_TOKEN_EXAMPLE], $message))
->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(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',
])
->and($message->getMockController()->getText = 'Test')
->object($originalMessage = $object->getServiceMessageFromOrigin([self::GCM_TOKEN_EXAMPLE], $message))
->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(TestedModel::class, '\Mock'))
->and($object = new \Mock\Gcm())
->and($object->setResponse(new Response()))
->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(ZendServiceClient::class, '\Mock\ZendService'))
->and($serviceClient = new \Mock\ZendService\Message())
->and($serviceClient->getMockController()->send = new $serviceResponse)
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(Push::class, '\Mock'))
->and($push = new \Mock\Push())
->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(DeviceCollection::class)
->hasSize(1);
}
}

View File

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

@@ -1,43 +0,0 @@
<?php
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Device;
/**
* @uses atoum\test
* @author Cédric Dugat <cedric@dugat.me>
*/
class BaseParameteredModel extends Units\Test
{
public function testMethods()
{
$this->if($object = new Device('Test', ['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(['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

@@ -1,30 +0,0 @@
<?php
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Device as TestedModel;
/**
* @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', ['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

@@ -1,32 +0,0 @@
<?php
namespace tests\units\Sly\NotificationPusher\Model;
use mageekguy\atoum as Units;
use Sly\NotificationPusher\Model\Message as TestedModel;
/**
* @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', [
'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

@@ -1,146 +0,0 @@
<?php
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;
/**
* @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(AdapterInterface::class, '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->and($devices = new DeviceModel('Token1'))
->and($message = new MessageModel('Test'))
->and($object = new TestedModel($adapter, $devices, $message))
->object($object->getDevices())
->isInstanceOf(DeviceCollection::class)
->integer($object->getDevices()->count())
->isEqualTo(1)
->array($object->getOptions())
->isEmpty();
}
public function testConstructWithManyDevicesAndOptions()
{
$this->if($this->mockClass(AdapterInterface::class, '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->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(DeviceCollection::class)
->integer($object->getDevices()->count())
->isEqualTo(3)
->array($object->getOptions())
->hasKey('param')
->contains('test')
->size
->isEqualTo(1);
}
public function testStatus()
{
date_default_timezone_set('UTC');
$this->if($this->mockClass(AdapterInterface::class, '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->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)
->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())
->hasDate($dt->format("Y"), $dt->format("m"), $dt->format('d'))
->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())
->isIdenticalTo($fDt);
}
public function testDevicesTokensCheck()
{
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(Apns::class, '\Mock'))
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(Gcm::class, '\Mock'))
->and($apnsAdapter = new \mock\Apns())
->and($gcmAdapter = new \mock\Gcm())
->and($badDevice = new DeviceModel('BadToken'))
->and($message = new MessageModel('Test'))
->exception(function () use ($apnsAdapter, $badDevice, $message) {
$object = new TestedModel($apnsAdapter, $badDevice, $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(Apns::class, '\Mock'))
->and($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass(Gcm::class, '\Mock'))
->and($apnsAdapter = new \mock\Apns())
->and($gcmAdapter = new \mock\Gcm())
->and($devices = new DeviceModel(self::APNS_TOKEN_EXAMPLE))
->and($message = new MessageModel('Test'))
->and($object = new TestedModel($apnsAdapter, $devices, $message))
->object($object->getAdapter())
->isInstanceOf(Apns::class)
->when($object->setAdapter($gcmAdapter))
->and($object->setDevices(new DeviceCollection([new DeviceModel(self::GCM_TOKEN_EXAMPLE)])))
->object($object->getAdapter())
->isInstanceOf(Gcm::class);
}
public function testMessage()
{
$this->if($this->mockClass(AdapterInterface::class, '\Mock'))
->and($adapter = new \Mock\AdapterInterface())
->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(MessageModel::class)
->string($object->getMessage()->getText())
->isEqualTo('Test')
->when($object->setMessage(new MessageModel('Test 2')))
->object($object->getMessage())
->isInstanceOf(MessageModel::class)
->string($object->getMessage()->getText())
->isEqualTo('Test 2');
}
}

View File

@@ -1,82 +0,0 @@
<?php
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;
/**
* @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(Push::class, '\Mock'))
->and($push = new \Mock\Push())
->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 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(PushCollection::class)
->object($object->getIterator())
->hasSize(1)
->when($object->add($push2))
->object($object)
->isInstanceOf(PushCollection::class)
->object($object->getIterator())
->hasSize(2)
->object($object->first())
->isEqualTo($push)
->object($object->last())
->isEqualTo($push2);
}
public function testPush()
{
date_default_timezone_set('UTC');
$this->if($this->mockGenerator()->orphanize('__construct'))
->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(Push::class, '\Mock'))
->and($push = new \Mock\Push())
->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(PushCollection::class)
->hasSize(1)
->object($object->getResponse())
->isInstanceOf(Response::class);
}
}