Fr3nch13/CakePHP Utilities

StudentsTableTest extends TestCase
in package

StudentsTable Test

Table of Contents

Properties

$autoFixtures  : bool
By default, all fixtures attached to this class will be truncated and reloaded after each test.
$dropTables  : bool
Control table create/drops on each test method.
$fixtureManager  : FixtureManager|null
The class responsible for managing the creation, loading and removing of fixtures
$Students  : StudentsTable
$_configure  : array<string|int, mixed>
Configure values to restore at end of test.
$_tableLocator  : LocatorInterface|null
Table locator instance
$defaultTable  : string|null
This object's default table alias.
$fixtures  : array<string|int, string>
Fixtures used by this test case.
$fixtureStrategy  : FixtureStrategyInterface|null

Methods

assertDirectoryDoesNotExist()  : void
Asserts that a directory does not exist.
assertDoesNotMatchRegularExpression()  : void
Asserts that a string does not match a given regular expression.
assertEqualsSql()  : void
Assert that a string matches SQL with db-specific characters like quotes removed.
assertEventFired()  : void
Asserts that a global event was fired. You must track events in your event manager for this assertion to work
assertEventFiredWith()  : void
Asserts an event was fired with data
assertFileDoesNotExist()  : void
Asserts that a file does not exist.
assertHtml()  : bool
Asserts HTML tags.
assertMatchesRegularExpression()  : void
Asserts that a string matches a given regular expression.
assertRegExpSql()  : void
Assertion for comparing a regex pattern against a query having its identifiers quoted. It accepts queries quoted with the characters `<` and `>`. If the third parameter is set to true, it will alter the pattern to both accept quoted and unquoted queries
assertTextContains()  : void
Assert that a string contains another string, ignoring differences in newlines.
assertTextEndsNotWith()  : void
Asserts that a string ends not with a given prefix, ignoring differences in newlines.
assertTextEndsWith()  : void
Asserts that a string ends with a given prefix, ignoring differences in newlines.
assertTextEquals()  : void
Assert text equality, ignoring differences in newlines.
assertTextNotContains()  : void
Assert that a text doesn't contain another text, ignoring differences in newlines.
assertTextNotEquals()  : void
Assert text equality, ignoring differences in newlines.
assertTextStartsNotWith()  : void
Asserts that a string starts not with a given prefix, ignoring differences in newlines.
assertTextStartsWith()  : void
Asserts that a string starts with a given prefix, ignoring differences in newlines.
clearPlugins()  : void
Clear all plugins from the global plugin collection.
deprecated()  : void
Helper method for check deprecation methods
fetchTable()  : Table
Convenience method to get a table instance.
getFixtures()  : array<string|int, string>
Defines which fixtures we'll be using.
getMockForModel()  : Table|MockObject
Mock a model, maintain fixtures and table association
getTableLocator()  : LocatorInterface
Gets the table locator.
loadFixtures()  : void
Chooses which fixtures to load for a given test
loadPlugins()  : BaseApplication
Load plugins into a simulated application.
loadRoutes()  : void
Load routes for the application.
removePlugins()  : void
Remove plugins from the global plugin collection.
setAppNamespace()  : string|null
Set the app namespace
setTableLocator()  : $this
Sets the table locator.
setUp()  : void
Connect the model.
skipIf()  : bool
Overrides SimpleTestCase::skipIf to provide a boolean return value
testAssociations()  : void
Test Associations method
testBehaviors()  : void
Test the behaviors
testCheckAddTraitExceptionCheckAdd()  : void
Tests if the fixName method doesn't exist in the Model that is using the CheckAdd Trait
testCheckAddTraitExceptionSlugify()  : void
Tests if the sluggableSlugify method doesn't exist in the Model that is using CheckAdd Trait
testCheckAddTraitFixNameCommon()  : void
Testing fixNameCommon() on the CheckAdd Trait
testClassInstance()  : void
Tests the class name of the Table
testEntity()  : void
Test the entity itself
testInitialize()  : void
Testing a method.
testMemoryBehavior()  : void
Test the memory behavior
testMergeDeleteTraitFindMergeRecords()  : void
Test the apply settting trait itself
testMergeDeleteTraitGetMergeStats()  : void
Test the apply settting trait itself
testMergeDeleteTraitMergeDelete()  : void
Test the apply settting trait itself
withErrorReporting()  : void
Helper method for tests that needs to use error_reporting()
_assertAttributes()  : string|false
Check the attributes as part of an assertTags() check.
_getTableClassName()  : string
Gets the class name for the table.
_normalizePath()  : string
Normalize a path for comparison.
addFixture()  : $this
Adds a fixture to this test case.
assertNotWithinRange()  : void
Compatibility function to test if a value is not between an acceptable range.
assertPathEquals()  : void
Compatibility function to test paths.
assertWithinRange()  : void
Compatibility function to test if a value is between an acceptable range.
getFixtureStrategy()  : FixtureStrategyInterface
Returns fixture strategy used by these tests.
setupFixtures()  : void
Initialized and loads any use fixtures.
skipUnless()  : bool
Compatibility function for skipping.
tearDown()  : void
teardown any static object changes and restore them.
teardownFixtures()  : void
Unloads any use fixtures.

Properties

$autoFixtures

By default, all fixtures attached to this class will be truncated and reloaded after each test.

autoFixtures is only used by deprecated fixture features. This property will be removed in 5.0

public bool $autoFixtures = true

Set this to false to handle manually

$dropTables

Control table create/drops on each test method.

dropTables is only used by deprecated fixture features. This property will be removed in 5.0

public bool $dropTables = false

If true, tables will still be dropped at the end of each test runner execution.

$fixtureManager

The class responsible for managing the creation, loading and removing of fixtures

public static FixtureManager|null $fixtureManager

$_configure

Configure values to restore at end of test.

protected array<string|int, mixed> $_configure = []

$defaultTable

This object's default table alias.

protected string|null $defaultTable = null

$fixtures

Fixtures used by this test case.

protected array<string|int, string> $fixtures = []

Methods

assertDirectoryDoesNotExist()

Asserts that a directory does not exist.

public static assertDirectoryDoesNotExist(string $directory[, string $message = '' ]) : void
Parameters
$directory : string

Directory

$message : string = ''

Message

Tags
throws
InvalidArgumentException
codeCoverageIgnore

assertDoesNotMatchRegularExpression()

Asserts that a string does not match a given regular expression.

public static assertDoesNotMatchRegularExpression(string $pattern, string $string[, string $message = '' ]) : void
Parameters
$pattern : string

Regex pattern

$string : string

String to test

$message : string = ''

Message

Tags
throws
InvalidArgumentException

assertEqualsSql()

Assert that a string matches SQL with db-specific characters like quotes removed.

public assertEqualsSql(string $expected, string $actual[, string $message = '' ]) : void
Parameters
$expected : string

The expected sql

$actual : string

The sql to compare

$message : string = ''

The message to display on failure

assertEventFired()

Asserts that a global event was fired. You must track events in your event manager for this assertion to work

public assertEventFired(string $name[, EventManager|null $eventManager = null ][, string $message = '' ]) : void
Parameters
$name : string

Event name

$eventManager : EventManager|null = null

Event manager to check, defaults to global event manager

$message : string = ''

Assertion failure message

assertEventFiredWith()

Asserts an event was fired with data

public assertEventFiredWith(string $name, string $dataKey, mixed $dataValue[, EventManager|null $eventManager = null ][, string $message = '' ]) : void

If a third argument is passed, that value is used to compare with the value in $dataKey

Parameters
$name : string

Event name

$dataKey : string

Data key

$dataValue : mixed

Data value

$eventManager : EventManager|null = null

Event manager to check, defaults to global event manager

$message : string = ''

Assertion failure message

assertFileDoesNotExist()

Asserts that a file does not exist.

public static assertFileDoesNotExist(string $filename[, string $message = '' ]) : void
Parameters
$filename : string

Filename

$message : string = ''

Message

Tags
throws
InvalidArgumentException
codeCoverageIgnore

assertHtml()

Asserts HTML tags.

public assertHtml(array<string|int, mixed> $expected, string $string[, bool $fullDebug = false ]) : bool

Takes an array $expected and generates a regex from it to match the provided $string. Samples for $expected:

Checks for an input tag with a name attribute (contains any non-empty value) and an id attribute that contains 'my-input':

['input' => ['name', 'id' => 'my-input']]

Checks for two p elements with some text in them:

[
  ['p' => true],
  'textA',
  '/p',
  ['p' => true],
  'textB',
  '/p'
]

You can also specify a pattern expression as part of the attribute values, or the tag being defined, if you prepend the value with preg: and enclose it with slashes, like so:

[
  ['input' => ['name', 'id' => 'preg:/FieldName\d+/']],
  'preg:/My\s+field/'
]

Important: This function is very forgiving about whitespace and also accepts any permutation of attribute order. It will also allow whitespace between specified tags.

Parameters
$expected : array<string|int, mixed>

An array, see above

$string : string

An HTML/XHTML/XML string

$fullDebug : bool = false

Whether more verbose output should be used.

Return values
bool

assertMatchesRegularExpression()

Asserts that a string matches a given regular expression.

public static assertMatchesRegularExpression(string $pattern, string $string[, string $message = '' ]) : void
Parameters
$pattern : string

Regex pattern

$string : string

String to test

$message : string = ''

Message

Tags
throws
InvalidArgumentException
codeCoverageIgnore

assertRegExpSql()

Assertion for comparing a regex pattern against a query having its identifiers quoted. It accepts queries quoted with the characters `<` and `>`. If the third parameter is set to true, it will alter the pattern to both accept quoted and unquoted queries

public assertRegExpSql(string $pattern, string $actual[, bool $optional = false ]) : void
Parameters
$pattern : string

The expected sql pattern

$actual : string

The sql to compare

$optional : bool = false

Whether quote characters (marked with <>) are optional

assertTextContains()

Assert that a string contains another string, ignoring differences in newlines.

public assertTextContains(string $needle, string $haystack[, string $message = '' ][, bool $ignoreCase = false ]) : void

Helpful for doing cross platform tests of blocks of text.

Parameters
$needle : string

The string to search for.

$haystack : string

The string to search through.

$message : string = ''

The message to display on failure.

$ignoreCase : bool = false

Whether the search should be case-sensitive.

assertTextEndsNotWith()

Asserts that a string ends not with a given prefix, ignoring differences in newlines.

public assertTextEndsNotWith(string $suffix, string $string[, string $message = '' ]) : void

Helpful for doing cross platform tests of blocks of text.

Parameters
$suffix : string

The suffix to not find.

$string : string

The string to search.

$message : string = ''

The message to use for failure.

assertTextEndsWith()

Asserts that a string ends with a given prefix, ignoring differences in newlines.

public assertTextEndsWith(string $suffix, string $string[, string $message = '' ]) : void

Helpful for doing cross platform tests of blocks of text.

Parameters
$suffix : string

The suffix to find.

$string : string

The string to search.

$message : string = ''

The message to use for failure.

assertTextEquals()

Assert text equality, ignoring differences in newlines.

public assertTextEquals(string $expected, string $result[, string $message = '' ]) : void

Helpful for doing cross platform tests of blocks of text.

Parameters
$expected : string

The expected value.

$result : string

The actual value.

$message : string = ''

The message to use for failure.

assertTextNotContains()

Assert that a text doesn't contain another text, ignoring differences in newlines.

public assertTextNotContains(string $needle, string $haystack[, string $message = '' ][, bool $ignoreCase = false ]) : void

Helpful for doing cross platform tests of blocks of text.

Parameters
$needle : string

The string to search for.

$haystack : string

The string to search through.

$message : string = ''

The message to display on failure.

$ignoreCase : bool = false

Whether the search should be case-sensitive.

assertTextNotEquals()

Assert text equality, ignoring differences in newlines.

public assertTextNotEquals(string $expected, string $result[, string $message = '' ]) : void

Helpful for doing cross platform tests of blocks of text.

Parameters
$expected : string

The expected value.

$result : string

The actual value.

$message : string = ''

The message to use for failure.

assertTextStartsNotWith()

Asserts that a string starts not with a given prefix, ignoring differences in newlines.

public assertTextStartsNotWith(string $prefix, string $string[, string $message = '' ]) : void

Helpful for doing cross platform tests of blocks of text.

Parameters
$prefix : string

The prefix to not find.

$string : string

The string to search.

$message : string = ''

The message to use for failure.

assertTextStartsWith()

Asserts that a string starts with a given prefix, ignoring differences in newlines.

public assertTextStartsWith(string $prefix, string $string[, string $message = '' ]) : void

Helpful for doing cross platform tests of blocks of text.

Parameters
$prefix : string

The prefix to check for.

$string : string

The string to search in.

$message : string = ''

The message to use for failure.

clearPlugins()

Clear all plugins from the global plugin collection.

public clearPlugins() : void

Useful in test case teardown methods.

deprecated()

Helper method for check deprecation methods

public deprecated(callable $callable) : void
Parameters
$callable : callable

callable function that will receive asserts

fetchTable()

Convenience method to get a table instance.

public fetchTable([string|null $alias = null ][, array<string, mixed> $options = [] ]) : Table
Parameters
$alias : string|null = null

The alias name you want to get. Should be in CamelCase format. If null then the value of $defaultTable property is used.

$options : array<string, mixed> = []

The options you want to build the table with. If a table has already been loaded the registry options will be ignored.

Tags
throws
CakeException

If $alias argument and $defaultTable property both are null.

see
TableLocator::get()
since
4.3.0
Return values
Table

getFixtures()

Defines which fixtures we'll be using.

public getFixtures() : array<string|int, string>
Return values
array<string|int, string>

getMockForModel()

Mock a model, maintain fixtures and table association

public getMockForModel(string $alias[, array<string|int, string> $methods = [] ][, array<string, mixed> $options = [] ]) : Table|MockObject
Parameters
$alias : string

The model to get a mock for.

$methods : array<string|int, string> = []

The list of methods to mock

$options : array<string, mixed> = []

The config data for the mock's constructor.

Tags
throws
MissingTableClassException
Return values
Table|MockObject

loadFixtures()

Chooses which fixtures to load for a given test

public loadFixtures() : void

Disabling auto-fixtures is deprecated and only available using FixtureInjector fixture system.

Each parameter is a model name that corresponds to a fixture, i.e. 'Posts', 'Authors', etc. Passing no parameters will cause all fixtures on the test case to load.

Tags
see
TestCase::$autoFixtures
throws
RuntimeException

when no fixture manager is available.

loadPlugins()

Load plugins into a simulated application.

public loadPlugins([array<string, mixed> $plugins = [] ]) : BaseApplication

Useful to test how plugins being loaded/not loaded interact with other elements in CakePHP or applications.

Parameters
$plugins : array<string, mixed> = []

List of Plugins to load.

Return values
BaseApplication

loadRoutes()

Load routes for the application.

public loadRoutes([array<string|int, mixed>|null $appArgs = null ]) : void

If no application class can be found an exception will be raised. Routes for plugins will not be loaded. Use loadPlugins() or use Cake\TestSuite\IntegrationTestCaseTrait to better simulate all routes and plugins being loaded.

Parameters
$appArgs : array<string|int, mixed>|null = null

Constructor parameters for the application class.

Tags
since
4.0.1

removePlugins()

Remove plugins from the global plugin collection.

public removePlugins([array<string|int, string> $names = [] ]) : void

Useful in test case teardown methods.

Parameters
$names : array<string|int, string> = []

A list of plugins you want to remove.

setAppNamespace()

Set the app namespace

public static setAppNamespace([string $appNamespace = 'TestApp' ]) : string|null
Parameters
$appNamespace : string = 'TestApp'

The app namespace, defaults to "TestApp".

Return values
string|null

The previous app namespace or null if not set.

skipIf()

Overrides SimpleTestCase::skipIf to provide a boolean return value

public skipIf(bool $shouldSkip[, string $message = '' ]) : bool
Parameters
$shouldSkip : bool

Whether the test should be skipped.

$message : string = ''

The message to display.

Return values
bool

testAssociations()

Test Associations method

public testAssociations() : void

testCheckAddTraitExceptionCheckAdd()

Tests if the fixName method doesn't exist in the Model that is using the CheckAdd Trait

public testCheckAddTraitExceptionCheckAdd() : void

testCheckAddTraitExceptionSlugify()

Tests if the sluggableSlugify method doesn't exist in the Model that is using CheckAdd Trait

public testCheckAddTraitExceptionSlugify() : void

testCheckAddTraitFixNameCommon()

Testing fixNameCommon() on the CheckAdd Trait

public testCheckAddTraitFixNameCommon() : void

testClassInstance()

Tests the class name of the Table

public testClassInstance() : void

testMemoryBehavior()

Test the memory behavior

public testMemoryBehavior() : void

testMergeDeleteTraitFindMergeRecords()

Test the apply settting trait itself

public testMergeDeleteTraitFindMergeRecords() : void

testMergeDeleteTraitGetMergeStats()

Test the apply settting trait itself

public testMergeDeleteTraitGetMergeStats() : void

testMergeDeleteTraitMergeDelete()

Test the apply settting trait itself

public testMergeDeleteTraitMergeDelete() : void

withErrorReporting()

Helper method for tests that needs to use error_reporting()

public withErrorReporting(int $errorLevel, callable $callable) : void
Parameters
$errorLevel : int

value of error_reporting() that needs to use

$callable : callable

callable function that will receive asserts

_assertAttributes()

Check the attributes as part of an assertTags() check.

protected _assertAttributes(array<string, mixed> $assertions, string $string[, bool $fullDebug = false ][, array<string|int, mixed>|string $regex = '' ]) : string|false
Parameters
$assertions : array<string, mixed>

Assertions to run.

$string : string

The HTML string to check.

$fullDebug : bool = false

Whether more verbose output should be used.

$regex : array<string|int, mixed>|string = ''

Full regexp from assertHtml

Return values
string|false

_getTableClassName()

Gets the class name for the table.

protected _getTableClassName(string $alias, array<string, mixed> $options) : string
Parameters
$alias : string

The model to get a mock for.

$options : array<string, mixed>

The config data for the mock's constructor.

Tags
throws
MissingTableClassException
psalm-return

class-string<\Cake\ORM\Table>

Return values
string

_normalizePath()

Normalize a path for comparison.

protected _normalizePath(string $path) : string
Parameters
$path : string

Path separated by "/" slash.

Return values
string

Normalized path separated by DIRECTORY_SEPARATOR.

addFixture()

Adds a fixture to this test case.

protected addFixture(string $fixture) : $this

Examples:

  • core.Tags
  • app.MyRecords
  • plugin.MyPluginName.MyModelName

Use this method inside your test cases' method to build up the fixture list.

Parameters
$fixture : string

Fixture

Return values
$this

assertNotWithinRange()

Compatibility function to test if a value is not between an acceptable range.

protected static assertNotWithinRange(float $expected, float $result, float $margin[, string $message = '' ]) : void
Parameters
$expected : float
$result : float
$margin : float

the rage of acceptation

$message : string = ''

the text to display if the assertion is not correct

assertPathEquals()

Compatibility function to test paths.

protected static assertPathEquals(string $expected, string $result[, string $message = '' ]) : void
Parameters
$expected : string
$result : string
$message : string = ''

the text to display if the assertion is not correct

assertWithinRange()

Compatibility function to test if a value is between an acceptable range.

protected static assertWithinRange(float $expected, float $result, float $margin[, string $message = '' ]) : void
Parameters
$expected : float
$result : float
$margin : float

the rage of acceptation

$message : string = ''

the text to display if the assertion is not correct

setupFixtures()

Initialized and loads any use fixtures.

protected setupFixtures() : void

skipUnless()

Compatibility function for skipping.

protected skipUnless(bool $condition[, string $message = '' ]) : bool
Parameters
$condition : bool

Condition to trigger skipping

$message : string = ''

Message for skip

Return values
bool

tearDown()

teardown any static object changes and restore them.

protected tearDown() : void

teardownFixtures()

Unloads any use fixtures.

protected teardownFixtures() : void

        
On this page

Search results