Rewrite the entire scheduled maintenance implementation

This commit is contained in:
James Brooks
2016-10-30 20:54:12 +00:00
parent a2cded299d
commit ebed68a7d8
57 changed files with 1989 additions and 512 deletions
+87
View File
@@ -0,0 +1,87 @@
<?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;
/**
* This is the schedule test class.
*
* @author James Brooks <james@alt-three.com>
*/
class ScheduleTest extends AbstractApiTestCase
{
public function testGetSchedules()
{
$schedules = factory('CachetHQ\Cachet\Models\Schedule', 3)->create();
$this->get('/api/v1/schedules');
$this->assertResponseOk();
$this->seeJson(['id' => $schedules[0]->id]);
$this->seeJson(['id' => $schedules[1]->id]);
$this->seeJson(['id' => $schedules[2]->id]);
}
public function testGetSchedule()
{
$schedule = factory('CachetHQ\Cachet\Models\Schedule')->create();
$this->get('/api/v1/schedules/'.$schedule->id);
$this->assertResponseOk();
$this->seeJson($schedule->toArray());
}
public function testCreateSchedule()
{
$this->beUser();
$schedule = [
'name' => 'Test Schedule',
'message' => 'Foo bar, baz.',
'status' => 1,
'scheduled_at' => date('Y-m-d H:i'),
];
$this->post('/api/v1/schedules/', $schedule);
$this->assertResponseOk();
$this->seeJson(array_forget($schedule, 'scheduled_at'));
}
public function testUpdateSchedule()
{
$this->beUser();
$schedule = factory('CachetHQ\Cachet\Models\Schedule')->create();
$this->put('/api/v1/schedules/'.$schedule->id, [
'name' => 'Updated schedule',
]);
$this->assertResponseOk();
$this->seeJson(['name' => 'Updated schedule']);
}
public function testDeleteSchedule()
{
$this->beUser();
factory('CachetHQ\Cachet\Models\Schedule')->create();
$this->delete('/api/v1/schedules/1');
$this->assertResponseStatus(204);
}
}
@@ -1,57 +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\Bus\Commands\Incident;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\Incident\ReportMaintenanceCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\Incident\ReportMaintenanceCommandHandler;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the add incident command test class.
*
* @author James Brooks <james@alt-three.com>
* @author Graham Campbell <graham@alt-three.com>
*/
class ReportMaintenanceCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = [
'name' => 'Test',
'message' => 'Foo bar baz',
'notify' => false,
'timestamp' => '2020-12-30 00:00:01',
];
$object = new ReportMaintenanceCommand(
$params['name'],
$params['message'],
$params['notify'],
$params['timestamp']
);
return compact('params', 'object');
}
protected function objectHasRules()
{
return true;
}
protected function getHandlerClass()
{
return ReportMaintenanceCommandHandler::class;
}
}
@@ -0,0 +1,59 @@
<?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\Bus\Commands\Schedule;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\Schedule\CreateScheduleCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\Schedule\CreateScheduleCommandHandler;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the create schedule command test class.
*
* @author James Brooks <james@alt-three.com>
*/
class CreateScheduleCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = [
'name' => 'Test',
'message' => 'Foo',
'status' => 1,
'scheduled_at' => date('Y-m-d H:i'),
'completed_at' => date('Y-m-d H:i'),
'components' => [],
];
$object = new CreateScheduleCommand(
$params['name'],
$params['message'],
$params['status'],
$params['scheduled_at'],
$params['completed_at'],
$params['components']
);
return compact('params', 'object');
}
protected function objectHasRules()
{
return true;
}
protected function getHandlerClass()
{
return CreateScheduleCommandHandler::class;
}
}
@@ -0,0 +1,50 @@
<?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\Bus\Commands\Schedule;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\Schedule\DeleteScheduleCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\Schedule\DeleteScheduleCommandHandler;
use CachetHQ\Cachet\Models\Schedule;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the create schedule command test class.
*
* @author James Brooks <james@alt-three.com>
*/
class DeleteScheduleCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = [
'schedule' => new Schedule(),
];
$object = new DeleteScheduleCommand(
$params['schedule']
);
return compact('params', 'object');
}
protected function objectHasRules()
{
return true;
}
protected function getHandlerClass()
{
return DeleteScheduleCommandHandler::class;
}
}
@@ -0,0 +1,62 @@
<?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\Bus\Commands\Schedule;
use AltThree\TestBench\CommandTrait;
use CachetHQ\Cachet\Bus\Commands\Schedule\UpdateScheduleCommand;
use CachetHQ\Cachet\Bus\Handlers\Commands\Schedule\UpdateScheduleCommandHandler;
use CachetHQ\Cachet\Models\Schedule;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the create schedule command test class.
*
* @author James Brooks <james@alt-three.com>
*/
class UpdateScheduleCommandTest extends AbstractTestCase
{
use CommandTrait;
protected function getObjectAndParams()
{
$params = [
'schedule' => new Schedule(),
'name' => 'Foo',
'message' => 'Bar',
'status' => 1,
'scheduled_at' => date('Y-m-d H:i'),
'completed_at' => date('Y-m-d H:i'),
'components' => [],
];
$object = new UpdateScheduleCommand(
$params['schedule'],
$params['name'],
$params['message'],
$params['status'],
$params['scheduled_at'],
$params['completed_at'],
$params['components']
);
return compact('params', 'object');
}
protected function objectHasRules()
{
return true;
}
protected function getHandlerClass()
{
return UpdateScheduleCommandHandler::class;
}
}
@@ -1,36 +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\Bus\Events\Incident;
use CachetHQ\Cachet\Bus\Events\Incident\MaintenanceWasScheduledEvent;
use CachetHQ\Cachet\Models\Incident;
/**
* This is the maintenance was scheduled event test class.
*
* @author James Brooks <james@alt-three.com>
*/
class MaintenanceWasScheduledEventTest extends AbstractIncidentEventTestCase
{
protected function objectHasHandlers()
{
return true;
}
protected function getObjectAndParams()
{
$params = ['incident' => new Incident()];
$object = new MaintenanceWasScheduledEvent($params['incident']);
return compact('params', 'object');
}
}
@@ -0,0 +1,26 @@
<?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\Bus\Events\Schedule;
use AltThree\TestBench\EventTrait;
use CachetHQ\Cachet\Bus\Events\Schedule\ScheduleEventInterface;
use CachetHQ\Tests\Cachet\AbstractTestCase;
abstract class AbstractScheduleEventTestCase extends AbstractTestCase
{
use EventTrait;
protected function getEventInterfaces()
{
return [ScheduleEventInterface::class];
}
}
@@ -0,0 +1,31 @@
<?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\Bus\Events\Schedule;
use CachetHQ\Cachet\Bus\Events\Schedule\ScheduleWasCreatedEvent;
use CachetHQ\Cachet\Models\Schedule;
class ScheduleWasAddedEventTest extends AbstractScheduleEventTestCase
{
protected function objectHasHandlers()
{
return false;
}
protected function getObjectAndParams()
{
$params = ['schedule' => new Schedule()];
$object = new ScheduleWasCreatedEvent($params['schedule']);
return compact('params', 'object');
}
}
@@ -0,0 +1,31 @@
<?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\Bus\Events\Schedule;
use CachetHQ\Cachet\Bus\Events\Schedule\ScheduleWasRemovedEvent;
use CachetHQ\Cachet\Models\Schedule;
class ScheduleWasRemovedEventTest extends AbstractScheduleEventTestCase
{
protected function objectHasHandlers()
{
return false;
}
protected function getObjectAndParams()
{
$params = ['schedule' => new Schedule()];
$object = new ScheduleWasRemovedEvent($params['schedule']);
return compact('params', 'object');
}
}
@@ -0,0 +1,31 @@
<?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\Bus\Events\Schedule;
use CachetHQ\Cachet\Bus\Events\Schedule\ScheduleWasUpdatedEvent;
use CachetHQ\Cachet\Models\Schedule;
class ScheduleWasUpdatedEventTest extends AbstractScheduleEventTestCase
{
protected function objectHasHandlers()
{
return false;
}
protected function getObjectAndParams()
{
$params = ['schedule' => new Schedule()];
$object = new ScheduleWasUpdatedEvent($params['schedule']);
return compact('params', 'object');
}
}
+31
View File
@@ -0,0 +1,31 @@
<?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\Models;
use AltThree\TestBench\ValidationTrait;
use CachetHQ\Cachet\Models\ScheduleComponent;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the schedule component model test class.
*
* @author James Brooks <james@alt-three.com>
*/
class ScheduleComponentTest extends AbstractTestCase
{
use ValidationTrait;
public function testValidation()
{
$this->checkRules(new ScheduleComponent());
}
}
+31
View File
@@ -0,0 +1,31 @@
<?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\Models;
use AltThree\TestBench\ValidationTrait;
use CachetHQ\Cachet\Models\Schedule;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the Schedule model test class.
*
* @author James Brooks <james@alt-three.com>
*/
class ScheduleTest extends AbstractTestCase
{
use ValidationTrait;
public function testValidation()
{
$this->checkRules(new Schedule());
}
}