use Civi\Core\Event\GenericHookEvent;
use Civi\Test\CiviEnvBuilder;
use Civi\Test\HookInterface;
+use Civi\Test\Invasive;
use Civi\Test\TransactionalInterface;
/**
->addWhere('size', 'LIKE', 'big')
->addWhere('shape', 'LIKE', '%a');
- $itemsToGet = new \ReflectionMethod($get, '_itemsToGet');
- $itemsToGet->setAccessible(TRUE);
+ $itemsToGet = [$get, '_itemsToGet'];
- $this->assertEquals(['red', 'blue'], $itemsToGet->invoke($get, 'color'));
- $this->assertEquals(['one'], $itemsToGet->invoke($get, 'group'));
- $this->assertEquals(['big'], $itemsToGet->invoke($get, 'size'));
- $this->assertEmpty($itemsToGet->invoke($get, 'shape'));
- $this->assertEmpty($itemsToGet->invoke($get, 'weight'));
+ $this->assertEquals(['red', 'blue'], Invasive::call($itemsToGet, ['color']));
+ $this->assertEquals(['one'], Invasive::call($itemsToGet, ['group']));
+ $this->assertEquals(['big'], Invasive::call($itemsToGet, ['size']));
+ $this->assertEmpty(Invasive::call($itemsToGet, ['shape']));
+ $this->assertEmpty(Invasive::call($itemsToGet, ['weight']));
}
public function testFieldsToGet() {
$get = MockBasicEntity::get()
->addWhere('color', '!=', 'green');
- $isFieldSelected = new \ReflectionMethod($get, '_isFieldSelected');
- $isFieldSelected->setAccessible(TRUE);
+ $isFieldSelected = [$get, '_isFieldSelected'];
// If no "select" is set, should always return true
- $this->assertTrue($isFieldSelected->invoke($get, 'color'));
- $this->assertTrue($isFieldSelected->invoke($get, 'shape'));
- $this->assertTrue($isFieldSelected->invoke($get, 'size', 'color', 'shape'));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['color']));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['shape']));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['size', 'color', 'shape']));
// With a non-empty "select" fieldsToSelect() will return fields needed to evaluate each clause.
$get->addSelect('identifier');
- $this->assertTrue($isFieldSelected->invoke($get, 'color', 'shape', 'size'));
- $this->assertTrue($isFieldSelected->invoke($get, 'identifier'));
- $this->assertFalse($isFieldSelected->invoke($get, 'shape', 'size', 'weight'));
- $this->assertFalse($isFieldSelected->invoke($get, 'group'));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['color', 'shape', 'size']));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['identifier']));
+ $this->assertFalse(Invasive::call($isFieldSelected, ['shape', 'size', 'weight']));
+ $this->assertFalse(Invasive::call($isFieldSelected, ['group']));
$get->addClause('OR', ['shape', '=', 'round'], ['AND', [['size', '=', 'big'], ['weight', '!=', 'small']]]);
- $this->assertTrue($isFieldSelected->invoke($get, 'color'));
- $this->assertTrue($isFieldSelected->invoke($get, 'identifier'));
- $this->assertTrue($isFieldSelected->invoke($get, 'shape'));
- $this->assertTrue($isFieldSelected->invoke($get, 'size'));
- $this->assertTrue($isFieldSelected->invoke($get, 'group', 'weight'));
- $this->assertFalse($isFieldSelected->invoke($get, 'group'));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['color']));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['identifier']));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['shape']));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['size']));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['group', 'weight']));
+ $this->assertFalse(Invasive::call($isFieldSelected, ['group']));
$get->addOrderBy('group');
- $this->assertTrue($isFieldSelected->invoke($get, 'group'));
+ $this->assertTrue(Invasive::call($isFieldSelected, ['group']));
}
public function testWildcardSelect() {
use Civi\Api4\MockBasicEntity;
use api\v4\Api4TestBase;
+use Civi\Test\Invasive;
use Civi\Test\TransactionalInterface;
/**
class EvaluateConditionTest extends Api4TestBase implements TransactionalInterface {
public function testEvaluateCondition() {
- $action = MockBasicEntity::get();
- $reflection = new \ReflectionClass($action);
- $method = $reflection->getMethod('evaluateCondition');
- $method->setAccessible(TRUE);
+ $method = [MockBasicEntity::get(), 'evaluateCondition'];
$data = [
'nada' => 0,
'values' => ['one' => 1, 'two' => 2, 'three' => 3],
];
- $this->assertFalse($method->invoke($action, '$uno > $dos', $data));
- $this->assertTrue($method->invoke($action, '$uno < $dos', $data));
- $this->assertTrue($method->invoke($action, '$apple == "red" && $banana != "red"', $data));
- $this->assertFalse($method->invoke($action, '$apple == "red" && $banana != "yellow"', $data));
- $this->assertTrue($method->invoke($action, '$values.one == $uno', $data));
- $this->assertTrue($method->invoke($action, '$values.one + $dos == $values.three', $data));
- $this->assertTrue($method->invoke($action, 'empty($nada)', $data));
- $this->assertFalse($method->invoke($action, 'empty($values)', $data));
+ $this->assertFalse(Invasive::call($method, ['$uno > $dos', $data]));
+ $this->assertTrue(Invasive::call($method, ['$uno < $dos', $data]));
+ $this->assertTrue(Invasive::call($method, ['$apple == "red" && $banana != "red"', $data]));
+ $this->assertFalse(Invasive::call($method, ['$apple == "red" && $banana != "yellow"', $data]));
+ $this->assertTrue(Invasive::call($method, ['$values.one == $uno', $data]));
+ $this->assertTrue(Invasive::call($method, ['$values.one + $dos == $values.three', $data]));
+ $this->assertTrue(Invasive::call($method, ['empty($nada)', $data]));
+ $this->assertFalse(Invasive::call($method, ['empty($values)', $data]));
}
}