From b01b546f181a3707691f92eb9873c0128d4c4579 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 13 Jun 2019 22:48:01 -0400 Subject: [PATCH] (REF) Convert YAML fixtures to JSON fixtures. Reset symfony/yaml dependency. Overview -------- The test suite includes some tests that read fixture data files (i.e. YAML files). This patch provides a safer way to address a dependency-management issue with parsing YAML files. Before ------ * In the last public release (`5.14`), the `symfony/yaml` package was not included with `civicrm-core`. However, it was loaded during testing by virtue of running `phpunit6`. * In the `5.15` RC code, `symfony/yaml` was added -- so that the test suite worked in `phpunit6`. However, this also added `symfony/yaml` to the general runtime distribution - which is liable to create conflicts with Civi extensions and CMS modules that also bundle `symfony/yaml`. (It's a popular package.) After ----- * The test suite no longer uses YAML, and the build no longer requires `symfony/yaml`. Instead, it uses JSON. --- composer.json | 1 - composer.lock | 67 +++------------------ tests/fixtures/case.json | 9 +++ tests/fixtures/case.yaml | 5 -- tests/fixtures/case_contact.json | 8 +++ tests/fixtures/case_contact.yaml | 4 -- tests/fixtures/case_relationships.json | 48 +++++++++++++++ tests/fixtures/case_relationships.yaml | 44 -------------- tests/fixtures/case_types.json | 13 ++++ tests/fixtures/case_types.yaml | 9 --- tests/fixtures/contacts.json | 54 +++++++++++++++++ tests/fixtures/contacts.yaml | 50 --------------- tests/phpunit/CiviTest/CiviUnitTestCase.php | 9 ++- 13 files changed, 146 insertions(+), 175 deletions(-) create mode 100644 tests/fixtures/case.json delete mode 100644 tests/fixtures/case.yaml create mode 100644 tests/fixtures/case_contact.json delete mode 100644 tests/fixtures/case_contact.yaml create mode 100644 tests/fixtures/case_relationships.json delete mode 100644 tests/fixtures/case_relationships.yaml create mode 100644 tests/fixtures/case_types.json delete mode 100644 tests/fixtures/case_types.yaml create mode 100644 tests/fixtures/contacts.json delete mode 100644 tests/fixtures/contacts.yaml diff --git a/composer.json b/composer.json index 050b5362f2..271f33cf59 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,6 @@ "symfony/event-dispatcher": "^2.8.44 || ~3.0", "symfony/filesystem": "^2.8.44 || ~3.0", "symfony/process": "^2.8.44 || ~3.0", - "symfony/yaml": "^2.8.44 || ~3.0", "psr/log": "~1.1", "symfony/finder": "^2.8.44 || ~3.0", "tecnickcom/tcpdf" : "6.2.*", diff --git a/composer.lock b/composer.lock index d4976108dc..7fe362a0ac 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ef15b267ffebe1be949611b7c8618924", + "content-hash": "a337d7adf0d57f28a1aff44917fe1b92", "packages": [ { "name": "civicrm/civicrm-cxn-rpc", @@ -1814,25 +1814,28 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.8.0", + "version": "v1.11.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae" + "reference": "82ebae02209c21113908c229e9883c419720738a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/7cc359f1b7b80fc25ed7796be7d96adc9b354bae", - "reference": "7cc359f1b7b80fc25ed7796be7d96adc9b354bae", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", + "reference": "82ebae02209c21113908c229e9883c419720738a", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "suggest": { + "ext-ctype": "For best performance" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.11-dev" } }, "autoload": { @@ -1865,7 +1868,7 @@ "polyfill", "portable" ], - "time": "2018-04-30T19:57:29+00:00" + "time": "2019-02-06T07:57:58+00:00" }, { "name": "symfony/polyfill-iconv", @@ -1975,56 +1978,6 @@ "homepage": "https://symfony.com", "time": "2018-07-26T11:13:39+00:00" }, - { - "name": "symfony/yaml", - "version": "v2.8.44", - "source": { - "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "fbf876678e29dc634430dcf0096e216eb0004467" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/fbf876678e29dc634430dcf0096e216eb0004467", - "reference": "fbf876678e29dc634430dcf0096e216eb0004467", - "shasum": "" - }, - "require": { - "php": ">=5.3.9", - "symfony/polyfill-ctype": "~1.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.8-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Yaml\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Yaml Component", - "homepage": "https://symfony.com", - "time": "2018-07-26T09:03:18+00:00" - }, { "name": "tecnickcom/tcpdf", "version": "6.2.26", diff --git a/tests/fixtures/case.json b/tests/fixtures/case.json new file mode 100644 index 0000000000..493ca8d896 --- /dev/null +++ b/tests/fixtures/case.json @@ -0,0 +1,9 @@ +{ + "civicrm_case": [ + { + "id": 1, + "case_type_id": 1, + "status_id": 1 + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/case.yaml b/tests/fixtures/case.yaml deleted file mode 100644 index 25e79471c4..0000000000 --- a/tests/fixtures/case.yaml +++ /dev/null @@ -1,5 +0,0 @@ -civicrm_case: - - - id: 1 - case_type_id: 1 - status_id: 1 diff --git a/tests/fixtures/case_contact.json b/tests/fixtures/case_contact.json new file mode 100644 index 0000000000..b589251233 --- /dev/null +++ b/tests/fixtures/case_contact.json @@ -0,0 +1,8 @@ +{ + "civicrm_case_contact": [ + { + "case_id": 1, + "contact_id": 3 + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/case_contact.yaml b/tests/fixtures/case_contact.yaml deleted file mode 100644 index 17d8b90469..0000000000 --- a/tests/fixtures/case_contact.yaml +++ /dev/null @@ -1,4 +0,0 @@ -civicrm_case_contact: - - - case_id: 1 - contact_id: 3 diff --git a/tests/fixtures/case_relationships.json b/tests/fixtures/case_relationships.json new file mode 100644 index 0000000000..f1c0dc962d --- /dev/null +++ b/tests/fixtures/case_relationships.json @@ -0,0 +1,48 @@ +{ + "civicrm_relationship_type": [ + { + "name_a_b": "Homeless Services Coordinator is", + "label_a_b": "Homeless Services Coordinator is", + "name_b_a": "Homeless Services Coordinator", + "label_b_a": "Homeless Services Coordinator", + "description": "Homeless Services Coordinator", + "contact_type_a": "Individual", + "contact_type_b": "Individual", + "is_reserved": 0, + "is_active": 1 + }, + { + "name_a_b": "Health Services Coordinator is", + "label_a_b": "Health Services Coordinator is", + "name_b_a": "Health Services Coordinator", + "label_b_a": "Health Services Coordinator", + "description": "Health Services Coordinator", + "contact_type_a": "Individual", + "contact_type_b": "Individual", + "is_reserved": 0, + "is_active": 1 + }, + { + "name_a_b": "Senior Services Coordinator is", + "label_a_b": "Senior Services Coordinator is", + "name_b_a": "Senior Services Coordinator", + "label_b_a": "Senior Services Coordinator", + "description": "Senior Services Coordinator", + "contact_type_a": "Individual", + "contact_type_b": "Individual", + "is_reserved": 0, + "is_active": 1 + }, + { + "name_a_b": "Benefits Specialist is", + "label_a_b": "Benefits Specialist is", + "name_b_a": "Benefits Specialist", + "label_b_a": "Benefits Specialist", + "description": "Benefits Specialist", + "contact_type_a": "Individual", + "contact_type_b": "Individual", + "is_reserved": 0, + "is_active": 1 + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/case_relationships.yaml b/tests/fixtures/case_relationships.yaml deleted file mode 100644 index 96323d07bc..0000000000 --- a/tests/fixtures/case_relationships.yaml +++ /dev/null @@ -1,44 +0,0 @@ -civicrm_relationship_type: - - - name_a_b: Homeless Services Coordinator is - label_a_b: Homeless Services Coordinator is - name_b_a: Homeless Services Coordinator - label_b_a: Homeless Services Coordinator - description: Homeless Services Coordinator - contact_type_a: Individual - contact_type_b: Individual - is_reserved: 0 - is_active: 1 - - - - name_a_b: Health Services Coordinator is - label_a_b: Health Services Coordinator is - name_b_a: Health Services Coordinator - label_b_a: Health Services Coordinator - description: Health Services Coordinator - contact_type_a: Individual - contact_type_b: Individual - is_reserved: 0 - is_active: 1 - - - - name_a_b: Senior Services Coordinator is - label_a_b: Senior Services Coordinator is - name_b_a: Senior Services Coordinator - label_b_a: Senior Services Coordinator - description: Senior Services Coordinator - contact_type_a: Individual - contact_type_b: Individual - is_reserved: 0 - is_active: 1 - - - - name_a_b: Benefits Specialist is - label_a_b: Benefits Specialist is - name_b_a: Benefits Specialist - label_b_a: Benefits Specialist - description: Benefits Specialist - contact_type_a: Individual - contact_type_b: Individual - is_reserved: 0 - is_active: 1 diff --git a/tests/fixtures/case_types.json b/tests/fixtures/case_types.json new file mode 100644 index 0000000000..6c2d397b60 --- /dev/null +++ b/tests/fixtures/case_types.json @@ -0,0 +1,13 @@ +{ + "civicrm_case_type": [ + { + "id": 1, + "name": "housing_support", + "title": "Housing Support", + "description": "Help homeless individuals obtain temporary and long-term housing", + "is_active": 1, + "is_reserved": 0, + "weight": 1 + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/case_types.yaml b/tests/fixtures/case_types.yaml deleted file mode 100644 index 47c47a887b..0000000000 --- a/tests/fixtures/case_types.yaml +++ /dev/null @@ -1,9 +0,0 @@ -civicrm_case_type: - - - id: 1 - name: housing_support - title: Housing Support - description: Help homeless individuals obtain temporary and long-term housing - is_active: 1 - is_reserved: 0 - weight: 1 diff --git a/tests/fixtures/contacts.json b/tests/fixtures/contacts.json new file mode 100644 index 0000000000..3b5e70573e --- /dev/null +++ b/tests/fixtures/contacts.json @@ -0,0 +1,54 @@ +{ + "civicrm_contact": [ + { + "id": 3, + "contact_type": "Individual", + "contact_sub_type": null, + "do_not_email": 0, + "do_not_phone": 0, + "do_not_mail": 0, + "do_not_sms": 0, + "do_not_trade": 0, + "is_opt_out": 0, + "legal_identifier": null, + "sort_name": "Site Administrator", + "display_name": "Site Administrator", + "nick_name": null, + "legal_name": null, + "image_URL": null, + "preferred_communication_method": null, + "preferred_mail_format": null, + "hash": null, + "api_key": null, + "source": null, + "first_name": "Site", + "middle_name": null, + "last_name": "Administrator" + }, + { + "id": 17, + "contact_type": "Individual", + "contact_sub_type": null, + "do_not_email": 0, + "do_not_phone": 0, + "do_not_mail": 0, + "do_not_sms": 0, + "do_not_trade": 0, + "is_opt_out": 0, + "legal_identifier": null, + "sort_name": null, + "display_name": "Test Contact", + "nick_name": null, + "legal_name": null, + "image_URL": null, + "preferred_communication_method": null, + "preferred_mail_format": null, + "hash": null, + "api_key": null, + "source": null, + "first_name": "Test", + "middle_name": null, + "last_name": "Contact" + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/contacts.yaml b/tests/fixtures/contacts.yaml deleted file mode 100644 index 42cc887757..0000000000 --- a/tests/fixtures/contacts.yaml +++ /dev/null @@ -1,50 +0,0 @@ -civicrm_contact: - - - id: 3 - contact_type: Individual - contact_sub_type: - do_not_email: 0 - do_not_phone: 0 - do_not_mail: 0 - do_not_sms: 0 - do_not_trade: 0 - is_opt_out: 0 - legal_identifier: - sort_name: Site Administrator - display_name: Site Administrator - nick_name: - legal_name: - image_URL: - preferred_communication_method: - preferred_mail_format: - hash: - api_key: - source: - first_name: Site - middle_name: - last_name: Administrator - - - - id: 17 - contact_type: Individual - contact_sub_type: - do_not_email: 0 - do_not_phone: 0 - do_not_mail: 0 - do_not_sms: 0 - do_not_trade: 0 - is_opt_out: 0 - legal_identifier: - sort_name: - display_name: Test Contact - nick_name: - legal_name: - image_URL: - preferred_communication_method: - preferred_mail_format: - hash: - api_key: - source: - first_name: Test - middle_name: - last_name: Contact diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 1c11b5e095..5ecff3a9f5 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -27,7 +27,6 @@ */ use Civi\Payment\System; -use Symfony\Component\Yaml\Yaml; /** * Include class definitions @@ -376,10 +375,10 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS = 0;"); - $yamlFiles = glob($fixturesDir . '/*.yaml'); - foreach ($yamlFiles as $yamlFixture) { - $yaml = Yaml::parse(file_get_contents($yamlFixture)); - foreach ($yaml as $tableName => $vars) { + $jsonFiles = glob($fixturesDir . '/*.json'); + foreach ($jsonFiles as $jsonFixture) { + $json = json_decode(file_get_contents($jsonFixture)); + foreach ($json as $tableName => $vars) { if ($tableName === 'civicrm_contact') { CRM_Core_DAO::executeQuery('DELETE c FROM civicrm_contact c LEFT JOIN civicrm_domain d ON d.contact_id = c.id WHERE d.id IS NULL'); } -- 2.25.1