3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 use PHPUnit\Framework\Assert
;
17 * An EventCheck is a fragment of a unit-test -- it is mixed into
18 * various test-scenarios and applies extra assertions.
20 class EventCheck
extends Assert
{
23 * @var \PHPUnit\Framework\Test
28 * Determine whether this check should be used during the current test.
30 * @param \PHPUnit\Framework\Test|NULL $test
33 * FALSE: The check will be completely skipped.
34 * TRUE: The check will be enabled. However, if the events never
35 * execute, that is OK. Useful for general compliance-testing.
37 public function isSupported($test) {
42 * @return \PHPUnit\Framework\Test|NULL
44 public function getTest() {
49 * @param \PHPUnit\Framework\Test|NULL $test
51 public function setTest($test): void
{
56 * Assert that a variable has a given type.
58 * @param string|string[] $types
59 * List of types, per `gettype()` or `get_class()`
60 * Ex: 'int|string|NULL'
61 * Ex: [`array`, `NULL`, `CRM_Core_DAO`]
63 * The variable to check
64 * @param string|NULL $msg
65 * @see \CRM_Utils_Type::validatePhpType
67 public function assertType($types, $value, ?
string $msg = NULL) {
68 if (!\CRM_Utils_Type
::validatePhpType($value, $types, FALSE)) {
69 $defactoType = is_object($value) ?
get_class($value) : gettype($value);
70 $types = is_array($types) ?
implode('|', $types) : $types;
71 $this->fail(sprintf("Expected one of (%s) but found %s\n%s", $types, $defactoType, $msg));
75 public function setUp() {
78 public function tearDown() {