Started work on Events tests
This commit is contained in:
67
tests/AbstractAnemicTestCase.php
Normal file
67
tests/AbstractAnemicTestCase.php
Normal file
@@ -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});
|
||||
}
|
||||
}
|
||||
}
|
||||
54
tests/Events/AbstractEventTestCase.php
Normal file
54
tests/Events/AbstractEventTestCase.php
Normal file
@@ -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));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
23
tests/Events/User/AbstractUserEventTestCase.php
Normal file
23
tests/Events/User/AbstractUserEventTestCase.php
Normal file
@@ -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];
|
||||
}
|
||||
}
|
||||
26
tests/Events/User/UserWasAddedEventTest.php
Normal file
26
tests/Events/User/UserWasAddedEventTest.php
Normal file
@@ -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