public function RulesTest::testCreateUpdateDelete in Auth0 Single Sign On 8.2
Test that create, update, and delete methods work as expected.
Return value
void
Throws
CoreException Thrown when there is a problem with parameters passed to the method.
\Exception Thrown by the HTTP client when there is a problem with the API call.
File
- vendor/
auth0/ auth0-php/ tests/ API/ Management/ RulesTest.php, line 153
Class
- RulesTest
- Class RulesTest.
Namespace
Auth0\Tests\API\ManagementCode
public function testCreateUpdateDelete() {
$api = new Management(self::$env['API_TOKEN'], self::$env['DOMAIN']);
$create_data = [
'name' => 'test-create-rule-' . rand(),
'script' => 'function (user, context, callback) { callback(null, user, context); }',
'enabled' => true,
];
$create_result = $api
->rules()
->create($create_data);
usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
$this
->assertNotEmpty($create_result['id']);
$this
->assertEquals($create_data['enabled'], $create_result['enabled']);
$this
->assertEquals($create_data['name'], $create_result['name']);
$this
->assertEquals($create_data['script'], $create_result['script']);
$test_rule_id = $create_result['id'];
$update_data = [
'name' => 'test-create-rule-' . rand(),
'script' => 'function (user, context, cb) { cb(null, user, context); }',
'enabled' => false,
];
$update_result = $api
->rules()
->update($test_rule_id, $update_data);
usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
$this
->assertEquals($update_data['enabled'], $update_result['enabled']);
$this
->assertEquals($update_data['name'], $update_result['name']);
$this
->assertEquals($update_data['script'], $update_result['script']);
$delete_result = $api
->rules()
->delete($test_rule_id);
usleep(AUTH0_PHP_TEST_INTEGRATION_SLEEP);
$this
->assertNull($delete_result);
}