Updated tests

This commit is contained in:
Graham Campbell
2015-12-06 11:04:02 +00:00
parent 036c819922
commit 19e3804227
42 changed files with 340 additions and 412 deletions

View File

@@ -39,6 +39,7 @@
"roumen/feed": "^2.9" "roumen/feed": "^2.9"
}, },
"require-dev": { "require-dev": {
"alt-three/testbench": "^1.0",
"filp/whoops": "^1.1", "filp/whoops": "^1.1",
"fzaninotto/faker": "^1.5", "fzaninotto/faker": "^1.5",
"graham-campbell/testbench-core": "^1.1", "graham-campbell/testbench-core": "^1.1",

62
composer.lock generated
View File

@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "68368056b2e111808dc9fde989b5324d", "hash": "d02e0141216bd2f17d2c97a5e7d0baab",
"content-hash": "976eda704e6a191e2bd557cb919f1ed6", "content-hash": "2dd41f1dc4f63c1ffae8cb0fc62ebfb5",
"packages": [ "packages": [
{ {
"name": "alt-three/emoji", "name": "alt-three/emoji",
@@ -3694,6 +3694,64 @@
} }
], ],
"packages-dev": [ "packages-dev": [
{
"name": "alt-three/testbench",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/AltThree/TestBench.git",
"reference": "cf53fab68ef3e397a0a72dc93fba2c65735916fa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/AltThree/TestBench/zipball/cf53fab68ef3e397a0a72dc93fba2c65735916fa",
"reference": "cf53fab68ef3e397a0a72dc93fba2c65735916fa",
"shasum": ""
},
"require": {
"graham-campbell/testbench-core": "^1.1",
"php": ">=5.5.9"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"AltThree\\TestBench\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "James Brooks",
"email": "james@alt-three.com"
},
{
"name": "Graham Campbell",
"email": "graham@alt-three.com"
},
{
"name": "Joseph Cohen",
"email": "joe@alt-three.com"
}
],
"description": "Provides Some Testing Traits For Alt Three Applications",
"keywords": [
"Alt Three",
"TestBench",
"application"
],
"time": "2015-12-06 10:47:25"
},
{ {
"name": "doctrine/instantiator", "name": "doctrine/instantiator",
"version": "1.0.5", "version": "1.0.5",

View File

@@ -1,67 +0,0 @@
<?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});
}
}
}

View File

@@ -11,10 +11,14 @@
namespace CachetHQ\Tests\Cachet; namespace CachetHQ\Tests\Cachet;
use CachetHQ\Cachet\Models\User;
use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\TestCase; use Illuminate\Foundation\Testing\TestCase;
/**
* This is the abstract test case class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
abstract class AbstractTestCase extends TestCase abstract class AbstractTestCase extends TestCase
{ {
/** /**
@@ -37,14 +41,4 @@ abstract class AbstractTestCase extends TestCase
return $app; return $app;
} }
/**
* Become a user.
*/
protected function beUser()
{
$this->user = factory(User::class)->create();
$this->be($this->user);
}
} }

View File

@@ -0,0 +1,36 @@
<?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\Api;
use CachetHQ\Cachet\Models\User;
use CachetHQ\Tests\Cachet\AbstractTestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
/**
* This is the abstract api test case class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
abstract class AbstractApiTestCase extends AbstractTestCase
{
use DatabaseMigrations;
/**
* Become a user.
*/
protected function beUser()
{
$this->user = factory(User::class)->create();
$this->be($this->user);
}
}

View File

@@ -11,13 +11,14 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Tests\Cachet\AbstractTestCase; /**
use Illuminate\Foundation\Testing\DatabaseMigrations; * This is the component group test class.
*
class ComponentGroupTest extends AbstractTestCase * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class ComponentGroupTest extends AbstractApiTestCase
{ {
use DatabaseMigrations;
public function testGetGroups() public function testGetGroups()
{ {
$groups = factory('CachetHQ\Cachet\Models\ComponentGroup', 3)->create(); $groups = factory('CachetHQ\Cachet\Models\ComponentGroup', 3)->create();

View File

@@ -11,13 +11,14 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Tests\Cachet\AbstractTestCase; /**
use Illuminate\Foundation\Testing\DatabaseMigrations; * This is the component test class.
*
class ComponentTest extends AbstractTestCase * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class ComponentTest extends AbstractApiTestCase
{ {
use DatabaseMigrations;
public function testGetComponents() public function testGetComponents()
{ {
$components = factory('CachetHQ\Cachet\Models\Component', 3)->create(); $components = factory('CachetHQ\Cachet\Models\Component', 3)->create();

View File

@@ -11,9 +11,13 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Tests\Cachet\AbstractTestCase; /**
* This is the general test class.
class GeneralTest extends AbstractTestCase *
* @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class GeneralTest extends AbstractApiTestCase
{ {
public function testGetPing() public function testGetPing()
{ {

View File

@@ -11,13 +11,14 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Tests\Cachet\AbstractTestCase; /**
use Illuminate\Foundation\Testing\DatabaseMigrations; * This is the incident test class.
*
class IncidentTest extends AbstractTestCase * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class IncidentTest extends AbstractApiTestCase
{ {
use DatabaseMigrations;
public function testGetIncidents() public function testGetIncidents()
{ {
$incidents = factory('CachetHQ\Cachet\Models\Incident', 3)->create(); $incidents = factory('CachetHQ\Cachet\Models\Incident', 3)->create();

View File

@@ -11,14 +11,16 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Tests\Cachet\AbstractTestCase;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class MetricPointTest extends AbstractTestCase /**
* This is the metric point test class.
*
* @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class MetricPointTest extends AbstractApiTestCase
{ {
use DatabaseMigrations;
public function testGetMetricPoint() public function testGetMetricPoint()
{ {
$metric = factory('CachetHQ\Cachet\Models\Metric')->create(); $metric = factory('CachetHQ\Cachet\Models\Metric')->create();

View File

@@ -11,13 +11,14 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Tests\Cachet\AbstractTestCase; /**
use Illuminate\Foundation\Testing\DatabaseMigrations; * This is the metric test class.
*
class MetricTest extends AbstractTestCase * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class MetricTest extends AbstractApiTestCase
{ {
use DatabaseMigrations;
public function testGetMetrics() public function testGetMetrics()
{ {
$metrics = factory('CachetHQ\Cachet\Models\Metric', 3)->create(); $metrics = factory('CachetHQ\Cachet\Models\Metric', 3)->create();

View File

@@ -11,13 +11,14 @@
namespace CachetHQ\Tests\Cachet\Api; namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Tests\Cachet\AbstractTestCase; /**
use Illuminate\Foundation\Testing\DatabaseMigrations; * This is the subscriber test class.
*
class SubscriberTest extends AbstractTestCase * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class SubscriberTest extends AbstractApiTestCase
{ {
use DatabaseMigrations;
public function testGetSubscribersUnauthenticated() public function testGetSubscribersUnauthenticated()
{ {
$this->get('/api/v1/subscribers'); $this->get('/api/v1/subscribers');

View File

@@ -1,31 +0,0 @@
<?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\Commands;
use CachetHQ\Tests\Cachet\AbstractAnemicTestCase;
use Illuminate\Contracts\Bus\Dispatcher;
/**
* This is the abstract command test case class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
abstract class AbstractCommandTestCase extends AbstractAnemicTestCase
{
public function testHandlerCanBeResolved()
{
$command = $this->getObjectAndParams()['object'];
$dispatcher = $this->app->make(Dispatcher::class);
$this->assertInstanceOf($this->getHandlerClass(), $dispatcher->resolveHandler($command));
}
}

View File

@@ -13,15 +13,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Component;
use CachetHQ\Cachet\Commands\Component\AddComponentCommand; use CachetHQ\Cachet\Commands\Component\AddComponentCommand;
use CachetHQ\Cachet\Handlers\Commands\Component\AddComponentCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Component\AddComponentCommandHandler;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the add component command test class. * This is the add component command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class AddComponentCommandTest extends AbstractCommandTestCase class AddComponentCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Component;
use CachetHQ\Cachet\Commands\Component\RemoveComponentCommand; use CachetHQ\Cachet\Commands\Component\RemoveComponentCommand;
use CachetHQ\Cachet\Handlers\Commands\Component\RemoveComponentCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Component\RemoveComponentCommandHandler;
use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Component;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the remove component command test class. * This is the remove component command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class RemoveComponentCommandTest extends AbstractCommandTestCase class RemoveComponentCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['component' => new Component()]; $params = ['component' => new Component()];
@@ -31,11 +35,6 @@ class RemoveComponentCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return RemoveComponentCommandHandler::class; return RemoveComponentCommandHandler::class;

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Component;
use CachetHQ\Cachet\Commands\Component\UpdateComponentCommand; use CachetHQ\Cachet\Commands\Component\UpdateComponentCommand;
use CachetHQ\Cachet\Handlers\Commands\Component\UpdateComponentCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Component\UpdateComponentCommandHandler;
use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Component;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the update component command test class. * This is the update component command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class UpdateComponentCommandTest extends AbstractCommandTestCase class UpdateComponentCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [
@@ -35,6 +39,7 @@ class UpdateComponentCommandTest extends AbstractCommandTestCase
'group_id' => 0, 'group_id' => 0,
'enabled' => true, 'enabled' => true,
]; ];
$object = new UpdateComponentCommand( $object = new UpdateComponentCommand(
$params['component'], $params['component'],
$params['name'], $params['name'],

View File

@@ -13,25 +13,24 @@ namespace CachetHQ\Tests\Cachet\Commands\ComponentGroup;
use CachetHQ\Cachet\Commands\ComponentGroup\AddComponentGroupCommand; use CachetHQ\Cachet\Commands\ComponentGroup\AddComponentGroupCommand;
use CachetHQ\Cachet\Handlers\Commands\ComponentGroup\AddComponentGroupCommandHandler; use CachetHQ\Cachet\Handlers\Commands\ComponentGroup\AddComponentGroupCommandHandler;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the add component group command test class. * This is the add component group command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class AddComponentGroupCommandTest extends AbstractCommandTestCase class AddComponentGroupCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = ['name' => 'Test', 'order' => 0];
'name' => 'Test',
'order' => 0, $object = new AddComponentGroupCommand($params['name'], $params['order']);
];
$object = new AddComponentGroupCommand(
$params['name'],
$params['order']
);
return compact('params', 'object'); return compact('params', 'object');
} }

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\ComponentGroup;
use CachetHQ\Cachet\Commands\ComponentGroup\RemoveComponentGroupCommand; use CachetHQ\Cachet\Commands\ComponentGroup\RemoveComponentGroupCommand;
use CachetHQ\Cachet\Handlers\Commands\ComponentGroup\RemoveComponentGroupCommandHandler; use CachetHQ\Cachet\Handlers\Commands\ComponentGroup\RemoveComponentGroupCommandHandler;
use CachetHQ\Cachet\Models\ComponentGroup; use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the remove component group command test class. * This is the remove component group command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class RemoveComponentGroupCommandTest extends AbstractCommandTestCase class RemoveComponentGroupCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['group' => new ComponentGroup()]; $params = ['group' => new ComponentGroup()];
@@ -31,11 +35,6 @@ class RemoveComponentGroupCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return RemoveComponentGroupCommandHandler::class; return RemoveComponentGroupCommandHandler::class;

View File

@@ -14,22 +14,22 @@ namespace CachetHQ\Tests\Cachet\Commands\ComponentGroup;
use CachetHQ\Cachet\Commands\ComponentGroup\UpdateComponentGroupCommand; use CachetHQ\Cachet\Commands\ComponentGroup\UpdateComponentGroupCommand;
use CachetHQ\Cachet\Handlers\Commands\ComponentGroup\UpdateComponentGroupCommandHandler; use CachetHQ\Cachet\Handlers\Commands\ComponentGroup\UpdateComponentGroupCommandHandler;
use CachetHQ\Cachet\Models\ComponentGroup; use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the update component group command test class. * This is the update component group command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class UpdateComponentGroupCommandTest extends AbstractCommandTestCase class UpdateComponentGroupCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = ['group' => new ComponentGroup(), 'name' => 'Foo', 'order' => 1];
'group' => new ComponentGroup(),
'name' => 'Foo',
'order' => 1,
];
$object = new UpdateComponentGroupCommand($params['group'], $params['name'], $params['order']); $object = new UpdateComponentGroupCommand($params['group'], $params['name'], $params['order']);
return compact('params', 'object'); return compact('params', 'object');

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Incident;
use CachetHQ\Cachet\Commands\Incident\RemoveIncidentCommand; use CachetHQ\Cachet\Commands\Incident\RemoveIncidentCommand;
use CachetHQ\Cachet\Handlers\Commands\Incident\RemoveIncidentCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Incident\RemoveIncidentCommandHandler;
use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the remove incident command test class. * This is the remove incident command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class RemoveIncidentCommandTest extends AbstractCommandTestCase class RemoveIncidentCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['incident' => new Incident()]; $params = ['incident' => new Incident()];
@@ -31,11 +35,6 @@ class RemoveIncidentCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return RemoveIncidentCommandHandler::class; return RemoveIncidentCommandHandler::class;

View File

@@ -13,15 +13,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Incident;
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand; use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
use CachetHQ\Cachet\Handlers\Commands\Incident\ReportIncidentCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Incident\ReportIncidentCommandHandler;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the add incident command test class. * This is the add incident command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class ReportIncidentCommandTest extends AbstractCommandTestCase class ReportIncidentCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [
@@ -36,6 +40,7 @@ class ReportIncidentCommandTest extends AbstractCommandTestCase
'template' => null, 'template' => null,
'template_vars' => null, 'template_vars' => null,
]; ];
$object = new ReportIncidentCommand( $object = new ReportIncidentCommand(
$params['name'], $params['name'],
$params['status'], $params['status'],

View File

@@ -13,15 +13,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Incident;
use CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand; use CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand;
use CachetHQ\Cachet\Handlers\Commands\Incident\ReportMaintenanceCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Incident\ReportMaintenanceCommandHandler;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the add incident command test class. * This is the add incident command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class ReportMaintenanceCommandTest extends AbstractCommandTestCase class ReportMaintenanceCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [
@@ -30,6 +34,7 @@ class ReportMaintenanceCommandTest extends AbstractCommandTestCase
'notify' => false, 'notify' => false,
'timestamp' => '2020-12-30 00:00:01', 'timestamp' => '2020-12-30 00:00:01',
]; ];
$object = new ReportMaintenanceCommand( $object = new ReportMaintenanceCommand(
$params['name'], $params['name'],
$params['message'], $params['message'],

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Incident;
use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand; use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand;
use CachetHQ\Cachet\Handlers\Commands\Incident\UpdateIncidentCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Incident\UpdateIncidentCommandHandler;
use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the update incident command test class. * This is the update incident command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class UpdateIncidentCommandTest extends AbstractCommandTestCase class UpdateIncidentCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [
@@ -38,6 +42,7 @@ class UpdateIncidentCommandTest extends AbstractCommandTestCase
'template' => null, 'template' => null,
'template_vars' => null, 'template_vars' => null,
]; ];
$object = new UpdateIncidentCommand( $object = new UpdateIncidentCommand(
$params['incident'], $params['incident'],
$params['name'], $params['name'],

View File

@@ -13,15 +13,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Metric;
use CachetHQ\Cachet\Commands\Metric\AddMetricCommand; use CachetHQ\Cachet\Commands\Metric\AddMetricCommand;
use CachetHQ\Cachet\Handlers\Commands\Metric\AddMetricCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Metric\AddMetricCommandHandler;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the add metric command test class. * This is the add metric command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class AddMetricCommandTest extends AbstractCommandTestCase class AddMetricCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [
@@ -33,6 +37,7 @@ class AddMetricCommandTest extends AbstractCommandTestCase
'display_chart' => 1, 'display_chart' => 1,
'places' => 0, 'places' => 0,
]; ];
$object = new AddMetricCommand( $object = new AddMetricCommand(
$params['name'], $params['name'],
$params['suffix'], $params['suffix'],

View File

@@ -14,27 +14,23 @@ namespace CachetHQ\Tests\Cachet\Commands\Metric;
use CachetHQ\Cachet\Commands\Metric\AddMetricPointCommand; use CachetHQ\Cachet\Commands\Metric\AddMetricPointCommand;
use CachetHQ\Cachet\Handlers\Commands\Metric\AddMetricPointCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Metric\AddMetricPointCommandHandler;
use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the add metric point command test class. * This is the add metric point command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class AddMetricPointCommandTest extends AbstractCommandTestCase class AddMetricPointCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = ['metric' => new Metric(), 'value' => 1, 'created_at' => '2020-12-30 12:00:00'];
'metric' => new Metric(), $object = new AddMetricPointCommand($params['metric'], $params['value'], $params['created_at']);
'value' => 1,
'created_at' => '2020-12-30 12:00:00',
];
$object = new AddMetricPointCommand(
$params['metric'],
$params['value'],
$params['created_at']
);
return compact('params', 'object'); return compact('params', 'object');
} }

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Metric;
use CachetHQ\Cachet\Commands\Metric\RemoveMetricCommand; use CachetHQ\Cachet\Commands\Metric\RemoveMetricCommand;
use CachetHQ\Cachet\Handlers\Commands\Metric\RemoveMetricCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Metric\RemoveMetricCommandHandler;
use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the remove metric command test class. * This is the remove metric command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class RemoveMetricCommandTest extends AbstractCommandTestCase class RemoveMetricCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['metric' => new Metric()]; $params = ['metric' => new Metric()];
@@ -31,11 +35,6 @@ class RemoveMetricCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return RemoveMetricCommandHandler::class; return RemoveMetricCommandHandler::class;

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Metric;
use CachetHQ\Cachet\Commands\Metric\RemoveMetricPointCommand; use CachetHQ\Cachet\Commands\Metric\RemoveMetricPointCommand;
use CachetHQ\Cachet\Handlers\Commands\Metric\RemoveMetricPointCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Metric\RemoveMetricPointCommandHandler;
use CachetHQ\Cachet\Models\MetricPoint; use CachetHQ\Cachet\Models\MetricPoint;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the remove metric point command test class. * This is the remove metric point command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class RemoveMetricPointCommandTest extends AbstractCommandTestCase class RemoveMetricPointCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['metricPoint' => new MetricPoint()]; $params = ['metricPoint' => new MetricPoint()];
@@ -31,11 +35,6 @@ class RemoveMetricPointCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return RemoveMetricPointCommandHandler::class; return RemoveMetricPointCommandHandler::class;

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Metric;
use CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand; use CachetHQ\Cachet\Commands\Metric\UpdateMetricCommand;
use CachetHQ\Cachet\Handlers\Commands\Metric\UpdateMetricCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Metric\UpdateMetricCommandHandler;
use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the update metric command test class. * This is the update metric command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class UpdateMetricCommandTest extends AbstractCommandTestCase class UpdateMetricCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [
@@ -35,6 +39,7 @@ class UpdateMetricCommandTest extends AbstractCommandTestCase
'display_chart' => 1, 'display_chart' => 1,
'places' => 0, 'places' => 0,
]; ];
$object = new UpdateMetricCommand( $object = new UpdateMetricCommand(
$params['metric'], $params['metric'],
$params['name'], $params['name'],

View File

@@ -15,15 +15,19 @@ use CachetHQ\Cachet\Commands\Metric\UpdateMetricPointCommand;
use CachetHQ\Cachet\Handlers\Commands\Metric\UpdateMetricPointCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Metric\UpdateMetricPointCommandHandler;
use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\MetricPoint; use CachetHQ\Cachet\Models\MetricPoint;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the update metric point command test class. * This is the update metric point command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class UpdateMetricPointCommandTest extends AbstractCommandTestCase class UpdateMetricPointCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [
@@ -32,6 +36,7 @@ class UpdateMetricPointCommandTest extends AbstractCommandTestCase
'value' => 1, 'value' => 1,
'created_at' => '2012-12-30 12:00:00', 'created_at' => '2012-12-30 12:00:00',
]; ];
$object = new UpdateMetricPointCommand( $object = new UpdateMetricPointCommand(
$params['point'], $params['point'],
$params['metric'], $params['metric'],

View File

@@ -13,25 +13,23 @@ namespace CachetHQ\Tests\Cachet\Commands\Subscriber;
use CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand; use CachetHQ\Cachet\Commands\Subscriber\SubscribeSubscriberCommand;
use CachetHQ\Cachet\Handlers\Commands\Subscriber\SubscribeSubscriberCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Subscriber\SubscribeSubscriberCommandHandler;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the subscribe subscriber command test class. * This is the subscribe subscriber command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class SubscribeSubscriberCommandTest extends AbstractCommandTestCase class SubscribeSubscriberCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = ['email' => 'support@cachethq.io', 'verified' => true];
'email' => 'support@cachethq.io', $object = new SubscribeSubscriberCommand($params['email'], $params['verified']);
'verified' => true,
];
$object = new SubscribeSubscriberCommand(
$params['email'],
$params['verified']
);
return compact('params', 'object'); return compact('params', 'object');
} }

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Subscriber;
use CachetHQ\Cachet\Commands\Subscriber\UnsubscribeSubscriberCommand; use CachetHQ\Cachet\Commands\Subscriber\UnsubscribeSubscriberCommand;
use CachetHQ\Cachet\Handlers\Commands\Subscriber\UnsubscribeSubscriberCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Subscriber\UnsubscribeSubscriberCommandHandler;
use CachetHQ\Cachet\Models\Subscriber; use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the unsubscribe subscriber command test class. * This is the unsubscribe subscriber command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class UnsubscribeSubscriberCommandTest extends AbstractCommandTestCase class UnsubscribeSubscriberCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['subscriber' => new Subscriber()]; $params = ['subscriber' => new Subscriber()];
@@ -31,11 +35,6 @@ class UnsubscribeSubscriberCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return UnsubscribeSubscriberCommandHandler::class; return UnsubscribeSubscriberCommandHandler::class;

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\Subscriber;
use CachetHQ\Cachet\Commands\Subscriber\VerifySubscriberCommand; use CachetHQ\Cachet\Commands\Subscriber\VerifySubscriberCommand;
use CachetHQ\Cachet\Handlers\Commands\Subscriber\VerifySubscriberCommandHandler; use CachetHQ\Cachet\Handlers\Commands\Subscriber\VerifySubscriberCommandHandler;
use CachetHQ\Cachet\Models\Subscriber; use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the verify subscriber command test class. * This is the verify subscriber command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class VerifySubscriberCommandTest extends AbstractCommandTestCase class VerifySubscriberCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['subscriber' => new Subscriber()]; $params = ['subscriber' => new Subscriber()];
@@ -31,11 +35,6 @@ class VerifySubscriberCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return VerifySubscriberCommandHandler::class; return VerifySubscriberCommandHandler::class;

View File

@@ -13,15 +13,19 @@ namespace CachetHQ\Tests\Cachet\Commands\User;
use CachetHQ\Cachet\Commands\User\AddTeamMemberCommand; use CachetHQ\Cachet\Commands\User\AddTeamMemberCommand;
use CachetHQ\Cachet\Handlers\Commands\User\AddTeamMemberCommandHandler; use CachetHQ\Cachet\Handlers\Commands\User\AddTeamMemberCommandHandler;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the add team member command test class. * This is the add team member command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class AddTeamMemberCommandTest extends AbstractCommandTestCase class AddTeamMemberCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = [ $params = [
@@ -30,6 +34,7 @@ class AddTeamMemberCommandTest extends AbstractCommandTestCase
'email' => 'test@test.com', 'email' => 'test@test.com',
'level' => 1, 'level' => 1,
]; ];
$object = new AddTeamMemberCommand( $object = new AddTeamMemberCommand(
$params['username'], $params['username'],
$params['password'], $params['password'],

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\User;
use CachetHQ\Cachet\Commands\User\GenerateApiTokenCommand; use CachetHQ\Cachet\Commands\User\GenerateApiTokenCommand;
use CachetHQ\Cachet\Handlers\Commands\User\GenerateApiTokenCommandHandler; use CachetHQ\Cachet\Handlers\Commands\User\GenerateApiTokenCommandHandler;
use CachetHQ\Cachet\Models\User; use CachetHQ\Cachet\Models\User;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the generate api token command test class. * This is the generate api token command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class GenerateApiTokenCommandTest extends AbstractCommandTestCase class GenerateApiTokenCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['user' => new User()]; $params = ['user' => new User()];
@@ -31,11 +35,6 @@ class GenerateApiTokenCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return GenerateApiTokenCommandHandler::class; return GenerateApiTokenCommandHandler::class;

View File

@@ -14,15 +14,19 @@ namespace CachetHQ\Tests\Cachet\Commands\User;
use CachetHQ\Cachet\Commands\User\RemoveUserCommand; use CachetHQ\Cachet\Commands\User\RemoveUserCommand;
use CachetHQ\Cachet\Handlers\Commands\User\RemoveUserCommandHandler; use CachetHQ\Cachet\Handlers\Commands\User\RemoveUserCommandHandler;
use CachetHQ\Cachet\Models\User; use CachetHQ\Cachet\Models\User;
use CachetHQ\Tests\Cachet\Commands\AbstractCommandTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use AltThree\TestBench\CommandTrait;
/** /**
* This is the remove user command test class. * This is the remove user command test class.
* *
* @author James Brooks <james@alt-three.com> * @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/ */
class RemoveUserCommandTest extends AbstractCommandTestCase class RemoveUserCommandTest extends AbstractTestCase
{ {
use CommandTrait;
protected function getObjectAndParams() protected function getObjectAndParams()
{ {
$params = ['user' => new User()]; $params = ['user' => new User()];
@@ -31,11 +35,6 @@ class RemoveUserCommandTest extends AbstractCommandTestCase
return compact('params', 'object'); return compact('params', 'object');
} }
protected function objectHasRules()
{
return false;
}
protected function getHandlerClass() protected function getHandlerClass()
{ {
return RemoveUserCommandHandler::class; return RemoveUserCommandHandler::class;

View File

@@ -1,64 +0,0 @@
<?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 CachetHQ\Cachet\Providers\EventServiceProvider;
use CachetHQ\Tests\Cachet\AbstractAnemicTestCase;
use ReflectionClass;
/**
* 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;
}
protected function objectHasHandlers()
{
return true;
}
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]));
if ($this->objectHasHandlers()) {
$this->assertGreaterThan(0, count($mappings[$class]));
} else {
$this->assertSame(0, count($mappings[$class]));
}
foreach ($mappings[$class] as $handler) {
$this->assertInstanceOf($handler, $this->app->make($handler));
}
}
}

View File

@@ -11,11 +11,19 @@
namespace CachetHQ\Tests\Cachet\Events\User; namespace CachetHQ\Tests\Cachet\Events\User;
use AltThree\TestBench\EventTrait;
use CachetHQ\Cachet\Events\User\UserEventInterface; use CachetHQ\Cachet\Events\User\UserEventInterface;
use CachetHQ\Tests\Cachet\Events\AbstractEventTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
class AbstractUserEventTestCase extends AbstractEventTestCase /**
* This is the abstract user event test class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
abstract class AbstractUserEventTestCase extends AbstractTestCase
{ {
use EventTrait;
protected function getEventInterfaces() protected function getEventInterfaces()
{ {
return [UserEventInterface::class]; return [UserEventInterface::class];

View File

@@ -14,6 +14,11 @@ namespace CachetHQ\Tests\Cachet\Events\User;
use CachetHQ\Cachet\Events\User\UserWasAddedEvent; use CachetHQ\Cachet\Events\User\UserWasAddedEvent;
use CachetHQ\Cachet\Models\User; use CachetHQ\Cachet\Models\User;
/**
* This is the user was added event test class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
class UserWasAddedEventTest extends AbstractUserEventTestCase class UserWasAddedEventTest extends AbstractUserEventTestCase
{ {
protected function objectHasHandlers() protected function objectHasHandlers()

View File

@@ -14,6 +14,11 @@ namespace CachetHQ\Tests\Cachet\Functional;
use CachetHQ\Tests\Cachet\AbstractTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use Illuminate\Contracts\Console\Kernel; use Illuminate\Contracts\Console\Kernel;
/**
* This is the command test class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
class CommandTest extends AbstractTestCase class CommandTest extends AbstractTestCase
{ {
public function testMigrations() public function testMigrations()

View File

@@ -11,17 +11,15 @@
namespace CachetHQ\Tests\Cachet\Providers; namespace CachetHQ\Tests\Cachet\Providers;
use CachetHQ\Cachet\Providers\AppServiceProvider; use AltThree\TestBench\ServiceProviderTrait;
use CachetHQ\Tests\Cachet\AbstractTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use GrahamCampbell\TestBenchCore\LaravelTrait;
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
/**
* This is the app service provider test class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
class AppServiceProviderTest extends AbstractTestCase class AppServiceProviderTest extends AbstractTestCase
{ {
use LaravelTrait, ServiceProviderTrait; use ServiceProviderTrait;
protected function getServiceProviderClass($app)
{
return AppServiceProvider::class;
}
} }

View File

@@ -11,67 +11,15 @@
namespace CachetHQ\Tests\Cachet\Providers; namespace CachetHQ\Tests\Cachet\Providers;
use CachetHQ\Cachet\Providers\EventServiceProvider; use AltThree\TestBench\EventServiceProviderTrait;
use CachetHQ\Tests\Cachet\AbstractTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use GrahamCampbell\TestBenchCore\LaravelTrait;
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use ReflectionClass;
/**
* This is the event service provider test class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
class EventServiceProviderTest extends AbstractTestCase class EventServiceProviderTest extends AbstractTestCase
{ {
use LaravelTrait, ServiceProviderTrait; use EventServiceProviderTrait;
protected function getServiceProviderClass($app)
{
return EventServiceProvider::class;
}
public function testIsAnEventServiceProvider()
{
$class = $this->getServiceProviderClass($this->app);
$reflection = new ReflectionClass($class);
$provider = new ReflectionClass(ServiceProvider::class);
$msg = "Expected class '$class' to be an event service provider.";
$this->assertTrue($reflection->isSubclassOf($provider), $msg);
}
public function testListenerMapIsAnArray()
{
$map = $this->getListenerMap();
$this->assertInternalType('array', $map);
$this->assertGreaterThan(0, count($map));
}
/**
* @depends testListenerMapIsAnArray
*/
public function testListenerMapEventsExist()
{
$map = $this->getListenerMap();
foreach (array_keys($map) as $event) {
$this->assertTrue(class_exists($event));
}
}
/**
* @depends testListenerMapIsAnArray
*/
public function testListenerMapKeysAreSorted()
{
$map = $this->getListenerMap();
$events = array_keys($map);
sort($events);
$this->assertSame($events, array_keys($map));
}
protected function getListenerMap()
{
$class = $this->getServiceProviderClass($this->app);
$reflection = new ReflectionClass($class);
$property = $reflection->getProperty('listen');
$property->setAccessible(true);
return $property->getValue(new $class($this->app));
}
} }

View File

@@ -11,17 +11,15 @@
namespace CachetHQ\Tests\Cachet\Providers; namespace CachetHQ\Tests\Cachet\Providers;
use CachetHQ\Cachet\Providers\RepositoryServiceProvider; use AltThree\TestBench\ServiceProviderTrait;
use CachetHQ\Tests\Cachet\AbstractTestCase; use CachetHQ\Tests\Cachet\AbstractTestCase;
use GrahamCampbell\TestBenchCore\LaravelTrait;
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
/**
* This is the repository service provider test class.
*
* @author Graham Campbell <graham@alt-three.com>
*/
class RepositoryServiceProviderTest extends AbstractTestCase class RepositoryServiceProviderTest extends AbstractTestCase
{ {
use LaravelTrait, ServiceProviderTrait; use ServiceProviderTrait;
protected function getServiceProviderClass($app)
{
return RepositoryServiceProvider::class;
}
} }