You've already forked php-flasher
mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-04-05 12:32:55 +01:00
Prepare v1.0 release
rename template adapter to flasher, and add title to base notification class Wip
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Tests\Laravel\Config;
|
||||
|
||||
use Flasher\Laravel\Config\Config;
|
||||
use Flasher\Tests\Laravel\TestCase;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
final class ConfigTest extends TestCase
|
||||
{
|
||||
public function testSimpleConfig()
|
||||
{
|
||||
$separator = $this->isLaravel4() ? '::' : '.';
|
||||
$config = new Config($this->app->make('config'), $separator);
|
||||
|
||||
$this->assertEquals('template', $config->get('default'));
|
||||
}
|
||||
|
||||
private function isLaravel4()
|
||||
{
|
||||
return 0 === strpos(Application::VERSION, '4.');
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Tests\Laravel;
|
||||
|
||||
use Illuminate\View\Compilers\BladeCompiler;
|
||||
|
||||
final class FlasherServiceProviderTest extends TestCase
|
||||
{
|
||||
public function testNotifyServiceExists()
|
||||
{
|
||||
$this->assertInstanceOf('Flasher\Laravel\Config\Config', $this->app->make('flasher.config'));
|
||||
$this->assertInstanceOf('Flasher\Prime\Flasher', $this->app->make('flasher'));
|
||||
$this->assertInstanceOf('Flasher\Prime\Response\ResponseManager', $this->app->make('flasher.response_manager'));
|
||||
$this->assertInstanceOf(
|
||||
'Flasher\Prime\Response\Resource\ResourceManager',
|
||||
$this->app->make('flasher.resource_manager')
|
||||
);
|
||||
$this->assertInstanceOf('Flasher\Laravel\Storage\Storage', $this->app->make('flasher.storage'));
|
||||
$this->assertInstanceOf('Flasher\Prime\Storage\StorageManager', $this->app->make('flasher.storage_manager'));
|
||||
$this->assertInstanceOf(
|
||||
'Flasher\Prime\EventDispatcher\EventDispatcher',
|
||||
$this->app->make('flasher.event_dispatcher')
|
||||
);
|
||||
$this->assertInstanceOf('Flasher\Prime\Filter\Filter', $this->app->make('flasher.filter'));
|
||||
}
|
||||
|
||||
public function testBladeDirective()
|
||||
{
|
||||
/** @var BladeCompiler $blade */
|
||||
$blade = $this->app->make('view')->getEngineResolver()->resolve('blade')->getCompiler();
|
||||
|
||||
$this->assertEquals(
|
||||
"<?php echo app('flasher.response_manager')->render(); ?>",
|
||||
$blade->compileString('@flasher_render()')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"<?php echo app('flasher.response_manager')->render(array()); ?>",
|
||||
$blade->compileString('@flasher_render(array())')
|
||||
);
|
||||
$this->assertEquals(
|
||||
"<?php echo app('flasher.response_manager')->render(array(\"priority\" => array(\"min\" => 4, \"max\" => 5))); ?>",
|
||||
$blade->compileString('@flasher_render(array("priority" => array("min" => 4, "max" => 5)))')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the PHPFlasher package.
|
||||
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Flasher\Tests\Laravel;
|
||||
|
||||
class ServiceProviderTest extends TestCase
|
||||
{
|
||||
public function testContainerContainServices()
|
||||
{
|
||||
$this->assertTrue($this->app->bound('flasher'));
|
||||
$this->assertTrue($this->app->bound('flasher.noty'));
|
||||
$this->assertTrue($this->app->bound('flasher.notyf'));
|
||||
$this->assertTrue($this->app->bound('flasher.pnotify'));
|
||||
$this->assertTrue($this->app->bound('flasher.sweetalert'));
|
||||
$this->assertTrue($this->app->bound('flasher.toastr'));
|
||||
|
||||
$this->assertInstanceOf('Flasher\Noty\Prime\NotyFactory', $this->app->make('flasher.noty'));
|
||||
$this->assertInstanceOf('Flasher\Notyf\Prime\NotyfFactory', $this->app->make('flasher.notyf'));
|
||||
$this->assertInstanceOf('Flasher\Pnotify\Prime\PnotifyFactory', $this->app->make('flasher.pnotify'));
|
||||
$this->assertInstanceOf('Flasher\SweetAlert\Prime\SweetAlertFactory', $this->app->make('flasher.sweetalert'));
|
||||
$this->assertInstanceOf('Flasher\Toastr\Prime\ToastrFactory', $this->app->make('flasher.toastr'));
|
||||
}
|
||||
|
||||
public function testFlasherCanCreateServicesFromAlias()
|
||||
{
|
||||
$flasher = $this->app->make('flasher');
|
||||
|
||||
$adapter = $flasher->create('noty');
|
||||
$this->assertInstanceOf('Flasher\Noty\Prime\NotyFactory', $adapter);
|
||||
|
||||
$adapter = $flasher->create('notyf');
|
||||
$this->assertInstanceOf('Flasher\Notyf\Prime\NotyfFactory', $adapter);
|
||||
|
||||
$adapter = $flasher->create('pnotify');
|
||||
$this->assertInstanceOf('Flasher\Pnotify\Prime\PnotifyFactory', $adapter);
|
||||
|
||||
$adapter = $flasher->create('sweetalert');
|
||||
$this->assertInstanceOf('Flasher\SweetAlert\Prime\SweetAlertFactory', $adapter);
|
||||
|
||||
$adapter = $flasher->create('toastr');
|
||||
$this->assertInstanceOf('Flasher\Toastr\Prime\ToastrFactory', $adapter);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Flasher\Tests\Laravel\Storage;
|
||||
/*
|
||||
* This file is part of the PHPFlasher package.
|
||||
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
|
||||
*/
|
||||
|
||||
use Flasher\Laravel\Storage\Storage;
|
||||
use Flasher\Tests\Laravel\TestCase;
|
||||
use Flasher\Prime\Envelope;
|
||||
namespace Flasher\Tests\Laravel;
|
||||
|
||||
use Flasher\Laravel\Storage\SessionBag;
|
||||
use Flasher\Prime\Notification\Envelope;
|
||||
use Flasher\Prime\Notification\Notification;
|
||||
use Flasher\Prime\Stamp\PriorityStamp;
|
||||
use Flasher\Prime\Stamp\UuidStamp;
|
||||
use Flasher\Prime\Storage\StorageBag;
|
||||
|
||||
final class StorageTest extends TestCase
|
||||
{
|
||||
public function testInitialState()
|
||||
{
|
||||
$storage = new Storage($this->app->make('session'));
|
||||
$storage = $this->getStorage();
|
||||
$this->assertEquals(array(), $storage->all());
|
||||
}
|
||||
|
||||
public function testAddEnvelope()
|
||||
{
|
||||
$storage = new Storage($this->app->make('session'));
|
||||
$storage = $this->getStorage();
|
||||
$envelope = new Envelope(new Notification());
|
||||
$storage->add($envelope);
|
||||
|
||||
$this->assertEquals(array($envelope), $storage->all());
|
||||
$this->assertEquals(UuidStamp::indexByUuid($envelope), $storage->all());
|
||||
}
|
||||
|
||||
public function testAddMultipleEnvelopes()
|
||||
{
|
||||
$storage = new Storage($this->app->make('session'));
|
||||
$storage = $this->getStorage();
|
||||
$envelopes = array(
|
||||
new Envelope(new Notification()),
|
||||
new Envelope(new Notification()),
|
||||
);
|
||||
|
||||
$storage->add($envelopes);
|
||||
$this->assertEquals($envelopes, $storage->all());
|
||||
$this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all());
|
||||
}
|
||||
|
||||
public function testUpdateEnvelopes()
|
||||
{
|
||||
$storage = new Storage($this->app->make('session'));
|
||||
$storage = $this->getStorage();
|
||||
$envelopes = array(
|
||||
new Envelope(new Notification(), array(
|
||||
new UuidStamp(),
|
||||
@@ -51,12 +56,12 @@ final class StorageTest extends TestCase
|
||||
);
|
||||
|
||||
$storage->add($envelopes);
|
||||
$this->assertEquals($envelopes, $storage->all());
|
||||
$this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all());
|
||||
|
||||
$envelopes[1]->withStamp(new PriorityStamp(1));
|
||||
$storage->update($envelopes[1]);
|
||||
|
||||
$this->assertEquals($envelopes, $storage->all());
|
||||
$this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all());
|
||||
$this->assertInstanceOf(
|
||||
'Flasher\Prime\Stamp\PriorityStamp',
|
||||
$envelopes[1]->get('Flasher\Prime\Stamp\PriorityStamp')
|
||||
@@ -65,7 +70,7 @@ final class StorageTest extends TestCase
|
||||
|
||||
public function testRemoveEnvelopes()
|
||||
{
|
||||
$storage = new Storage($this->app->make('session'));
|
||||
$storage = $this->getStorage();
|
||||
$envelopes = array(
|
||||
new Envelope(new Notification(), array(
|
||||
new UuidStamp(),
|
||||
@@ -76,15 +81,15 @@ final class StorageTest extends TestCase
|
||||
);
|
||||
|
||||
$storage->add($envelopes);
|
||||
$this->assertEquals($envelopes, $storage->all());
|
||||
$this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all());
|
||||
|
||||
$storage->remove($envelopes[1]);
|
||||
$this->assertEquals(array($envelopes[0]), $storage->all());
|
||||
$this->assertEquals(UuidStamp::indexByUuid($envelopes[0]), $storage->all());
|
||||
}
|
||||
|
||||
public function testRemoveMultipleEnvelopes()
|
||||
{
|
||||
$storage = new Storage($this->app->make('session'));
|
||||
$storage = $this->getStorage();
|
||||
$envelopes = array(
|
||||
new Envelope(new Notification(), array(
|
||||
new UuidStamp(),
|
||||
@@ -95,7 +100,7 @@ final class StorageTest extends TestCase
|
||||
);
|
||||
|
||||
$storage->add($envelopes);
|
||||
$this->assertEquals($envelopes, $storage->all());
|
||||
$this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all());
|
||||
|
||||
$storage->remove($envelopes);
|
||||
$this->assertEquals(array(), $storage->all());
|
||||
@@ -103,7 +108,7 @@ final class StorageTest extends TestCase
|
||||
|
||||
public function testClearAllEnvelopes()
|
||||
{
|
||||
$storage = new Storage($this->app->make('session'));
|
||||
$storage = $this->getStorage();
|
||||
$envelopes = array(
|
||||
new Envelope(new Notification(), array(
|
||||
new UuidStamp(),
|
||||
@@ -114,9 +119,14 @@ final class StorageTest extends TestCase
|
||||
);
|
||||
|
||||
$storage->add($envelopes);
|
||||
$this->assertEquals($envelopes, $storage->all());
|
||||
$this->assertEquals(UuidStamp::indexByUuid($envelopes), $storage->all());
|
||||
|
||||
$storage->clear();
|
||||
$this->assertEquals(array(), $storage->all());
|
||||
}
|
||||
|
||||
private function getStorage()
|
||||
{
|
||||
return new StorageBag(new SessionBag($this->app->make('session')));
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the PHPFlasher package.
|
||||
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Flasher\Tests\Laravel;
|
||||
|
||||
use Illuminate\Config\Repository as Config;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Orchestra\Testbench\TestCase as Orchestra;
|
||||
|
||||
class TestCase extends Orchestra
|
||||
{
|
||||
public function createApplication()
|
||||
{
|
||||
if (0 !== strpos(Application::VERSION, '4.0')) {
|
||||
return parent::createApplication();
|
||||
}
|
||||
|
||||
$app = new Application();
|
||||
|
||||
$app->detectEnvironment(array(
|
||||
'local' => array('your-machine-name'),
|
||||
));
|
||||
|
||||
$app->bindInstallPaths($this->getApplicationPaths());
|
||||
|
||||
$app['env'] = 'testing';
|
||||
|
||||
$app->instance('app', $app);
|
||||
|
||||
Facade::clearResolvedInstances();
|
||||
Facade::setFacadeApplication($app);
|
||||
|
||||
$config = new Config($app->getConfigLoader(), $app['env']);
|
||||
$app->instance('config', $config);
|
||||
$app->startExceptionHandling();
|
||||
|
||||
if ($app->runningInConsole()) {
|
||||
$app->setRequestForConsoleEnvironment();
|
||||
}
|
||||
|
||||
date_default_timezone_set($this->getApplicationTimezone());
|
||||
|
||||
$aliases = array_merge($this->getApplicationAliases(), $this->getPackageAliases());
|
||||
AliasLoader::getInstance($aliases)->register();
|
||||
|
||||
Request::enableHttpMethodParameterOverride();
|
||||
|
||||
$providers = array_merge($this->getApplicationProviders(), $this->getPackageProviders());
|
||||
$app->getProviderRepository()->load($app, $providers);
|
||||
|
||||
$this->getEnvironmentSetUp($app);
|
||||
|
||||
$app->boot();
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $app
|
||||
*
|
||||
@@ -16,6 +71,11 @@ class TestCase extends Orchestra
|
||||
{
|
||||
return array(
|
||||
'Flasher\Laravel\FlasherServiceProvider',
|
||||
'Flasher\Noty\Laravel\FlasherNotyServiceProvider',
|
||||
'Flasher\Notyf\Laravel\FlasherNotyfServiceProvider',
|
||||
'Flasher\Pnotify\Laravel\FlasherPnotifyServiceProvider',
|
||||
'Flasher\SweetAlert\Laravel\FlasherSweetAlertServiceProvider',
|
||||
'Flasher\Toastr\Laravel\FlasherToastrServiceProvider',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,6 +84,14 @@ class TestCase extends Orchestra
|
||||
*/
|
||||
protected function getEnvironmentSetUp($app)
|
||||
{
|
||||
$separator = $this->isLaravel4() ? '::config' : '';
|
||||
|
||||
$app['config']->set('session.driver', 'array');
|
||||
$app['config']->set('session'.$separator.'.driver', 'array');
|
||||
}
|
||||
|
||||
private function isLaravel4()
|
||||
{
|
||||
return 0 === strpos(Application::VERSION, '4.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user