Merge pull request #134 from php-flasher/test/storage-manager

Test/storage manager
This commit is contained in:
Younes KHOUBZA
2023-02-01 23:07:07 +01:00
committed by GitHub
4 changed files with 206 additions and 1 deletions
@@ -8,7 +8,7 @@
namespace Flasher\Tests\Prime\Factory;
use Flasher\Prime\Factory\NotificationFactory;
use PHPUnit\Framework\TestCase;
use Flasher\Tests\Prime\TestCase;
class NotificationFactoryTest extends TestCase
{
+138
View File
@@ -0,0 +1,138 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\Storage;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Prime\Stamp\DelayStamp;
use Flasher\Prime\Stamp\HopsStamp;
use Flasher\Prime\Stamp\UuidStamp;
use Flasher\Prime\Storage\StorageManager;
use Flasher\Tests\Prime\TestCase;
class StorageManagerTest extends TestCase
{
/**
* @return void
*/
public function testGetAllStoredEnvelopes()
{
$envelopes = array(
new Envelope(new Notification(), new UuidStamp('1111')),
new Envelope(new Notification(), new UuidStamp('2222')),
new Envelope(new Notification(), new UuidStamp('3333')),
new Envelope(new Notification(), new UuidStamp('4444')),
);
$storage = $this->getMockBuilder('Flasher\Prime\Storage\StorageInterface')->getMock();
$storage->expects($this->once())->method('all')->willReturn($envelopes);
$storageManager = new StorageManager($storage);
$this->assertEquals($envelopes, $storageManager->all());
}
/**
* @return void
*/
public function testGetFilteredEnvelopes()
{
$envelopes = array(
new Envelope(new Notification(), new UuidStamp('1111')),
new Envelope(new Notification(), new UuidStamp('2222'), new HopsStamp(1), new DelayStamp(0)),
new Envelope(new Notification(), new UuidStamp('3333')),
new Envelope(new Notification(), new UuidStamp('4444')),
);
$storage = $this->getMockBuilder('Flasher\Prime\Storage\StorageInterface')->getMock();
$storage->expects($this->once())->method('all')->willReturn($envelopes);
$storageManager = new StorageManager($storage);
$this->assertEquals(array($envelopes[1]), $storageManager->filter());
}
/**
* @return void
*/
public function testAddEnvelopes()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$storageManager = new StorageManager();
$storageManager->add($envelopes);
$this->assertEquals($envelopes, $storageManager->all());
}
/**
* @return void
*/
public function testUpdateEnvelopes()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$storageManager = new StorageManager();
$storageManager->update($envelopes);
$this->assertEquals($envelopes, $storageManager->all());
}
/**
* @return void
*/
public function testRemoveEnvelopes()
{
$envelopes = array(
new Envelope(new Notification(), new UuidStamp('1111')),
new Envelope(new Notification(), new UuidStamp('2222')),
new Envelope(new Notification(), new UuidStamp('3333')),
new Envelope(new Notification(), new UuidStamp('4444')),
);
$storageManager = new StorageManager();
$storageManager->add($envelopes);
$storageManager->remove(array(
new Envelope(new Notification(), new UuidStamp('2222')),
new Envelope(new Notification(), new UuidStamp('3333')),
));
$this->assertEquals(array($envelopes[0], $envelopes[3]), $storageManager->all());
}
/**
* @return void
*/
public function testClearEnvelopes()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$storageManager = new StorageManager();
$storageManager->add($envelopes);
$storageManager->clear();
$this->assertEquals(array(), $storageManager->all());
}
}
@@ -0,0 +1,25 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\Translation;
use Flasher\Prime\Translation\EchoTranslator;
use Flasher\Tests\Prime\TestCase;
class EchoTranslatorTest extends TestCase
{
/**
* @return void
*/
public function testEchoTranslator()
{
$translator = new EchoTranslator();
$this->assertEquals('en', $translator->getLocale());
$this->assertEquals('PHPFlasher', $translator->translate('PHPFlasher'));
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\Translation;
use Flasher\Prime\Translation\Language;
use Flasher\Tests\Prime\TestCase;
class LanguageTest extends TestCase
{
/**
* @return void
*/
public function testLanguageDirection()
{
$this->assertEquals(Language::RTL, Language::direction('ar'));
$this->assertEquals(Language::LTR, Language::direction('fr'));
$this->assertEquals(Language::LTR, Language::direction('unknown'));
}
/**
* @return void
*/
public function testIsRTL()
{
$this->assertTrue(Language::isRTL('ar_AE'));
$this->assertFalse(Language::isRTL('en_US'));
}
/**
* @return void
*/
public function testIsLTR()
{
$this->assertTrue(Language::isLTR('en_US'));
$this->assertFalse(Language::isLTR('ar_AE'));
}
}