{"id":462,"date":"2013-03-21T01:30:58","date_gmt":"2013-03-21T05:30:58","guid":{"rendered":"http:\/\/blogs.law.harvard.edu\/acts\/?p=462"},"modified":"2013-03-21T20:51:13","modified_gmt":"2013-03-22T00:51:13","slug":"getting-travis-ci-to-work-with-a-php-project","status":"publish","type":"post","link":"https:\/\/archive.blogs.harvard.edu\/acts\/2013\/03\/21\/getting-travis-ci-to-work-with-a-php-project\/","title":{"rendered":"Getting Travis-CI to work with a PHP Project"},"content":{"rendered":"<p>First off, Travis CI is only usable through github. It&#8217;s a great service that allows tests to be run before pull requests are merged, helping to ensure code stability. It&#8217;s a very new service, and PHP support is in flux. Almost daily information changes. So I fear this will be outdated tomorrow. Regardless, I wanted to get this written down.<\/p>\n<p>The magic all happens in the .travis.yml file. It&#8217;s a config file that tells travis what to run. It only has a few sections, but they can be tricky. Here is the example .travis.yml for PHP:<\/p>\n<pre class=\"brush: perl; title: ; notranslate\" title=\"\">\r\nlanguage: php\r\n\r\n# list any PHP version you want to test against\r\nphp:\r\n  # using major version aliases\r\n\r\n  # aliased to 5.2.17\r\n  - 5.2\r\n  # aliased to a recent 5.3.x version\r\n  - 5.3\r\n  # aliased to a recent 5.4.x version\r\n  - 5.4\r\n\r\n# optionally specify a list of environments, for example to test different RDBMS\r\nenv:\r\n  - DB=mysql\r\n  - DB=pgsql\r\n\r\n# execute any number of scripts before the test run, custom env&#039;s are available as variables\r\nbefore_script:\r\n  - if &#x5B;&#x5B; &quot;$DB&quot; == &quot;pgsql&quot; ]]; then psql -c &quot;DROP DATABASE IF EXISTS hello_world_test;&quot; -U postgres; fi\r\n  - if &#x5B;&#x5B; &quot;$DB&quot; == &quot;pgsql&quot; ]]; then psql -c &quot;create database hello_world_test;&quot; -U postgres; fi\r\n  - if &#x5B;&#x5B; &quot;$DB&quot; == &quot;mysql&quot; ]]; then mysql -e &quot;create database IF NOT EXISTS hello_world_test;&quot; -uroot; fi\r\n\r\n# omitting &quot;script:&quot; will default to phpunit\r\n# use the $DB env variable to determine the phpunit.xml to use\r\nscript: phpunit --configuration phpunit_$DB.xml --coverage-text\r\n\r\n# configure notifications (email, IRC, campfire etc)\r\nnotifications:\r\n  irc: &quot;irc.freenode.org#travis&quot;\r\n<\/pre>\n<p><strong>Not included libs<\/strong><\/p>\n<p>Currently this will not work. Their phpunit is requiring libraries that aren&#8217;t included in the vm that&#8217;s created. Regardless of if your project is using these libraries:<\/p>\n<pre class=\"brush: perl; title: ; notranslate\" title=\"\">\r\nbefore_script:\r\n  # everything after this point is needed to just use phpunit\r\n  - pear channel-discover pear.phpunit.de\r\n  - pear install phpunit\/PHP_Invoker\r\n  - pear install phpunit\/DbUnit\r\n  - pear install phpunit\/PHPUnit_Selenium\r\n  - pear install phpunit\/PHPUnit_Story\r\n<\/pre>\n<p><strong>Database usage<\/strong><\/p>\n<p>I use mysql currently. The problem I hit was you can create users, but you can&#8217;t grant them privilages. So you HAVE to use the default root user with no password.<\/p>\n<pre class=\"brush: perl; title: ; notranslate\" title=\"\">\r\nenv:\r\n  - DB=mysql\r\n\r\n# execute any number of scripts before the test run, custom env&#039;s are available as variables\r\nbefore_script:\r\n  - mysql -e &#039;CREATE DATABASE `quizmo_dev`;&#039;\r\n  # The following is fine, but travis won&#039;t allow granting privilages\r\n  # - mysql -e &quot;CREATE USER &#039;quizmo_dev&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;quizmo_dev&#039;;&quot;\r\n  # - mysql -e &quot;GRANT ALL PRIVILEGES ON *.* TO &#039;quizmo_dev&#039;@&#039;localhost&#039; WITH GRANT OPTION;&quot;\r\n  # migrating adds all tables\r\n  - quizmo\/protected\/yiic migrate --interactive=0\r\n<\/pre>\n<p><strong>Notifications don&#8217;t work<\/strong><\/p>\n<p>I&#8217;m assuming this is something they&#8217;ll fix soon. I&#8217;m just trying to use email notifications &#8212; but it never sends an email.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First off, Travis CI is only usable through github. It&#8217;s a great service that allows tests to be run before pull requests are merged, helping to ensure code stability. It&#8217;s a very new service, and PHP support is in flux. Almost daily information changes. So I fear this will be outdated tomorrow. Regardless, I wanted [&hellip;]<\/p>\n","protected":false},"author":4571,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[910,64019,3163],"tags":[64049,64050],"class_list":["post-462","post","type-post","status-publish","format-standard","hentry","category-development","category-open-source-development","category-php","tag-continuous-integration","tag-travis-ci"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/users\/4571"}],"replies":[{"embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/comments?post=462"}],"version-history":[{"count":8,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/462\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/posts\/462\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/media?parent=462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/categories?post=462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/archive.blogs.harvard.edu\/acts\/wp-json\/wp\/v2\/tags?post=462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}