Skip to content

FragmentTestCase

FragmentTestCase is the base class for all fragment tests and provides the necessary assertions

abstract class FragmentTestCase extends PhpUnitTestCase implements IFragmentTestCase

ExtendsPhpUnitTestCase
ImplementsIFragmentTestCase
Since1.0.0
SourceTesting/FragmentTestCase.php
PropertyTypeDescription
$actionNamemixedprotected.
$containermixedprotected.
$contextNamemixedprotected.
$moduleNamemixedprotected.
$requestMethodmixedprotected.
$validationSuccessmixedprotected.
MethodDescription
appendAttribute(string $name, mixed $value): void
appendAttributeByRef(string $name, mixed &$value): void
applyRequestParameters(array<string, mixed> $parameters, bool $clearFirst = false): voidHelper: apply runtime parameters directly to canonical WebRequest (replaces deprecated DataHolder usage).
assertContainerAttributeEquals(mixed $expected, string $attributeName, string $namespace = null, string $message = 'Failed asserting that the attribute <%1$s/%2$s> has the v…', float $delta = 0, integer $maxDepth = 10, boolean $canonicalizeEol = false): voidassert that the test container has a given attribute with the expected value
assertContainerAttributeExists(string $attributeName, string $namespace = null, string $message = 'Failed asserting that the container has an attribute name…'): voidassert that the exectionContainer has a given attribute
clearAttributes(): void
clearSingletonModels(): voidDrop the shared model instances, so a test that mutated one does not hand it to the next.
createActionInstance(): Actioncreates an Action instance and initializes it with this testcase’s init context
[`createRequestDataHolder(array<intstring, mixed> $arguments = [], mixed $type = null): array<int
getAttribute(string $name, mixed $default = null): mixed
getAttributeNames(): array<int, string>
getAttributes(): array<string, mixed>
getContext(): ContextReturn the context defined for this test (or the default one).
hasAttribute(string $name): bool
normalizeViewName(string $shortName): stringnormalizes a viewname according to the configured rules Please do not use this method, it exists only for internal purposes and will be removed ASAP.
removeAttribute(string $name): mixed
setArguments(mixed $arguments): void
setAttribute(string $name, mixed $value): void
setAttributeByRef(string $name, mixed &$value): void
setAttributes(array<string, mixed> $attributes): void
setAttributesByRef(array<string, mixed> &$attributes): void
setOutputType(OutputType $outputType): void
setRequestData(mixed $rd): void
setRequestMethod(string $method): void
setUp(): voidpreviously created an execution container per test; now no-op
tearDown(): voidunsets legacy container (no longer applicable)

protected function appendAttribute(string $name, mixed $value): void

ParameterTypeDescription
$namestring
$valuemixed

protected function appendAttributeByRef(string $name, mixed &$value): void

ParameterTypeDescription
$namestring
$valuemixed

protected function applyRequestParameters(array<string, mixed> $parameters, bool $clearFirst = false): void

Helper: apply runtime parameters directly to canonical WebRequest (replaces deprecated DataHolder usage).

ParameterTypeDescription
$parametersarray``<``string``, ``mixed``>
$clearFirstbool

protected function assertContainerAttributeEquals(mixed $expected, string $attributeName, string $namespace = null, string $message = 'Failed asserting that the attribute <%1$s/%2$s> has the v…', float $delta = 0, integer $maxDepth = 10, boolean $canonicalizeEol = false): void

assert that the test container has a given attribute with the expected value

ParameterTypeDescription
$expectedmixedthe expected attribute value
$attributeNamestringthe attribute name
$namespacestringthe attribute namespace
$messagestringan optional message to display if the test fails
$deltafloat
$maxDepthinteger
$canonicalizeEolboolean

protected function assertContainerAttributeExists(string $attributeName, string $namespace = null, string $message = 'Failed asserting that the container has an attribute name…'): void

assert that the exectionContainer has a given attribute

an optional message to display if the test fails

ParameterTypeDescription
$attributeNamestringthe attribute name
$namespacestringthe attribute namespace
$messagestringan optional message to display if the test fails

protected function clearAttributes(): void

protected function clearSingletonModels(): void

Drop the shared model instances, so a test that mutated one does not hand it to the next.

The model locator owns those instances and clears them itself at a worker request boundary, so this asks it rather than reaching into the context.

protected function createActionInstance(): Action

creates an Action instance and initializes it with this testcase’s init context

Returns Action

protected function createRequestDataHolder(array<int|string, mixed> $arguments = [], mixed $type = null): array<int|string, mixed>

(Deprecated) Legacy helper that previously created an RequestDataHolder instance.

ParameterTypeDescription
$arguments`array<int“string, mixed>`
$typemixed

Returns array``<``int``|``string``, ``mixed``>

protected function getAttribute(string $name, mixed $default = null): mixed

ParameterTypeDescription
$namestring
$defaultmixed

Returns mixed

protected function getAttributeNames(): array<int, string>

Returns array``<``int``, ``string``>

protected function getAttributes(): array<string, mixed>

Returns array``<``string``, ``mixed``>

public function getContext(): Context

Return the context defined for this test (or the default one).

Returns Context — The context instance defined for this test.

protected function hasAttribute(string $name): bool

ParameterTypeDescription
$namestring

Returns bool

protected function normalizeViewName(string $shortName): string

normalizes a viewname according to the configured rules Please do not use this method, it exists only for internal purposes and will be removed ASAP.

the short view name

ParameterTypeDescription
$shortNamestringthe short view name

Returns string — the full view name

protected function removeAttribute(string $name): mixed

ParameterTypeDescription
$namestring

Returns mixed

protected function setArguments(mixed $arguments): void

ParameterTypeDescription
$argumentsmixed

protected function setAttribute(string $name, mixed $value): void

ParameterTypeDescription
$namestring
$valuemixed

protected function setAttributeByRef(string $name, mixed &$value): void

ParameterTypeDescription
$namestring
$valuemixed

protected function setAttributes(array<string, mixed> $attributes): void

ParameterTypeDescription
$attributesarray``<``string``, ``mixed``>

protected function setAttributesByRef(array<string, mixed> &$attributes): void

ParameterTypeDescription
$attributesarray``<``string``, ``mixed``>

protected function setOutputType(OutputType $outputType): void

ParameterTypeDescription
$outputTypeOutputType

protected function setRequestData(mixed $rd): void

ParameterTypeDescription
$rdmixed

protected function setRequestMethod(string $method): void

ParameterTypeDescription
$methodstring

public function setUp(): void

previously created an execution container per test; now no-op

public function tearDown(): void

unsets legacy container (no longer applicable)

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
anything()Assert
arrayHasKey()Assert
assertArrayHasKey()AssertAsserts that an array has a specified key.
assertArrayIsEqualToArrayIgnoringListOfKeys()AssertAsserts that two arrays are equal while ignoring a list of keys.
assertArrayIsEqualToArrayOnlyConsideringListOfKeys()AssertAsserts that two arrays are equal while only considering a list of keys.
assertArrayIsIdenticalToArrayIgnoringListOfKeys()AssertAsserts that two arrays are equal while ignoring a list of keys.
assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys()AssertAsserts that two arrays are identical while only considering a list of keys.
assertArrayNotHasKey()AssertAsserts that an array does not have a specified key.
assertArraysAreEqual()AssertAssert that two arrays are equal.
assertArraysAreEqualIgnoringOrder()AssertAssert that two arrays are equal while ignoring the order of their values.
assertArraysAreIdentical()AssertAssert that two arrays are identical.
assertArraysAreIdenticalIgnoringOrder()AssertAssert that two arrays are identical while ignoring the order of their values.
assertArraysHaveEqualValues()AssertAssert that two arrays have equal values.
assertArraysHaveEqualValuesIgnoringOrder()AssertAssert that two arrays have equal values while ignoring the order of these values.
assertArraysHaveIdenticalValues()AssertAssert that two arrays have identical values.
assertArraysHaveIdenticalValuesIgnoringOrder()AssertAssert that two arrays have identical values while ignoring the order of these values.
assertContains()AssertAsserts that a haystack contains a needle.
assertContainsEquals()Assert
assertContainsNotOnlyArray()AssertAsserts that a haystack does not contain only values of type array.
assertContainsNotOnlyBool()AssertAsserts that a haystack does not contain only values of type bool.
assertContainsNotOnlyCallable()AssertAsserts that a haystack does not contain only values of type callable.
assertContainsNotOnlyClosedResource()AssertAsserts that a haystack does not contain only values of type closed resource.
assertContainsNotOnlyFloat()AssertAsserts that a haystack does not contain only values of type float.
assertContainsNotOnlyInstancesOf()AssertAsserts that a haystack does not contain only instances of a specified interface or class name.
assertContainsNotOnlyInt()AssertAsserts that a haystack does not contain only values of type int.
assertContainsNotOnlyIterable()AssertAsserts that a haystack does not contain only values of type iterable.
assertContainsNotOnlyNull()AssertAsserts that a haystack does not contain only values of type null.
assertContainsNotOnlyNumeric()AssertAsserts that a haystack does not contain only values of type numeric.
assertContainsNotOnlyObject()AssertAsserts that a haystack does not contain only values of type object.
assertContainsNotOnlyResource()AssertAsserts that a haystack does not contain only values of type resource.
assertContainsNotOnlyScalar()AssertAsserts that a haystack does not contain only values of type scalar.
assertContainsNotOnlyString()AssertAsserts that a haystack does not contain only values of type string.
assertContainsOnlyArray()AssertAsserts that a haystack contains only values of type array.
assertContainsOnlyBool()AssertAsserts that a haystack contains only values of type bool.
assertContainsOnlyCallable()AssertAsserts that a haystack contains only values of type callable.
assertContainsOnlyClosedResource()AssertAsserts that a haystack contains only values of type closed resource.
assertContainsOnlyFloat()AssertAsserts that a haystack contains only values of type float.
assertContainsOnlyInstancesOf()AssertAsserts that a haystack contains only instances of a specified interface or class name.
assertContainsOnlyInt()AssertAsserts that a haystack contains only values of type int.
assertContainsOnlyIterable()AssertAsserts that a haystack contains only values of type iterable.
assertContainsOnlyNull()AssertAsserts that a haystack contains only values of type null.
assertContainsOnlyNumeric()AssertAsserts that a haystack contains only values of type numeric.
assertContainsOnlyObject()AssertAsserts that a haystack contains only values of type object.
assertContainsOnlyResource()AssertAsserts that a haystack contains only values of type resource.
assertContainsOnlyScalar()AssertAsserts that a haystack contains only values of type scalar.
assertContainsOnlyString()AssertAsserts that a haystack contains only values of type string.
assertCount()AssertAsserts the number of elements of an array, Countable or Traversable.
assertDirectoryDoesNotExist()AssertAsserts that a directory does not exist.
assertDirectoryExists()AssertAsserts that a directory exists.
assertDirectoryIsNotReadable()AssertAsserts that a directory exists and is not readable.
assertDirectoryIsNotWritable()AssertAsserts that a directory exists and is not writable.
assertDirectoryIsReadable()AssertAsserts that a directory exists and is readable.
assertDirectoryIsWritable()AssertAsserts that a directory exists and is writable.
assertDoesNotMatchRegularExpression()AssertAsserts that a string does not match a given regular expression.
assertEmpty()AssertAsserts that a variable is empty.
assertEquals()AssertAsserts that two variables are equal.
assertEqualsCanonicalizing()AssertAsserts that two variables are equal (canonicalizing).
assertEqualsIgnoringCase()AssertAsserts that two variables are equal (ignoring case).
assertEqualsWithDelta()AssertAsserts that two variables are equal (with delta).
assertFalse()AssertAsserts that a condition is false.
assertFileDoesNotExist()AssertAsserts that a file does not exist.
assertFileEquals()AssertAsserts that the contents of one file is equal to the contents of another file.
assertFileEqualsCanonicalizing()AssertAsserts that the contents of one file is equal to the contents of another file (canonicalizing).
assertFileEqualsFileIgnoringWhitespace()AssertAsserts that the contents of one file is equal to the contents of another file (ignoring whitespace).
assertFileEqualsIgnoringCase()AssertAsserts that the contents of one file is equal to the contents of another file (ignoring case).
assertFileExists()AssertAsserts that a file exists.
assertFileIsNotReadable()AssertAsserts that a file exists and is not readable.
assertFileIsNotWritable()AssertAsserts that a file exists and is not writable.
assertFileIsReadable()AssertAsserts that a file exists and is readable.
assertFileIsWritable()AssertAsserts that a file exists and is writable.
assertFileMatchesFormat()AssertAsserts that a string matches a given format string.
assertFileMatchesFormatFile()AssertAsserts that a string matches a given format string.
assertFileNotEquals()AssertAsserts that the contents of one file is not equal to the contents of another file.
assertFileNotEqualsCanonicalizing()AssertAsserts that the contents of one file is not equal to the contents of another file (canonicalizing).
assertFileNotEqualsFileIgnoringWhitespace()AssertAsserts that the contents of one file is not equal to the contents of another file (ignoring whitespace).
assertFileNotEqualsIgnoringCase()AssertAsserts that the contents of one file is not equal to the contents of another file (ignoring case).
assertFinite()AssertAsserts that a variable is finite.
assertGreaterThan()AssertAsserts that a value is greater than another value.
assertGreaterThanOrEqual()AssertAsserts that a value is greater than or equal to another value.
assertInfinite()AssertAsserts that a variable is infinite.
assertInstanceOf()AssertAsserts that a variable is of a given type.
assertIsArray()AssertAsserts that a variable is of type array.
assertIsBool()AssertAsserts that a variable is of type bool.
assertIsCallable()AssertAsserts that a variable is of type callable.
assertIsClosedResource()AssertAsserts that a variable is of type resource and is closed.
assertIsFloat()AssertAsserts that a variable is of type float.
assertIsInt()AssertAsserts that a variable is of type int.
assertIsIterable()AssertAsserts that a variable is of type iterable.
assertIsList()Assert
assertIsNotArray()AssertAsserts that a variable is not of type array.
assertIsNotBool()AssertAsserts that a variable is not of type bool.
assertIsNotCallable()AssertAsserts that a variable is not of type callable.
assertIsNotClosedResource()AssertAsserts that a variable is not of type resource.
assertIsNotFloat()AssertAsserts that a variable is not of type float.
assertIsNotInt()AssertAsserts that a variable is not of type int.
assertIsNotIterable()AssertAsserts that a variable is not of type iterable.
assertIsNotNumeric()AssertAsserts that a variable is not of type numeric.
assertIsNotObject()AssertAsserts that a variable is not of type object.
assertIsNotReadable()AssertAsserts that a file/dir exists and is not readable.
assertIsNotResource()AssertAsserts that a variable is not of type resource.
assertIsNotScalar()AssertAsserts that a variable is not of type scalar.
assertIsNotString()AssertAsserts that a variable is not of type string.
assertIsNotWritable()AssertAsserts that a file/dir exists and is not writable.
assertIsNumeric()AssertAsserts that a variable is of type numeric.
assertIsObject()AssertAsserts that a variable is of type object.
assertIsReadable()AssertAsserts that a file/dir is readable.
assertIsResource()AssertAsserts that a variable is of type resource.
assertIsScalar()AssertAsserts that a variable is of type scalar.
assertIsString()AssertAsserts that a variable is of type string.
assertIsWritable()AssertAsserts that a file/dir exists and is writable.
assertJson()AssertAsserts that a string is a valid JSON string.
assertJsonFileEqualsJsonFile()AssertAsserts that two JSON files are equal.
assertJsonFileNotEqualsJsonFile()AssertAsserts that two JSON files are not equal.
assertJsonStringEqualsJsonFile()AssertAsserts that the generated JSON encoded object and the content of the given file are equal.
assertJsonStringEqualsJsonString()AssertAsserts that two given JSON encoded objects or arrays are equal.
assertJsonStringNotEqualsJsonFile()AssertAsserts that the generated JSON encoded object and the content of the given file are not equal.
assertJsonStringNotEqualsJsonString()AssertAsserts that two given JSON encoded objects or arrays are not equal.
assertLessThan()AssertAsserts that a value is smaller than another value.
assertLessThanOrEqual()AssertAsserts that a value is smaller than or equal to another value.
assertMatchesRegularExpression()AssertAsserts that a string matches a given regular expression.
assertNan()AssertAsserts that a variable is nan.
assertNotContains()AssertAsserts that a haystack does not contain a needle.
assertNotContainsEquals()Assert
assertNotCount()AssertAsserts the number of elements of an array, Countable or Traversable.
assertNotEmpty()AssertAsserts that a variable is not empty.
assertNotEquals()AssertAsserts that two variables are not equal.
assertNotEqualsCanonicalizing()AssertAsserts that two variables are not equal (canonicalizing).
assertNotEqualsIgnoringCase()AssertAsserts that two variables are not equal (ignoring case).
assertNotEqualsWithDelta()AssertAsserts that two variables are not equal (with delta).
assertNotFalse()AssertAsserts that a condition is not false.
assertNotInstanceOf()AssertAsserts that a variable is not of a given type.
assertNotNull()AssertAsserts that a variable is not null.
assertNotSame()AssertAsserts that two variables do not have the same type and value.
assertNotSameSize()AssertAssert that the size of two arrays (or Countable or Traversable objects) is not the same.
assertNotTrue()AssertAsserts that a condition is not true.
assertNull()AssertAsserts that a variable is null.
assertObjectEquals()Assert
assertObjectHasProperty()AssertAsserts that an object has a specified property.
assertObjectNotEquals()Assert
assertObjectNotHasProperty()AssertAsserts that an object does not have a specified property.
assertSame()AssertAsserts that two variables have the same type and value.
assertSameSize()AssertAssert that the size of two arrays (or Countable or Traversable objects) is the same.
assertStringContainsString()Assert
assertStringContainsStringIgnoringCase()Assert
assertStringContainsStringIgnoringLineEndings()Assert
assertStringEndsNotWith()AssertAsserts that a string ends not with a given suffix.
assertStringEndsWith()AssertAsserts that a string ends with a given suffix.
assertStringEqualsFile()AssertAsserts that the contents of a string is equal to the contents of a file.
assertStringEqualsFileCanonicalizing()AssertAsserts that the contents of a string is equal to the contents of a file (canonicalizing).
assertStringEqualsFileIgnoringCase()AssertAsserts that the contents of a string is equal to the contents of a file (ignoring case).
assertStringEqualsFileIgnoringWhitespace()AssertAsserts that the contents of a string is equal to the contents of a file (ignoring whitespace).
assertStringEqualsStringIgnoringLineEndings()AssertAsserts that two strings are equal except for line endings.
assertStringEqualsStringIgnoringWhitespace()AssertAsserts that two strings are equal ignoring whitespace.
assertStringMatchesFormat()AssertAsserts that a string matches a given format string.
assertStringMatchesFormatFile()AssertAsserts that a string matches a given format file.
assertStringNotContainsString()Assert
assertStringNotContainsStringIgnoringCase()Assert
assertStringNotEqualsFile()AssertAsserts that the contents of a string is not equal to the contents of a file.
assertStringNotEqualsFileCanonicalizing()AssertAsserts that the contents of a string is not equal to the contents of a file (canonicalizing).
assertStringNotEqualsFileIgnoringCase()AssertAsserts that the contents of a string is not equal to the contents of a file (ignoring case).
assertStringNotEqualsFileIgnoringWhitespace()AssertAsserts that the contents of a string is not equal to the contents of a file (ignoring whitespace).
assertStringNotEqualsStringIgnoringWhitespace()AssertAsserts that two strings are not equal ignoring whitespace.
assertStringStartsNotWith()AssertAsserts that a string starts not with a given prefix.
assertStringStartsWith()AssertAsserts that a string starts with a given prefix.
assertThat()AssertEvaluates a PHPUnit\Framework\Constraint matcher object.
assertTrue()AssertAsserts that a condition is true.
assertXmlFileEqualsXmlFile()AssertAsserts that two XML files are equal, ignoring comments.
assertXmlFileEqualsXmlFileConsideringComments()AssertAsserts that two XML files are equal, considering comments.
assertXmlFileNotEqualsXmlFile()AssertAsserts that two XML files are not equal, ignoring comments.
assertXmlFileNotEqualsXmlFileConsideringComments()AssertAsserts that two XML files are not equal, considering comments.
assertXmlStringEqualsXmlFile()AssertAsserts that two XML documents are equal, ignoring comments.
assertXmlStringEqualsXmlFileConsideringComments()AssertAsserts that two XML documents are equal, considering comments.
assertXmlStringEqualsXmlString()AssertAsserts that two XML documents are equal, ignoring comments.
assertXmlStringEqualsXmlStringConsideringComments()AssertAsserts that two XML documents are equal, considering comments.
assertXmlStringNotEqualsXmlFile()AssertAsserts that two XML documents are not equal, ignoring comments.
assertXmlStringNotEqualsXmlFileConsideringComments()AssertAsserts that two XML documents are not equal, considering comments.
assertXmlStringNotEqualsXmlString()AssertAsserts that two XML documents are not equal, ignoring comments.
assertXmlStringNotEqualsXmlStringConsideringComments()AssertAsserts that two XML documents are not equal, considering comments.
callback()Assert
containsEqual()Assert
containsIdentical()Assert
containsOnlyArray()Assert
containsOnlyBool()Assert
containsOnlyCallable()Assert
containsOnlyClosedResource()Assert
containsOnlyFloat()Assert
containsOnlyInstancesOf()Assert
containsOnlyInt()Assert
containsOnlyIterable()Assert
containsOnlyNull()Assert
containsOnlyNumeric()Assert
containsOnlyObject()Assert
containsOnlyResource()Assert
containsOnlyScalar()Assert
containsOnlyString()Assert
countOf()Assert
createAttribute()PhpUnitTestCaseCreate attributes for custom annotations
directoryExists()Assert
equalTo()Assert
equalToCanonicalizing()Assert
equalToIgnoringCase()Assert
equalToWithDelta()Assert
fail()AssertFails a test with the given message.
fileExists()Assert
getClearCache()PhpUnitTestCasecheck whether to clear the cache in isolated tests
getCount()AssertReturn the current assertion count.
getIsolationDefaultContext()PhpUnitTestCaseget the default context to use in isolated tests
getIsolationEnvironment()PhpUnitTestCaseget the environment to bootstrap in isolated tests
greaterThan()Assert
greaterThanOrEqual()Assert
identicalTo()Assert
isArray()Assert
isBool()Assert
isCallable()Assert
isClosedResource()Assert
isEmpty()Assert
isFalse()Assert
isFinite()Assert
isFloat()Assert
isInfinite()Assert
isInstanceOf()Assert
isInt()Assert
isIterable()Assert
isJson()Assert
isList()Assert
isNan()Assert
isNull()Assert
isNumeric()Assert
isObject()Assert
isReadable()Assert
isResource()Assert
isScalar()Assert
isString()Assert
isTrue()Assert
isWritable()Assert
lessThan()Assert
lessThanOrEqual()Assert
logicalAnd()Assert
logicalNot()Assert
logicalOr()Assert
logicalXor()Assert
markTestIncomplete()AssertMark the test as incomplete.
markTestSkipped()AssertMark the test as skipped.
matches()Assert
matchesRegularExpression()Assert
objectEquals()Assert
resetCount()AssertReset the assertion counter.
setClearCache()PhpUnitTestCaseset whether the cache should be cleared for the isolated subprocess
setIsolationDefaultContext()PhpUnitTestCaseset the default context to use in isolated tests
setIsolationEnvironment()PhpUnitTestCaseset the environment to bootstrap in isolated tests
setUpBeforeClass()TestCaseThis method is called before the first test of this test class is run.
stringContains()Assert
stringEndsWith()Assert
stringEqualsStringIgnoringLineEndings()Assert
stringEqualsStringIgnoringWhitespace()Assert
stringStartsWith()Assert
tearDownAfterClass()TestCaseThis method is called after the last test of this test class is run.