Changed SceneAttachment to require the class to implement AttachmentInterface.
This commit is contained in:
@@ -11,6 +11,7 @@ use Doctrine\ORM\Mapping\Id;
|
||||
use Doctrine\ORM\Mapping\ManyToMany;
|
||||
use Doctrine\ORM\Mapping\Table;
|
||||
use LotGD\Core\Attachment;
|
||||
use LotGD\Core\AttachmentInterface;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
|
||||
/**
|
||||
@@ -36,13 +37,13 @@ class SceneAttachment
|
||||
|
||||
/**
|
||||
* SceneAttachment constructor.
|
||||
* @param string $class A class inheriting from Attachment.
|
||||
* @param string $class A class inheriting from AttachmentInterface.
|
||||
* @param string $title
|
||||
* @throws ArgumentException if $class does not implement Attachment
|
||||
* @throws ArgumentException if $class does not implement AttachmentInterface
|
||||
*/
|
||||
public function __construct(string $class, string $title) {
|
||||
if (!is_subclass_of($class, Attachment::class)) {
|
||||
throw new ArgumentException("The class '{$class}' must inherit from " . Attachment::class);
|
||||
if (!is_subclass_of($class, AttachmentInterface::class)) {
|
||||
throw new ArgumentException("The class '{$class}' must inherit from " . AttachmentInterface::class);
|
||||
}
|
||||
|
||||
$this->class = $class;
|
||||
|
||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace LotGD\Core\Tests\Models;
|
||||
|
||||
use LotGD\Core\Action;
|
||||
use LotGD\Core\Attachment;
|
||||
use LotGD\Core\Exceptions\ArgumentException;
|
||||
use LotGD\Core\Models\{Scene, SceneAttachment, SceneConnection, SceneConnectionGroup, SceneTemplate};
|
||||
@@ -11,7 +12,15 @@ use LotGD\Core\Tests\SceneTemplates\NewSceneSceneTemplate;
|
||||
|
||||
class TestAttachment extends Attachment
|
||||
{
|
||||
public function getData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
class InvalidTestAttachment
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace LotGD\Core\Tests\Models;
|
||||
use LotGD\Core\Action;
|
||||
use LotGD\Core\ActionGroup;
|
||||
use LotGD\Core\Attachment;
|
||||
use LotGD\Core\Game;
|
||||
use LotGD\Core\Models\Character;
|
||||
use LotGD\Core\Models\Viewpoint;
|
||||
use LotGD\Core\Models\Scene;
|
||||
@@ -16,16 +17,26 @@ class SampleAttachment extends Attachment
|
||||
{
|
||||
protected $foo;
|
||||
|
||||
public function __construct(string $foo)
|
||||
public function __construct(Game $game, Scene $scene, $testParam = null)
|
||||
{
|
||||
parent::__construct('bar');
|
||||
$this->foo = $foo;
|
||||
parent::__construct($game, $scene);
|
||||
$this->foo = $testParam;
|
||||
}
|
||||
|
||||
public function getFoo()
|
||||
{
|
||||
return $this->foo;
|
||||
}
|
||||
|
||||
public function getData(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,13 +133,14 @@ class ViewpointTest extends CoreModelTestCase
|
||||
public function testAttachments()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$input = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
|
||||
|
||||
$a1 = new SampleAttachment('baz');
|
||||
$a2 = new SampleAttachment('fiz');
|
||||
$a1 = new SampleAttachment($this->g, $input->getScene(), "baz");
|
||||
$a2 = new SampleAttachment($this->g, $input->getScene(), "fiz");
|
||||
|
||||
$attachments = [$a1, $a2];
|
||||
|
||||
$input = $em->getRepository(Viewpoint::class)->find("10000000-0000-0000-0000-000000000002");
|
||||
|
||||
$input->setAttachments($attachments);
|
||||
$input->save($em);
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ characters:
|
||||
viewpoints:
|
||||
-
|
||||
owner_id: "10000000-0000-0000-0000-000000000002"
|
||||
scene_id: "30000000-0000-0000-0000-000000000001"
|
||||
title: "The Village"
|
||||
description: "This is the village."
|
||||
template: "lotgd/tests/village"
|
||||
|
||||
Reference in New Issue
Block a user