From 639e2f140b32c4be9b23219973b5b412518e482d Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Fri, 7 Jul 2017 00:35:52 +0300
Subject: [PATCH] - Better handling of PEAR (and pecl) installation, added
 tests to verify.

---
 tasks/main.yml             | 17 +++++++++++++++++
 tasks/pear.yml             | 10 ++++++++++
 tests/files/check_pear.php |  4 ++++
 tests/playbook.yml         |  5 +++++
 tests/test_php7.py         |  9 ++++++++-
 5 files changed, 44 insertions(+), 1 deletion(-)
 create mode 100644 tasks/pear.yml
 create mode 100644 tests/files/check_pear.php

diff --git a/tasks/main.yml b/tasks/main.yml
index 36750a6..4f400b4 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -57,3 +57,20 @@
       user: root
       name: Composer self-update
       job: /usr/local/bin/composer self-update 2>&1 | logger
+
+- name: Check for PEAR installation
+  changed_when: False
+  ignore_errors: True
+  command: which pear
+  register: php7_which_pear
+
+- include: pear.yml
+  when: php7_which_pear|failed
+
+- name: Configure include_path
+  when: ansible_pkg_mgr == 'openbsd_pkg'
+  ini_file:
+      dest: /etc/php-7.0.ini
+      section: PHP
+      option: include_path
+      value: '".:/pear/lib:/var/www/pear/lib:/usr/local/share/php-7.0"'
diff --git a/tasks/pear.yml b/tasks/pear.yml
new file mode 100644
index 0000000..b34af7c
--- /dev/null
+++ b/tasks/pear.yml
@@ -0,0 +1,10 @@
+---
+- name: Download PEAR installer
+  get_url:
+      url: https://pear.php.net/install-pear-nozlib.phar
+      dest: /root/install-pear-nozlib.phar
+
+- name: Install PEAR
+  command: php /root/install-pear-nozlib.phar
+  args:
+      creates: /usr/local/bin/pear
diff --git a/tests/files/check_pear.php b/tests/files/check_pear.php
new file mode 100644
index 0000000..81ee51e
--- /dev/null
+++ b/tests/files/check_pear.php
@@ -0,0 +1,4 @@
+<?php
+require_once 'System.php';
+var_dump(class_exists('System', false));
+?>
diff --git a/tests/playbook.yml b/tests/playbook.yml
index fa483a9..0901607 100644
--- a/tests/playbook.yml
+++ b/tests/playbook.yml
@@ -20,3 +20,8 @@
 - hosts: all
   roles:
     - role: php7
+  post_tasks:
+      - name: Copy check_pear script
+        copy:
+            src: check_pear.php
+            dest: /root/check_pear.php
diff --git a/tests/test_php7.py b/tests/test_php7.py
index 388b881..9affa26 100644
--- a/tests/test_php7.py
+++ b/tests/test_php7.py
@@ -11,8 +11,15 @@ def test_composer(Command):
     assert Command('composer --version').stdout.startswith('Composer version')
 
 
-def test_pear(Command):
+def test_pear(Command, Sudo):
     assert Command('pear version').stdout.startswith('PEAR Version')
+    with Sudo():
+        assert Command(
+            'php /root/check_pear.php').stdout.strip() == 'bool(true)'
+
+
+def test_pecl(Command):
+    assert Command('pecl version').stdout.startswith('PEAR Version')
 
 
 def test_php_ini(Command):
-- 
GitLab