SapphireTest
class SapphireTest extends TestCase implements TestOnly
Test case class for the Sapphire framework.
Sapphire unit testing is based on PHPUnit, but provides a number of hooks into our data model that make it easier to work with.
This class should not be used anywhere outside of unit tests, as phpunit may not be installed in production sites.
Methods
No description
Gets illegal extensions for this class
Gets required extensions for this class
No description
No description
No description
No description
Called once per test case ({@link SapphireTest} subclass).
tearDown method that's called once per test class rather once per test method.
Clear all fixtures which were previously loaded through {@link loadFixture()}
No description
No description
Clear the log of emails sent
Search for an email that was sent.
Assert that the matching email was sent since the last call to clearEmails() All of the parameters can either be a string, or, if they start with "/", a PREG-compatible regular expression.
Assert that the given {@link SS_List} includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
Asserts that no items in a given list appear in the given dataobject list
Assert that the given {@link SS_List} includes only DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
Assert that the every record in the given {@link SS_List} matches the given key-value pairs.
Asserts that two SQL queries are equivalent
Asserts that a SQL query contains a SQL fragment
Asserts that a SQL query contains a SQL fragment
Start test environment
Reset the testing database's schema, but only if it is active
A wrapper for automatically performing callbacks as a user with a specific permission
Create a member and group with the given permission code, and log in with it.
Log out the current user
Return all extra objects to scaffold for this test
Get additional controller classes to register routes for
Details
at line 174
static TempDatabase
tempDB()
at line 187
static array
getIllegalExtensions()
Gets illegal extensions for this class
at line 197
static array
getRequiredExtensions()
Gets required extensions for this class
at line 226
static string|string[]
get_fixture_file()
at line 234
bool
getUsesDatabase()
at line 242
bool
getUsesTransactions()
at line 250
array
getRequireDefaultRecordsFrom()
at line 376
static
setUpBeforeClass()
Called once per test case ({@link SapphireTest} subclass).
This is different to {@link setUp()}, which gets called once per method. Useful to initialize expensive operations which don't change state for any called method inside the test, e.g. dynamically adding an extension. See {@link teardownAfterClass()} for tearing down the state again.
Always sets up in order: - Reset php state - Nest - Custom state helpers
User code should call parent::setUpBeforeClass() before custom setup code
at line 405
static
tearDownAfterClass()
tearDown method that's called once per test class rather once per test method.
Always sets up in order: - Custom state helpers - Unnest - Reset php state
User code should call parent::tearDownAfterClass() after custom tear down code
at line 418
FixtureFactory|false
getFixtureFactory()
deprecated
deprecated 4.0.0:5.0.0
at line 432
$this
setFixtureFactory(FixtureFactory $factory)
deprecated
deprecated 4.0.0:5.0.0
Sets a new fixture factory
at line 515
loadFixture(string $fixtureFile)
deprecated
deprecated 4.0.0:5.0.0
Load a YAML fixture file into the database.
Once loaded, you can use idFromFixture() and objFromFixture() to get items from the fixture. Doesn't clear existing fixtures.
at line 526
clearFixtures()
Clear all fixtures which were previously loaded through {@link loadFixture()}
at line 588
static
assertContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false)
at line 609
static
assertNotContains($needle, $haystack, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true, bool $checkForNonObjectIdentity = false)
at line 635
bool
clearEmails()
Clear the log of emails sent
at line 656
static array
findEmail(string $to, string $from = null, string $subject = null, string $content = null)
Search for an email that was sent.
All of the parameters can either be a string, or, if they start with "/", a PREG-compatible regular expression.
at line 675
static
assertEmailSent(string $to, string $from = null, string $subject = null, string $content = null)
Assert that the matching email was sent since the last call to clearEmails() All of the parameters can either be a string, or, if they start with "/", a PREG-compatible regular expression.
at line 725
static
assertListContains(SS_List|array $matches, SS_List $list, string $message = '')
Assert that the given {@link SS_List} includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
at line 749
assertDOSContains(array $matches, $dataObjectSet)
deprecated
deprecated 4.0.0:5.0.0 Use assertListContains() instead
at line 775
static
assertListNotContains(SS_List|array $matches, SS_List $list, string $message = '')
Asserts that no items in a given list appear in the given dataobject list
at line 803
static
assertNotDOSContains($matches, $dataObjectSet)
deprecated
deprecated 4.0.0:5.0.0 Use assertListNotContains() instead
at line 827
static
assertListEquals(mixed $matches, SS_List $list, string $message = '')
Assert that the given {@link SS_List} includes only DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
Example
Check that only the entries Sam Minnee and Ingo Schommer exist in $members. Order doesn't matter: $this->assertListEquals([ ['FirstName' =>'Sam', 'Surname' => 'Minnee'], ['FirstName' => 'Ingo', 'Surname' => 'Schommer'], ], $members);
at line 851
assertDOSEquals($matches, SS_List $dataObjectSet)
deprecated
deprecated 4.0.0:5.0.0 Use assertListEquals() instead
at line 871
static
assertListAllMatch(mixed $match, SS_List $list, string $message = '')
Assert that the every record in the given {@link SS_List} matches the given key-value pairs.
Example
Check that every entry in $members has a Status of 'Active': $this->assertListAllMatch(['Status' => 'Active'], $members);
at line 895
assertDOSAllMatch($match, SS_List $dataObjectSet)
deprecated
deprecated 4.0.0:5.0.0 Use assertListAllMatch() instead
at line 924
static
assertSQLEquals(string $expectedSQL, string $actualSQL, string $message = '', int $delta, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false)
Asserts that two SQL queries are equivalent
at line 949
static
assertSQLContains(string $needleSQL, string $haystackSQL, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true)
Asserts that a SQL query contains a SQL fragment
at line 971
static
assertSQLNotContains(string $needleSQL, string $haystackSQL, string $message = '', bool $ignoreCase = false, bool $checkForObjectIdentity = true)
Asserts that a SQL query contains a SQL fragment
at line 987
static
start()
Start test environment
at line 1035
static
resetDBSchema(bool $includeExtraDataObjects = false, bool $forceCreate = false)
Reset the testing database's schema, but only if it is active
at line 1055
mixed
actWithPermission(string|array $permCode, callable $callback)
A wrapper for automatically performing callbacks as a user with a specific permission
at line 1117
int
logInWithPermission(string|array $permCode = 'ADMIN')
Create a member and group with the given permission code, and log in with it.
Returns the member ID.
at line 1129
logInAs(Member|int|string $member)
Log in as the given member
at line 1142
logOut()
Log out the current user
at line 1201
static array
getExtraDataObjects()
Return all extra objects to scaffold for this test
at line 1211
static array
getExtraControllers()
Get additional controller classes to register routes for