Started work on Events tests
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CachetHQ\Cachet\Events\User;
|
||||||
|
|
||||||
|
interface UserEventInterface
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ namespace CachetHQ\Cachet\Events\User;
|
|||||||
|
|
||||||
use CachetHQ\Cachet\Models\User;
|
use CachetHQ\Cachet\Models\User;
|
||||||
|
|
||||||
class UserWasAddedEvent
|
final class UserWasAddedEvent implements UserEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The user that has been added.
|
* The user that has been added.
|
||||||
@@ -24,6 +24,8 @@ class UserWasAddedEvent
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new user was added event instance.
|
* Create a new user was added event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(User $user)
|
public function __construct(User $user)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace CachetHQ\Cachet\Events\User;
|
|||||||
|
|
||||||
use CachetHQ\Cachet\Models\User;
|
use CachetHQ\Cachet\Models\User;
|
||||||
|
|
||||||
class UserWasRemovedEvent
|
final class UserWasRemovedEvent implements UserEventInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The user that has been removed.
|
* The user that has been removed.
|
||||||
@@ -24,6 +24,8 @@ class UserWasRemovedEvent
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new user was removed event instance.
|
* Create a new user was removed event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(User $user)
|
public function __construct(User $user)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CachetHQ\Tests\Cachet;
|
||||||
|
|
||||||
|
use ReflectionClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the abstract anemic test case class.
|
||||||
|
*
|
||||||
|
* @author Graham Campbell <graham@alt-three.com>
|
||||||
|
*/
|
||||||
|
abstract class AbstractAnemicTestCase extends AbstractTestCase
|
||||||
|
{
|
||||||
|
public function testClassIsFinal()
|
||||||
|
{
|
||||||
|
$rc = new ReflectionClass($this->getObjectAndParams()['object']);
|
||||||
|
|
||||||
|
$this->assertTrue($rc->isFinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPropertiesMatchTheConstructor()
|
||||||
|
{
|
||||||
|
$rc = new ReflectionClass($this->getObjectAndParams()['object']);
|
||||||
|
|
||||||
|
$properties = array_map(function ($property) {
|
||||||
|
return $property->getName();
|
||||||
|
}, $rc->getProperties());
|
||||||
|
|
||||||
|
$params = array_map(function ($param) {
|
||||||
|
return $param->getName();
|
||||||
|
}, $rc->getMethod('__construct')->getParameters());
|
||||||
|
|
||||||
|
if ($this->objectHasRules()) {
|
||||||
|
$params[] = 'rules';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertSame($properties, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPropertiesAreCorrectlyDefined()
|
||||||
|
{
|
||||||
|
$rc = new ReflectionClass($this->getObjectAndParams()['object']);
|
||||||
|
|
||||||
|
foreach ($rc->getProperties() as $property) {
|
||||||
|
$this->assertTrue($property->isPublic());
|
||||||
|
$this->assertFalse($property->isStatic());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPropertyAccessBehavesCorrectly()
|
||||||
|
{
|
||||||
|
extract($this->getObjectAndParams());
|
||||||
|
|
||||||
|
foreach ($params as $key => $value) {
|
||||||
|
$this->assertSame($value, $object->{$key});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CachetHQ\Tests\Cachet\Events;
|
||||||
|
|
||||||
|
use ReflectionClass;
|
||||||
|
use CachetHQ\Cachet\Providers\EventServiceProvider;
|
||||||
|
use CachetHQ\Tests\Cachet\AbstractAnemicTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the abstract event test case class.
|
||||||
|
*
|
||||||
|
* @author Graham Campbell <graham@alt-three.com>
|
||||||
|
*/
|
||||||
|
abstract class AbstractEventTestCase extends AbstractAnemicTestCase
|
||||||
|
{
|
||||||
|
protected function objectHasRules()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEventImplementsTheCorrectInterfaces()
|
||||||
|
{
|
||||||
|
$event = $this->getObjectAndParams()['object'];
|
||||||
|
|
||||||
|
foreach ($this->getEventInterfaces() as $interface) {
|
||||||
|
$this->assertInstanceOf($interface, $event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public function testEventHasRegisteredHandlers()
|
||||||
|
{
|
||||||
|
$property = (new ReflectionClass(EventServiceProvider::class))->getProperty('listen');
|
||||||
|
$property->setAccessible(true);
|
||||||
|
|
||||||
|
$class = get_class($this->getObjectAndParams()['object']);
|
||||||
|
$mappings = $property->getValue(new EventServiceProvider($this->app));
|
||||||
|
|
||||||
|
$this->assertTrue(isset($mappings[$class]));
|
||||||
|
$this->assertGreaterThan(0, count($mappings[$class]));
|
||||||
|
|
||||||
|
foreach ($mappings[$class] as $handler) {
|
||||||
|
$this->assertInstanceOf($handler, $this->app->make($handler));
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Cachet.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CachetHQ\Tests\Cachet\Events\User;
|
||||||
|
|
||||||
|
use CachetHQ\Cachet\Events\User\UserEventInterface;
|
||||||
|
use CachetHQ\Tests\Cachet\Events\AbstractEventTestCase;
|
||||||
|
|
||||||
|
class AbstractUserEventTestCase extends AbstractEventTestCase
|
||||||
|
{
|
||||||
|
protected function getEventInterfaces()
|
||||||
|
{
|
||||||
|
return [UserEventInterface::class];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of CachetHQ.
|
||||||
|
*
|
||||||
|
* (c) Alt Three Services Limited
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace CachetHQ\Tests\Cachet\Events\User;
|
||||||
|
|
||||||
|
use CachetHQ\Cachet\Events\User\UserWasAddedEvent;
|
||||||
|
use CachetHQ\Cachet\Models\User;
|
||||||
|
|
||||||
|
class UserWasAddedEventTest extends AbstractUserEventTestCase
|
||||||
|
{
|
||||||
|
protected function getObjectAndParams()
|
||||||
|
{
|
||||||
|
$params = ['user' => new User()];
|
||||||
|
$object = new UserWasAddedEvent($params['user']);
|
||||||
|
|
||||||
|
return compact('params', 'object');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user