Skip to content

Commit

Permalink
test: implement animal and bird model tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vicvolk committed Sep 17, 2021
1 parent 8280a78 commit 8e30335
Show file tree
Hide file tree
Showing 67 changed files with 826 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .phpunit.result.cache

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function eventGatewayType(string $eventGatewayType): AbstractEventBasedGa
return $this;
}

public function asyncAfter(bool $isCamundaAsyncAfter): AbstractEventBasedGatewayBuilder
public function asyncAfter(bool $isAsyncAfter): AbstractEventBasedGatewayBuilder
{
throw new \Exception("'asyncAfter' is not supported for 'Event Based Gateway'");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Bpmn/Builder/AbstractFlowNodeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function exclusive(bool $exclusive): AbstractFlowNodeBuilder
return $this;
}

public function camundaJobPriority(string $jobPriority): AbstractFlowNodeBuilder
public function jobPriority(string $jobPriority): AbstractFlowNodeBuilder
{
$this->element->setJobPriority($jobPriority);
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Bpmn/Builder/AbstractFormFieldBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function defaultValue(string $defaultValue): AbstractFormFieldBuilder
return $this;
}

public function camundaFormFieldDone(): AbstractFormFieldBuilder
public function formFieldDone(): AbstractFormFieldBuilder
{
return parent::builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,26 @@ public function newInstance(ModelTypeInstanceContext $instanceContext): ModelEle
self::$completionConditionChild = $sequenceBuilder->element(CompletionConditionInterface::class)
->build();

self::$camundaAsyncAfter = $typeBuilder->booleanAttribute(BpmnModelConstants::ATTRIBUTE_ASYNC_AFTER)
self::$asyncAfter = $typeBuilder->booleanAttribute(BpmnModelConstants::ATTRIBUTE_ASYNC_AFTER)
->namespace(BpmnModelConstants::NS)
->defaultValue(false)
->build();

self::$camundaAsyncBefore = $typeBuilder->booleanAttribute(BpmnModelConstants::ATTRIBUTE_ASYNC_BEFORE)
self::$asyncBefore = $typeBuilder->booleanAttribute(BpmnModelConstants::ATTRIBUTE_ASYNC_BEFORE)
->namespace(BpmnModelConstants::NS)
->defaultValue(false)
->build();

self::$camundaExclusive = $typeBuilder->booleanAttribute(BpmnModelConstants::ATTRIBUTE_EXCLUSIVE)
self::$exclusive = $typeBuilder->booleanAttribute(BpmnModelConstants::ATTRIBUTE_EXCLUSIVE)
->namespace(BpmnModelConstants::NS)
->defaultValue(true)
->build();

self::$camundaCollection = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_COLLECTION)
self::$collection = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_COLLECTION)
->namespace(BpmnModelConstants::NS)
->build();

self::$camundaElementVariable = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_ELEMENT_VARIABLE)
self::$elementVariable = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_ELEMENT_VARIABLE)
->namespace(BpmnModelConstants::NS)
->build();

Expand Down
16 changes: 8 additions & 8 deletions src/Model/Bpmn/Impl/Instance/UserTaskImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,43 +62,43 @@ public function newInstance(ModelTypeInstanceContext $instanceContext): ModelEle
self::$renderingCollection = $sequenceBuilder->elementCollection(RenderingInterface::class)
->build();

self::$camundaAssigneeAttribute = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_ASSIGNEE)
self::$assigneeAttribute = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_ASSIGNEE)
->namespace(BpmnModelConstants::NS)
->build();

self::$camundaCandidateGroupsAttribute = $typeBuilder->stringAttribute(
self::$candidateGroupsAttribute = $typeBuilder->stringAttribute(
BpmnModelConstants::ATTRIBUTE_CANDIDATE_GROUPS
)
->namespace(BpmnModelConstants::NS)
->build();

self::$camundaCandidateUsersAttribute = $typeBuilder->stringAttribute(
self::$candidateUsersAttribute = $typeBuilder->stringAttribute(
BpmnModelConstants::ATTRIBUTE_CANDIDATE_USERS
)
->namespace(BpmnModelConstants::NS)
->build();

self::$camundaDueDateAttribute = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_DUE_DATE)
self::$dueDateAttribute = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_DUE_DATE)
->namespace(BpmnModelConstants::NS)
->build();

self::$camundaFollowUpDateAttribute = $typeBuilder->stringAttribute(
self::$followUpDateAttribute = $typeBuilder->stringAttribute(
BpmnModelConstants::ATTRIBUTE_FOLLOW_UP_DATE
)
->namespace(BpmnModelConstants::NS)
->build();

self::$camundaFormHandlerClassAttribute = $typeBuilder->stringAttribute(
self::$formHandlerClassAttribute = $typeBuilder->stringAttribute(
BpmnModelConstants::ATTRIBUTE_FORM_HANDLER_CLASS
)
->namespace(BpmnModelConstants::NS)
->build();

self::$camundaFormKeyAttribute = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_FORM_KEY)
self::$formKeyAttribute = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_FORM_KEY)
->namespace(BpmnModelConstants::NS)
->build();

self::$camundaPriorityAttribute = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_PRIORITY)
self::$priorityAttribute = $typeBuilder->stringAttribute(BpmnModelConstants::ATTRIBUTE_PRIORITY)
->namespace(BpmnModelConstants::NS)
->build();

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Bpmn/Instance/ErrorEventDefinitionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function setError(ErrorInterface $error): void;

public function getErrorCodeVariable(): string;

public function setCamundaErrorCodeVariable(string $errorCodeVariable): void;
public function setErrorCodeVariable(string $errorCodeVariable): void;

public function setErrorMessageVariable(string $errorCauseVariable): void;

Expand Down
8 changes: 3 additions & 5 deletions src/Model/Xml/Impl/Instance/ModelElementInstanceImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ public function getUniqueChildElementByNameNs(
$elementName
);
if (!empty($childElements)) {
ModelUtil::getModelElement($childElements[0], $this->modelInstance);
return ModelUtil::getModelElement($childElements[0], $this->modelInstance);
} else {
return null;
}
}

public function getUniqueChildElementByType(
ModelElementInstanceInterface $elementType
string $elementType
): ?ModelElementInstanceInterface {
$childElements = $this->domElement->getChildElementsByType($this->modelInstance, $elementType);
if (!empty($childElements)) {
ModelUtil::getModelElement($childElements[0], $this->modelInstance);
return ModelUtil::getModelElement($childElements[0], $this->modelInstance);
} else {
return null;
}
Expand Down Expand Up @@ -357,8 +357,6 @@ public function equals(?ModelElementInstanceInterface $obj): bool
{
if ($obj == null) {
return false;
} elseif ($obj == $this) {
return true;
} else {
return $obj->domElement->equals($this->domElement);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Model/Xml/Impl/Type/Attribute/AttributeImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract protected function convertXmlValueToModelValue(?string $rawValue);
/**
* @param mixed $modelValue;
*/
abstract protected function convertModelValueToXmlValue($modelValue): string;
abstract protected function convertModelValueToXmlValue($modelValue): ?string;

public function getOwningElementType(): ModelElementTypeInterface
{
Expand Down Expand Up @@ -68,9 +68,8 @@ public function getValue(ModelElementInstanceInterface $modelElement)

if ($value === null && $this->defaultValue !== null) {
return $this->defaultValue;
} else {
return $this->convertXmlValueToModelValue($value);
}
return $this->convertXmlValueToModelValue($value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Xml/Impl/Type/Attribute/EnumAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected function convertXmlValueToModelValue(?string $rawValue)
/**
* @param mixed $modelValue;
*/
protected function convertModelValueToXmlValue($modelValue): string
protected function convertModelValueToXmlValue($modelValue): ?string
{
$class = new \ReflectionClass($this->type);
$constants = $class->getConstants();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class ChildElementCollectionImpl implements ChildElementCollectionInterface
{
private $childElementTypeClass;
protected $childElementTypeClass;
private $parentElementType;
private $minOccurs = 0;
protected $maxOccurs = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Xml/Impl/Type/Reference/ElementReferenceImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function setReferenceTargetElement(
$referenceTargetElement
): void {
$modelInstance = $referenceSourceParentElement->getModelInstance();
$identifier = $referenceTargetAttribute->getValue($referenceTargetElement);
$identifier = $this->referenceTargetAttribute->getValue($referenceTargetElement);
$existingElement = $modelInstance->getModelElementById($identifier);
if ($existingElement == null || !$existingElement->equals($referenceTargetElement)) {
throw new ModelReferenceException("Cannot create reference to model element");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protected function getView(ModelElementInstanceImpl $referenceSourceParentElemen
}
}
}
return $referenceTargetElements;
}

protected function updateReference(
Expand Down
5 changes: 4 additions & 1 deletion src/Model/Xml/Impl/Util/DomUtil/ElementByNameListFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ public function __construct(string $localName, string $namespaceUri)
$this->namespaceUri = $namespaceUri;
}

public function matches(\DomElement $element): bool
/**
* @param mixed $element
*/
public function matches($element): bool
{
return parent::matches($element) &&
$this->localName == $element->localName &&
Expand Down
5 changes: 4 additions & 1 deletion src/Model/Xml/Impl/Util/DomUtil/ElementByTypeListFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ public function __construct($type, ModelInstanceImpl $modelInstance)
$this->model = $modelInstance;
}

public function matches(\DomElement $element): bool
/**
* @param mixed $element
*/
public function matches($element): bool
{
if (!parent::matches($element)) {
return false;
Expand Down
5 changes: 4 additions & 1 deletion src/Model/Xml/Impl/Util/DomUtil/ElementNodeListFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

class ElementNodeListFilter implements NodeListFilterInterface
{
public function matches(\DomElement $element): bool
/**
* @param mixed $element
*/
public function matches($element): bool
{
return $element->nodeType == XML_ELEMENT_NODE;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Model/Xml/Impl/Util/DomUtil/NodeListFilterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

interface NodeListFilterInterface
{
public function matches(\DomElement $element): bool;
/**
* @param mixed $element
*/
public function matches($element): bool;
}
4 changes: 2 additions & 2 deletions src/Model/Xml/Impl/Util/ModelUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public static function ensureInstanceOf($instance, string $type): void
}
}

public static function valueAsBoolean(string $rawValue): bool
public static function valueAsBoolean(?string $rawValue): bool
{
return json_decode($rawValue);
return $rawValue === null ? false : json_decode($rawValue);
}

public static function valueAsInteger(string $rawValue): int
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Xml/Impl/Util/XmlQName.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class XmlQName
{
public const KNOWN_PREFIXES = [
'http://www.camunda.com/fox' => 'fox',
'http://activiti.org/bpmn' => 'camunda',
'http://camunda.org/schema/1.0/bpmn' => 'camunda',
'http://www.test.com/fox' => 'fox',
'http://activiti.org/bpmn' => 'test',
'http://test.org/schema/1.0/bpmn' => 'test',
'http://www.omg.org/spec/BPMN/20100524/MODEL' => 'bpmn2',
'http://www.omg.org/spec/BPMN/20100524/DI' => 'di',
'http://www.omg.org/spec/DD/20100524/DI' => 'di',
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Xml/Instance/DomElementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ public function setModelElementInstance(ModelElementInstanceInterface $modelElem
public function registerNamespace(?string $prefix, string $namespaceUri);

public function lookupPrefix(string $namespaceUri): string;

public function equals(?DomElementInterface $obj): bool;
}
4 changes: 3 additions & 1 deletion src/Model/Xml/Instance/ModelElementInstanceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getUniqueChildElementByNameNs(
): ?ModelElementInstanceInterface;

public function getUniqueChildElementByType(
ModelElementInstanceInterface $elementType
string $elementType
): ?ModelElementInstanceInterface;

public function setUniqueChildElementByNameNs(ModelElementInstanceInterface $newChild): void;
Expand All @@ -77,4 +77,6 @@ public function insertElementAfter(
): void;

public function updateAfterReplacement(): void;

public function equals(?ModelElementInstanceInterface $obj): bool;
}
4 changes: 2 additions & 2 deletions tests/Xml/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use PHPUnit\Framework\TestCase;
use BpmPlatform\Model\Xml\ModelBuilder;
use BpmPlatform\Model\Xml\TestModel\{
use Tests\Xml\TestModel\{
TestModel,
TestModelConstants
};
use BpmPlatform\Model\Xml\TestModel\Instance\{
use Tests\Xml\TestModel\Instance\{
Animals,
Animal,
Bird,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace BpmPlatform\Model\Xml\TestModel;
namespace Tests\Xml\TestModel;

class Gender
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace BpmPlatform\Model\Xml\TestModel\Instance;
namespace Tests\Xml\TestModel\Instance;

use BpmPlatform\Model\Xml\ModelBuilder;
use BpmPlatform\Model\Xml\Impl\Instance\ModelElementInstanceImpl;
use BpmPlatform\Model\Xml\TestModel\{
use Tests\Xml\TestModel\{
Gender,
TestModelConstants
};
Expand Down Expand Up @@ -157,10 +157,6 @@ public function setAge(int $age): void
self::$ageAttr->setValue($this, $age);
}

public function getRelationshipDefinition() {
return self::$relationshipDefinitionsColl;
}

public function getRelationshipDefinitions(): array
{
return self::$relationshipDefinitionsColl->get($this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace BpmPlatform\Model\Xml\TestModel\Instance;
namespace Tests\Xml\TestModel\Instance;

use BpmPlatform\Model\Xml\Instance\ModelElementInstanceInterface;
use BpmPlatform\Model\Xml\Impl\Type\Attribute\AttributeImpl;
Expand Down
Loading

0 comments on commit 8e30335

Please sign in to comment.