HippoStep\SilverStripePhpUnit9\SapphireTestPhpUnit9
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.
Synopsis
class SapphireTestPhpUnit9
extends TestCase
{
- // members
- protected static string|array $fixture_file = NULL;
- protected FixtureFactory $fixtureFactory;
- protected Boolean $usesDatabase = NULL;
- protected bool $usesTransactions = true;
- protected static bool $is_running_test = false;
- protected array $requireDefaultRecordsFrom = ;
- protected static array $illegal_extensions = ;
- protected static array $required_extensions = ;
- protected static array $extra_dataobjects = ;
- protected static array $extra_controllers = ;
- protected boolean $backupGlobals = false;
- protected static SapphireTestState $state = NULL;
- protected static TempDatabase $tempDB = NULL;
- protected array $cache_generatedMembers = ;
- // methods
- public static TempDatabase tempDB()
- public static array getIllegalExtensions()
- public static array getRequiredExtensions()
- protected static bool is_running_test()
- protected static void set_is_running_test()
- public static String get_fixture_file()
- public bool getUsesDatabase()
- public bool getUsesTransactions()
- public array getRequireDefaultRecordsFrom()
- protected void setUp()
- protected bool shouldSetupDatabaseForCurrentTest()
- protected bool currentTestEnablesDatabase()
- protected bool currentTestDisablesDatabase()
- public static void setUpBeforeClass()
- public static void tearDownAfterClass()
- public FixtureFactory|false getFixtureFactory()
- public $this setFixtureFactory()
- protected int idFromFixture()
- protected array allFixtureIDs()
- protected DataObject objFromFixture()
- public void loadFixture()
- public void clearFixtures()
- protected string getCurrentAbsolutePath()
- protected string getCurrentRelativePath()
- protected void tearDown()
- public static void assertContains()
- public static void assertNotContains()
- public bool clearEmails()
- public static array|null findEmail()
- public static void assertEmailSent()
- public static void assertListContains()
- public void assertDOSContains()
- public static void assertListNotContains()
- public static void assertNotDOSContains()
- public static void assertListEquals()
- public void assertDOSEquals()
- public static void assertListAllMatch()
- public void assertDOSAllMatch()
- protected static string normaliseSQL()
- public static void assertSQLEquals()
- public static void assertSQLContains()
- public static void assertSQLNotContains()
- public static void start()
- public static void resetDBSchema()
- public mixed actWithPermission()
- protected Member createMemberWithPermission()
- public int logInWithPermission()
- public void logInAs()
- public void logOut()
- protected void useTestTheme()
- protected array getFixturePaths()
- public static array getExtraDataObjects()
- public static array getExtraControllers()
- protected string resolveFixturePath()
- protected void setUpRoutes()
- protected array getExtraRoutes()
Hierarchy
Extends
- PHPUnit\Framework\TestCase
Members
protected
-
$backupGlobals
We need to disabling backing up of globals to avoid overriding the few globals SilverStripe relies on, like $lang for the i18n subsystem. -
$cache_generatedMembers
Cache for logInWithPermission() - $extra_controllers
—
array
List of class names of {@see Controller} objects to register routes for Controllers must implement Link() method - $extra_dataobjects
—
array
By default, the test database won't contain any DataObjects that have the interface TestOnly. - $fixtureFactory — HippoStep\SilverStripePhpUnit9\FixtureFactory
- $fixture_file
—
HippoStep\SilverStripePhpUnit9\string|array
Path to fixture data for this test run. - $illegal_extensions
—
array
A list of extensions that can't be applied during the execution of this run. If they are applied, they will be temporarily removed and a database migration called. - $is_running_test — HippoStep\SilverStripePhpUnit9\bool
- $requireDefaultRecordsFrom
—
array
By default, setUp() does not require default records. Pass class names in here, and the require/augment default records function will be called on them. - $required_extensions
—
array
A list of extensions that must be applied during the execution of this run. If they are not applied, they will be temporarily added and a database migration called. - $state
—
SilverStripe\Dev\State\SapphireTestState
State management container for SapphireTest - $tempDB
—
SilverStripe\ORM\Connect\TempDatabase
Temp database helper - $usesDatabase — HippoStep\SilverStripePhpUnit9\Boolean
- $usesTransactions
—
HippoStep\SilverStripePhpUnit9\bool
This test will cleanup its state via transactions.
Methods
protected
- allFixtureIDs() — Return all of the IDs in the fixture of a particular class name.
- createMemberWithPermission() — Create Member and Group objects on demand with specific permission code
- currentTestDisablesDatabase() — Helper method to check, if the current test uses the database.
- currentTestEnablesDatabase() — Helper method to check, if the current test uses the database.
- getCurrentAbsolutePath() — Useful for writing unit tests without hardcoding folder structures.
- getCurrentRelativePath()
- getExtraRoutes() — Get extra routes to merge into Director.rules
- getFixturePaths() — Get fixture paths for this test
- idFromFixture() — Get the ID of an object from the fixture.
- is_running_test() — Check if test bootstrapping has been performed. Must not be relied on outside of unit tests.
- normaliseSQL() — Removes sequences of repeated whitespace characters from SQL queries making them suitable for string comparison
- objFromFixture() — Get an object from the fixture.
- resolveFixturePath() — Map a fixture path to a physical file
- setUp() — Setup the test.
- setUpRoutes()
- set_is_running_test() — Set test running state
- shouldSetupDatabaseForCurrentTest() — Helper method to determine if the current test should enable a test database
- tearDown() — Setup the test.
- useTestTheme() — Test against a theme.
public
- actWithPermission() — A wrapper for automatically performing callbacks as a user with a specific permission
- assertContains()
- assertDOSAllMatch()
- assertDOSContains()
- assertDOSEquals()
- assertEmailSent() — 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.
- assertListAllMatch() — Assert that the every record in the given {@link SS_List} matches the given key-value pairs.
- assertListContains() — Assert that the given {@link SS_List} includes DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
- assertListEquals() — Assert that the given {@link SS_List} includes only DataObjects matching the given key-value pairs. Each match must correspond to 1 distinct record.
- assertListNotContains() — Asserts that no items in a given list appear in the given dataobject list
- assertNotContains()
- assertNotDOSContains()
- assertSQLContains() — Asserts that a SQL query contains a SQL fragment
- assertSQLEquals() — Asserts that two SQL queries are equivalent
- assertSQLNotContains() — Asserts that a SQL query contains a SQL fragment
- clearEmails() — Clear the log of emails sent
- clearFixtures() — Clear all fixtures which were previously loaded through {@link loadFixture()}
- findEmail() — Search for an email that was sent.
- getExtraControllers() — Get additional controller classes to register routes for
- getExtraDataObjects() — Return all extra objects to scaffold for this test
- getFixtureFactory()
- getIllegalExtensions() — Gets illegal extensions for this class
- getRequireDefaultRecordsFrom()
- getRequiredExtensions() — Gets required extensions for this class
- getUsesDatabase()
- getUsesTransactions()
- get_fixture_file()
- loadFixture() — Load a YAML fixture file into the database.
- logInAs() — Log in as the given member
- logInWithPermission() — Create a member and group with the given permission code, and log in with it.
- logOut() — Log out the current user
- resetDBSchema() — Reset the testing database's schema, but only if it is active
- setFixtureFactory() — Sets a new fixture factory
- setUpBeforeClass() — Called once per test case ({@link SapphireTest} subclass).
- start() — Start test environment
- tearDownAfterClass() — tearDown method that's called once per test class rather once per test method.
- tempDB()