Skip to content

Instantly share code, notes, and snippets.

@monishdeb
Created March 17, 2017 11:53
Show Gist options
  • Save monishdeb/89b8f7f4ae67d99b67d2d939dca0a997 to your computer and use it in GitHub Desktop.
Save monishdeb/89b8f7f4ae67d99b67d2d939dca0a997 to your computer and use it in GitHub Desktop.
diff --git a/api/v3/examples/Activity/Create.php b/api/v3/examples/Activity/Create.php
index a380f12..27d3ce4 100644
--- a/api/v3/examples/Activity/Create.php
+++ b/api/v3/examples/Activity/Create.php
@@ -8,7 +8,7 @@
function activity_create_example() {
$params = array(
'source_contact_id' => 1,
- 'activity_type_id' => '55',
+ 'activity_type_id' => 'Test activity type',
'subject' => 'test activity type id',
'activity_date_time' => '2011-06-02 14:36:13',
'status_id' => 2,
diff --git a/tests/phpunit/api/v3/ActivityTest.php b/tests/phpunit/api/v3/ActivityTest.php
index 5ce55f7..4077b5d 100644
--- a/tests/phpunit/api/v3/ActivityTest.php
+++ b/tests/phpunit/api/v3/ActivityTest.php
@@ -408,6 +408,7 @@ class api_v3_ActivityTest extends CiviUnitTestCase {
require_once 'api/v3/examples/Activity/Create.php';
$result = activity_create_example();
$expectedResult = activity_create_expectedresult();
+ $expectedResult['values'][1]['activity_type_id'] = $this->test_activity_type_value;
$this->assertEquals($result, $expectedResult);
}
@JoeMurray
Copy link

I'm not comfortable with L10 passing a string to for an unsigned int parameter value. Could you use a CONST to define a value, and perhaps give it a large value so it will not conflict with anthing loaded by the tarball during testing?

@monishdeb
Copy link
Author

monishdeb commented Mar 24, 2017

Actually, there is no definite value for activity type id when a last activity type (here the value is 54) is deleted from install (or upgrade) then on test build at this point https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php#L63 a new activity type is created with next incremented value i.e. 54. As a result of which it conflicts with the hard-coded value '55' for this unit-test https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ActivityTest.php#L407

So yes another alternative will be, if we can use larger value as https://gist.github.com/monishdeb/dfc0b33db972e03994f88b687bfab1ff but do we still need CONST to define that value or simply use larger value?

@JoeMurray
Copy link

Could you future-proof this to 999 rather than 99. I think it's good coding style to use CONST, but agree it's common not to. Your choice in this instance since it's merely a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment