Merge pull request #129 from php-flasher/test/events

test: add events tests
This commit is contained in:
Younes KHOUBZA
2023-01-31 01:52:20 +01:00
committed by GitHub
9 changed files with 330 additions and 0 deletions
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\FilterEvent;
use Flasher\Prime\Filter\Filter;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Tests\Prime\TestCase;
class FilterEventTest extends TestCase
{
/**
* @return void
*/
public function testFilterEvent()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$event = new FilterEvent($envelopes, array('limit' => 2));
$this->assertInstanceOf('Flasher\Prime\Filter\Filter', $event->getFilter());
$this->assertEquals(array($envelopes[0], $envelopes[1]), $event->getEnvelopes());
$filter = new Filter($envelopes, array());
$event->setFilter($filter);
$this->assertEquals($envelopes, $event->getEnvelopes());
}
}
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\PersistEvent;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Tests\Prime\TestCase;
class PersistEventTest extends TestCase
{
/**
* @return void
*/
public function testPersistEvent()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$event = new PersistEvent($envelopes);
$this->assertEquals($envelopes, $event->getEnvelopes());
$envelopes = array(
new Envelope(new Notification()),
);
$event->setEnvelopes($envelopes);
$this->assertEquals($envelopes, $event->getEnvelopes());
}
}
@@ -0,0 +1,33 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\PostPersistEvent;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Tests\Prime\TestCase;
class PostPersistEventTest extends TestCase
{
/**
* @return void
*/
public function testPostPersistEvent()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$event = new PostPersistEvent($envelopes);
$this->assertEquals($envelopes, $event->getEnvelopes());
}
}
@@ -0,0 +1,37 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\PostRemoveEvent;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Tests\Prime\TestCase;
class PostRemoveEventTest extends TestCase
{
/**
* @return void
*/
public function testPostRemoveEvent()
{
$envelopesToRemove = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$envelopesToKeep = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$event = new PostRemoveEvent($envelopesToRemove, $envelopesToKeep);
$this->assertEquals($envelopesToRemove, $event->getEnvelopesToRemove());
$this->assertEquals($envelopesToKeep, $event->getEnvelopesToKeep());
}
}
@@ -0,0 +1,33 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\PostUpdateEvent;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Tests\Prime\TestCase;
class PostUpdateEventTest extends TestCase
{
/**
* @return void
*/
public function testPostUpdateEvent()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$event = new PostUpdateEvent($envelopes);
$this->assertEquals($envelopes, $event->getEnvelopes());
}
}
@@ -0,0 +1,38 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\PresentationEvent;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Tests\Prime\TestCase;
class PresentationEventTest extends TestCase
{
/**
* @return void
*/
public function testPresentationEvent()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$context = array(
'livewire' => true,
);
$event = new PresentationEvent($envelopes, $context);
$this->assertEquals($envelopes, $event->getEnvelopes());
$this->assertEquals($context, $event->getContext());
}
}
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\RemoveEvent;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Tests\Prime\TestCase;
class RemoveEventTest extends TestCase
{
/**
* @return void
*/
public function testRemoveEvent()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$event = new RemoveEvent($envelopes);
$this->assertEquals($envelopes, $event->getEnvelopesToRemove());
$this->assertEquals(array(), $event->getEnvelopesToKeep());
$event->setEnvelopesToKeep(array($envelopes[0], $envelopes[1]));
$event->setEnvelopesToRemove(array($envelopes[2], $envelopes[3]));
$this->assertEquals(array($envelopes[2], $envelopes[3]), $event->getEnvelopesToRemove());
$this->assertEquals(array($envelopes[0], $envelopes[1]), $event->getEnvelopesToKeep());
}
}
@@ -0,0 +1,29 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\ResponseEvent;
use Flasher\Tests\Prime\TestCase;
class ResponseEventTest extends TestCase
{
/**
* @return void
*/
public function testResponseEvent()
{
$event = new ResponseEvent('{"foo": "bar"}', 'json');
$this->assertEquals('{"foo": "bar"}', $event->getResponse());
$this->assertEquals('json', $event->getPresenter());
$event->setResponse('{"foo": "baz"}');
$this->assertEquals('{"foo": "baz"}', $event->getResponse());
}
}
@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the PHPFlasher package.
* (c) Younes KHOUBZA <younes.khoubza@gmail.com>
*/
namespace Flasher\Tests\Prime\EventDispatcher\Event;
use Flasher\Prime\EventDispatcher\Event\UpdateEvent;
use Flasher\Prime\Notification\Envelope;
use Flasher\Prime\Notification\Notification;
use Flasher\Tests\Prime\TestCase;
class UpdateEventTest extends TestCase
{
/**
* @return void
*/
public function testUpdateEvent()
{
$envelopes = array(
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
new Envelope(new Notification()),
);
$event = new UpdateEvent($envelopes);
$this->assertEquals($envelopes, $event->getEnvelopes());
$envelopes = array(
new Envelope(new Notification()),
);
$event->setEnvelopes($envelopes);
$this->assertEquals($envelopes, $event->getEnvelopes());
}
}