update tests

This commit is contained in:
KHOUBZA Younes
2020-12-15 15:17:00 +01:00
parent fe0a69b8c5
commit 59da4a3466
16 changed files with 50 additions and 226 deletions
+9 -7
View File
@@ -14,14 +14,11 @@
"require": {
"php": ">=5.3",
"ext-json": "*",
"symfony/config": "^2.7|^3.0|^4.0|^5.0",
"symfony/dependency-injection": "^2.7|^3.0|^4.0|^5.0",
"symfony/http-kernel": "^2.7|^3.0|^4.0|^5.0",
"symfony/yaml": "^2.7|^3.0|^4.0|^5.0",
"twig/twig": "^1.34|^2.0|^3.0"
"illuminate/support": "^4.0|^5.0|^6.0|^7.0|^8.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0|^9.0"
"phpunit/phpunit": "^4.8|^5.0|^6.0|^7.0|^8.0|^9.0",
"orchestra/testbench": "^2.0|^3.0|^4.0|^5.0|^6.0"
},
"autoload": {
"psr-4": {
@@ -31,5 +28,10 @@
"src/Prime/helpers.php"
]
},
"minimum-stability": "dev"
"minimum-stability": "dev",
"config": {
"platform": {
"php": "5.4"
}
}
}
@@ -31,10 +31,15 @@ class FlasherNotyExtensionTest extends TestCase
$flasher = $container->getDefinition('flasher');
$calls = $flasher->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertCount(2, $calls);
$this->assertSame('addFactory', $calls[0][0]);
$this->assertSame('noty', $calls[0][1][0]);
$this->assertSame('flasher.noty', (string) $calls[0][1][1]);
$this->assertSame('template', $calls[0][1][0]);
$this->assertSame('flasher.notification_factory', (string) $calls[0][1][1]);
$this->assertSame('addFactory', $calls[1][0]);
$this->assertSame('noty', $calls[1][1][0]);
$this->assertSame('flasher.noty', (string) $calls[1][1][1]);
}
public function testConfigurationInjectedIntoFlasherConfig()
@@ -31,10 +31,15 @@ class FlasherNotyfExtensionTest extends TestCase
$flasher = $container->getDefinition('flasher');
$calls = $flasher->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertCount(2, $calls);
$this->assertSame('addFactory', $calls[0][0]);
$this->assertSame('notyf', $calls[0][1][0]);
$this->assertSame('flasher.notyf', (string) $calls[0][1][1]);
$this->assertSame('template', $calls[0][1][0]);
$this->assertSame('flasher.notification_factory', (string) $calls[0][1][1]);
$this->assertSame('addFactory', $calls[1][0]);
$this->assertSame('notyf', $calls[1][1][0]);
$this->assertSame('flasher.notyf', (string) $calls[1][1][1]);
}
public function testConfigurationInjectedIntoFlasherConfig()
@@ -31,10 +31,15 @@ class FlasherPnotifyExtensionTest extends TestCase
$flasher = $container->getDefinition('flasher');
$calls = $flasher->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertCount(2, $calls);
$this->assertSame('addFactory', $calls[0][0]);
$this->assertSame('pnotify', $calls[0][1][0]);
$this->assertSame('flasher.pnotify', (string) $calls[0][1][1]);
$this->assertSame('template', $calls[0][1][0]);
$this->assertSame('flasher.notification_factory', (string) $calls[0][1][1]);
$this->assertSame('addFactory', $calls[1][0]);
$this->assertSame('pnotify', $calls[1][1][0]);
$this->assertSame('flasher.pnotify', (string) $calls[1][1][1]);
}
public function testConfigurationInjectedIntoFlasherConfig()
-52
View File
@@ -1,52 +0,0 @@
<?php
namespace Flasher\Prime\Factory;
use Flasher\Prime\Notification\Notification;
use Flasher\Prime\Notification\NotificationBuilder;
use Flasher\Prime\Storage\StorageManagerInterface;
abstract class AbstractFactory implements FactoryInterface
{
/**
* @var StorageManagerInterface
*/
protected $storageManager;
/**
* @param StorageManagerInterface $storageManager
*/
public function __construct(StorageManagerInterface $storageManager)
{
$this->storageManager = $storageManager;
}
/**
* {@inheritdoc}
*/
public function createNotificationBuilder()
{
return new NotificationBuilder($this->getStorageManager(), new Notification(), 'default');
}
/**
* Dynamically call the default driver instance.
*
* @param string $method
* @param array $parameters
*
* @return mixed
*/
public function __call($method, array $parameters)
{
return call_user_func_array(array($this->createNotificationBuilder(), $method), $parameters);
}
/**
* @return StorageManagerInterface
*/
public function getStorageManager()
{
return $this->storageManager;
}
}
-16
View File
@@ -1,16 +0,0 @@
<?php
namespace Flasher\Prime\Factory;
use Flasher\Prime\Notification\NotificationBuilderInterface;
/**
* @mixin NotificationBuilderInterface
*/
interface FactoryInterface
{
/**
* @return NotificationBuilderInterface
*/
public function createNotificationBuilder();
}
@@ -1,14 +0,0 @@
<?php
namespace Flasher\Prime\Renderer\Response;
final class ArrayResponse implements ResponseInterface
{
/**
* @inheritDoc
*/
public function render(array $response, array $context = array())
{
return $response;
}
}
@@ -1,49 +0,0 @@
<?php
namespace Flasher\Prime\Renderer\Response;
final class HtmlResponse implements ResponseInterface
{
/**
* @inheritDoc
*/
public function render(array $response, array $context = array())
{
if (empty($response['notifications'])) {
return '';
}
$scripts = $this->renderScripts($response['scripts'], $context);
$notifications = json_encode($response);
return <<<HTML
{$scripts}
<script type="text/javascript">
if ("undefined" === typeof PHPFlasher) {
alert("[PHPFlasher] not found, please include the '/bundles/flasher/flasher.js' file");
} else {
PHPFlasher.render({$notifications});
}
</script>
HTML;
}
/**
* @param string[] $scripts
* @param array $context
*
* @return string
*/
public function renderScripts($scripts, array $context)
{
$html = '';
foreach ($scripts as $file) {
if (empty($context['content']) || false === strpos($context['content'], $file)) {
$html .= sprintf('<script src="%s"></script>', $file).PHP_EOL;
}
}
return $html;
}
}
@@ -1,14 +0,0 @@
<?php
namespace Flasher\Prime\Renderer\Response;
interface ResponseInterface
{
/**
* @param array $response
* @param array $context
*
* @return mixed
*/
public function render(array $response, array $context = array());
}
@@ -1,37 +0,0 @@
<?php
namespace Flasher\Prime\Renderer\Response;
final class ResponseManager implements ResponseManagerInterface
{
/**
* @var array<string, ResponseInterface>
*/
private $responses;
public function __construct()
{
$this->addResponse('array', new ArrayResponse());
$this->addResponse('html', new HtmlResponse());
}
/**
* @inheritDoc
*/
public function addResponse($alias, ResponseInterface $response)
{
$this->responses[$alias] = $response;
}
/**
* @inheritDoc
*/
public function create($alias)
{
if (!isset($this->responses[$alias])) {
throw new \InvalidArgumentException(sprintf('[%s] response not supported.', $alias));
}
return $this->responses[$alias];
}
}
@@ -1,19 +0,0 @@
<?php
namespace Flasher\Prime\Renderer\Response;
interface ResponseManagerInterface
{
/**
* @param string $alias
* @param ResponseInterface $response
*/
public function addResponse($alias, ResponseInterface $response);
/**
* @param string $alias
*
* @return ResponseInterface
*/
public function create($alias);
}
@@ -31,10 +31,15 @@ class FlasherSweetAlertExtensionTest extends TestCase
$flasher = $container->getDefinition('flasher');
$calls = $flasher->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertCount(2, $calls);
$this->assertSame('addFactory', $calls[0][0]);
$this->assertSame('sweet_alert', $calls[0][1][0]);
$this->assertSame('flasher.sweet_alert', (string) $calls[0][1][1]);
$this->assertSame('template', $calls[0][1][0]);
$this->assertSame('flasher.notification_factory', (string) $calls[0][1][1]);
$this->assertSame('addFactory', $calls[1][0]);
$this->assertSame('sweet_alert', $calls[1][1][0]);
$this->assertSame('flasher.sweet_alert', (string) $calls[1][1][1]);
}
public function testConfigurationInjectedIntoFlasherConfig()
@@ -22,7 +22,7 @@ class EventSubscriberCompilerPassTest extends TestCase
$manager = $container->getDefinition('flasher.event_dispatcher');
$calls = $manager->getMethodCalls();
$this->assertCount(4, $calls);
$this->assertCount(5, $calls);
$this->assertEquals('addSubscriber', $calls[0][0]);
$this->assertEquals('test_subscriber', $calls[0][1][0]);
@@ -22,7 +22,7 @@ class FactoryCompilerPassTest extends TestCase
$manager = $container->getDefinition('flasher');
$calls = $manager->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertCount(2, $calls);
$this->assertEquals('addFactory', $calls[0][0]);
$this->assertEquals('test_flasher', $calls[0][1][0]);
}
@@ -13,7 +13,6 @@ class ConfigurationTest extends TestCase
$config = $this->process(array());
$expected = array(
'default' => 'toastr',
'scripts' => array(
'/bundles/flasher/flasher.js',
),
@@ -31,10 +31,14 @@ class FlasherToastrExtensionTest extends TestCase
$flasher = $container->getDefinition('flasher');
$calls = $flasher->getMethodCalls();
$this->assertCount(1, $calls);
$this->assertCount(2, $calls);
$this->assertSame('addFactory', $calls[0][0]);
$this->assertSame('toastr', $calls[0][1][0]);
$this->assertSame('flasher.toastr', (string) $calls[0][1][1]);
$this->assertSame('template', $calls[0][1][0]);
$this->assertSame('flasher.notification_factory', (string) $calls[0][1][1]);
$this->assertSame('addFactory', $calls[1][0]);
$this->assertSame('toastr', $calls[1][1][0]);
$this->assertSame('flasher.toastr', (string) $calls[1][1][1]);
}
public function testConfigurationInjectedIntoFlasherConfig()